A GitHub Action to automatically tag and version software using semantic versioning on release branches.
- π·οΈ Automatic semantic versioning - Creates git tags following semantic versioning (v1, v1.0, v1.0.0)
- π Tag updates - Updates major and minor tags to point to the latest release
- π¦ Node.js integration - Automatically reads version from package.json
- πΏ Release branch support - Works with release branches (e.g., release/v1, release/v2.1)
- βοΈ Flexible configuration - Multiple version sources: auto-detection, package.json, or manual
- π Version-only mode - Can return version information without creating tags for use in separate workflows
Use the action directly in your workflow:
name: Release
on:
push:
branches:
- 'release/v*'
jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create version tags
uses: vln-devsecops/actions-autoversion@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}Use the reusable workflow for easier setup:
name: Release
on:
push:
branches:
- 'release/v*'
jobs:
version:
uses: vln-devsecops/actions-autoversion/.github/workflows/autoversion.yml@v1
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}When you push to a release branch like release/v1:
- The action detects the branch name
- For Node.js projects, it reads the version from
package.json - Otherwise, it extracts the version from the branch name
- It creates/updates three tags:
v1(major version tag)v1.0(minor version tag)v1.0.0(patch version tag)
The action supports multiple version sources (controlled by version-source input):
auto(default): First tries to read from package.json, then falls back to branch namepackage.json: Reads version only from package.jsonmanual: Uses manually specified major, minor, and patch versions
- First release on
release/v1: Creates tagsv1,v1.0, andv1.0.0 - Subsequent releases on
release/v1: Updatesv1andv1.0tags to point to the latest commit, creates new patch tag (e.g.,v1.0.1,v1.0.2)
The action includes validation to prevent common errors:
- Duplicate tags: Fails if the exact patch version tag already exists (e.g., cannot create
v1.2.3twice) - Version mismatches: When using
package.jsonmode or auto mode, validates that the major version inpackage.jsonmatches the release branch (e.g.,package.jsonwith version2.0.0on branchrelease/v1will fail) - Minor version validation: If the release branch specifies a minor version (e.g.,
release/v2.1), validates it matches thepackage.jsonminor version
| Input | Description | Required | Default |
|---|---|---|---|
release-branch-pattern |
Pattern to match release branches | No | release/v* |
version-source |
Source of version: auto, package.json, or manual |
No | auto |
major-version |
Major version (when version-source is manual) |
No | - |
minor-version |
Minor version (when version-source is manual) |
No | - |
patch-version |
Patch version (when version-source is manual) |
No | - |
tag-prefix |
Prefix for version tags | No | v |
create-tags |
Whether to create/update tags (set to false to only return version) |
No | true |
github-token |
GitHub token for creating tags (required only when create-tags is true) |
No | - |
| Output | Description | Example |
|---|---|---|
version |
The full semantic version | 1.0.0 |
tags |
Comma-separated list of tags created/updated | v1,v1.0,v1.0.0 |
major-tag |
The major version tag | v1 |
minor-tag |
The minor version tag | v1.0 |
patch-tag |
The full semantic version tag | v1.0.0 |
name: Release
on:
push:
branches:
- 'release/v*'
jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create version tags
uses: vln-devsecops/actions-autoversion@v1
with:
version-source: package.json
github-token: ${{ secrets.GITHUB_TOKEN }}name: Release
on:
push:
branches:
- 'release/v*'
jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create version tags
uses: vln-devsecops/actions-autoversion@v1
with:
version-source: manual
major-version: '2'
minor-version: '1'
patch-version: '0'
github-token: ${{ secrets.GITHUB_TOKEN }}name: Release
on:
push:
branches:
- 'release/v*'
jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create version tags
uses: vln-devsecops/actions-autoversion@v1
with:
tag-prefix: 'version-'
github-token: ${{ secrets.GITHUB_TOKEN }}This will create tags like version-1, version-1.0, version-1.0.0.
name: Build
on:
push:
branches:
- 'release/v*'
jobs:
get-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.autoversion.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version (without creating tags)
id: autoversion
uses: vln-devsecops/actions-autoversion@v1
with:
create-tags: false
- name: Display version
run: echo "Building version ${{ steps.autoversion.outputs.version }}"
build:
needs: get-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build with version ${{ needs.get-version.outputs.version }}
run: |
echo "Building version ${{ needs.get-version.outputs.version }}"
# Your build commands here
release:
needs: [get-version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create tags
uses: vln-devsecops/actions-autoversion@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}This pattern allows you to determine the version once, use it throughout your workflow for building and testing, and then create the tags in a separate job after everything succeeds.
MIT - see LICENSE file for details.