Semantic versioning tool based on GitHub commit history and Conventional Commits.
- 🚀 Calculate semantic versions from commit history
- 🔄 Follows Conventional Commits specification
- 🌿 Supports multi-branch workflows with prerelease versions
- 💡 Smart data source: local git first, GitHub API fallback
- 🎯 Zero configuration required
- 📦 Works in CI/CD environments (shallow clones supported)
npm install -g ghsemvernpx ghsemver current
npx ghsemver nextGet the latest semantic version tag from your repository:
ghsemver current
# Output: 1.0.0Calculate the next version based on commit history:
ghsemver next
# Output: 1.1.0Use --log flag to see detailed information:
ghsemver next --log
# Output:
# Current branch: main
# Main branch: main
# Current version: 1.0.0 (local git)
# Tag commit: abc1234 (local git)
# Analyzing 3 commit(s) (local git)
# Release type: minor
# 1.1.0Get the current version (latest semantic version tag).
ghsemver current [options]Options:
-b, --branch <branch>- Specify branch (optional)-m, --main-branch <mainBranch>- Specify main branch (optional)--log- Enable verbose logging
Calculate the next version based on commits.
ghsemver next [options]Options:
-b, --branch <branch>- Specify branch (optional)-m, --main-branch <mainBranch>- Specify main branch (optional)-s, --suffix <suffix>- Prerelease suffix for non-main branches (optional)--log- Enable verbose logging
This tool follows Conventional Commits specification:
Incremented when commits contain breaking changes:
BREAKING CHANGE:orBREAKING-CHANGE:in commit message body!after commit type:feat!:,fix!:
feat!: redesign authentication system
BREAKING CHANGE: removed old authentication API
Result: 1.0.0 → 2.0.0
Incremented for new features:
- Commit type:
featorfeature
feat: add user export functionality
Result: 1.0.0 → 1.1.0
Incremented for bug fixes and performance improvements:
- Commit type:
fix - Commit type:
perf
fix: resolve login page styling issue
perf: optimize database queries
Result: 1.0.0 → 1.0.1
On non-main branches, versions include a prerelease identifier:
Format: {version}-{suffix}.{number}
# On develop branch
ghsemver next
# Output: 1.1.0-develop.1
# On feature/awesome branch
ghsemver next
# Output: 1.1.0-feature-awesome.1
# Custom suffix
ghsemver next --suffix beta
# Output: 1.1.0-beta.1When commits don't match Conventional Commits patterns or only contain non-versioning types:
chore:,docs:,style:,refactor:,test:,build:,ci:
ghsemver next
# Output: (empty string)Set GITHUB_TOKEN to increase API rate limits:
export GITHUB_TOKEN=your_github_token_hereGet a token at: https://github.com/settings/tokens
- Repository Detection: Extracts GitHub repository info from git remote
- Branch Detection: Automatically detects current branch (or uses specified branch)
- Version Discovery: Finds latest semantic version tag (vX.Y.Z format)
- Commit Analysis: Gets commits since last tag, analyzes using Conventional Commits
- Version Calculation: Calculates next version based on commit types
The tool prioritizes local git operations and falls back to GitHub API when needed:
| Operation | Priority |
|---|---|
| Current branch | Local git → CLI option → GitHub API |
| Latest tag | Local git → GitHub API |
| Commit history | Local git (if complete) → GitHub API |
| Main branch | CLI option → GitHub API |
This approach is:
- ⚡ Fast: Local operations are ~20x faster
- 🔒 Offline-capable: Works without internet if data is local
- 💰 API-friendly: Reduces GitHub API usage
# Get current version
ghsemver current
# Output: 1.0.0
# Calculate next version (silent mode)
ghsemver next
# Output: 1.1.0# .github/workflows/release.yml
- name: Calculate version
id: version
run: |
VERSION=$(npx ghsemver next)
if [ -z "$VERSION" ]; then
echo "No version bump needed"
exit 0
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create release
if: steps.version.outputs.version
run: |
git tag "v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"{
"scripts": {
"version:current": "ghsemver current",
"version:next": "ghsemver next",
"version:check": "ghsemver next || echo 'No version bump needed'"
}
}#!/bin/bash
VERSION=$(ghsemver next)
if [ -z "$VERSION" ]; then
echo "No version bump required"
exit 0
fi
echo "Bumping version to $VERSION"
npm version $VERSION --no-git-tag-version
git add package.json
git commit -m "chore: bump version to $VERSION"
git tag "v$VERSION"
git push --follow-tags- ✅ Valid:
v1.0.0,v2.3.4,v10.20.30 - ❌ Invalid:
1.0.0,v1.0,release-v1.0.0
The tool only recognizes tags starting with v followed by semantic version (X.Y.Z).
Output versions do not include the v prefix.
- Node.js >= 18.0.0
- Git repository with GitHub remote
- Git installed and available in PATH
ISC
Issues and pull requests are welcome at https://github.com/shared-utils/semver
Inspired by semantic-release but designed to be:
- Lighter weight
- Zero configuration
- Focused on version calculation only