A lightweight, high-performance GitHub Action to automatically manage Semantic Versioning (SemVer) tags. This action calculates the next version based on your current tags and pushes a new tag to your repository.
- Automated SemVer: Bumps
patch,minor, ormajorversions automatically. - Node 20 Runtime: Built on the latest GitHub Actions runner for speed and security.
- Lightweight: Compiled into a single distribution file for fast execution.
- Dry Run Support: Preview your next tag without pushing it.
- Custom Prefixes: Support for
v1.0.0,release-1.0.0, or no prefix at all.
To use this action, create a .yml file in your .github/workflows/ directory.
name: Auto Tag
on:
push:
branches:
- main
jobs:
tag:
runs-on: ubuntu-latest
permissions:
contents: write # Important: Required to create tags
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to see existing tags
- name: Bump version and push tag
id: tag_action
uses: anantacloud-actions/github-tag-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: patch
- name: Output New Tag
run: echo "The new tag is ${{ steps.tag_action.outputs.new_tag }}"| Input | Description | Required | Default |
|---|---|---|---|
github_token |
GITHUB_TOKEN or Personal Access Token. |
Yes | N/A |
default_bump |
Which part of the version to increment (patch, minor, major). |
No | patch |
tag_prefix |
A prefix to add to the tag (e.g., v). |
No | v |
dry_run |
If true, the action calculates the tag but does not push it. |
No | false |
| Output | Description |
|---|---|
new_tag |
The value of the newly created tag (e.g., v1.0.1). |
old_tag |
The value of the previous tag (e.g., v1.0.0). |
If you want to contribute or modify this action:
- Clone the repo.
- Install dependencies:
npm install. - Modify
src/index.js. - Build the distribution:
npm run build. - Note: The
dist/index.jsfile must be committed for the action to run.
This project is licensed under the MIT License - see the LICENSE file for details.
### Final Step: Why `fetch-depth: 0`?
I added `fetch-depth: 0` to the README example. By default, `actions/checkout` only fetches the latest commit. For your action to correctly find the **previous** tags to determine the next version, it needs the full history (or at least the tags). This is a common pitfall for users of tag actions!