Generate your next Semantic Version based on Conventional Commit, update whatever.json and bump Tag to Git repository, via Bash, for low dependency and saving precious seconds !
🚸 This action update the last commit to avoid creating another one
🔰 SUPPORT ONLY .JSON FILE (for now)
✅ OS COMPATIBILITY
- Linux
MacOS(SOON)
✅ LANGAGE and PROGRAM USED
- This script work with Bash 4+
- Use JQ to manipulate JSON file
This action generate version based on the last git tag and the prefix of the last commit message, and only the last.
It take consideration of 'SemVer' and 'Conventional Commit'.
If no git tag exist, the version begin at '0.0.0' to start the process, so, if your last commit contains, for example, 'feat: my best feature ever !', then the generated version will be '0.1.0'.
This action give you multiple functions to deal with your version control:
- Generate RELEASE version (1.0.0)
- Generate SNAPSHOT version (1.0.1-SNAPSHOT)
- Add PREFIX to RELEASE and SNAPSHOT (v1.0.1)
- Manage SEMVER keywords (BREAKING/feat/patch)
- Update any JSON file (only if .version key's first element in data structure)
- Create TAG to repository on the triggered commit
When 'enable-snapshot' is 'true', this action calculate the next version, and add '-SNAPSHOT.1' suffix, so, if your last commit contains, for example, 'fix: the best until that tiny bug', then the generated version will be '0.1.1-SNAPSHOT.1'.
If the next one is a 'patch' too, then the version will be '0.1.1-SNAPSHOT.2', etc... until semver kind's changed for something else than the previous commit's semver kind, 'patch' here.
So, if the next commit contains a 'feat' prefix, then the next snapshot will be '0.2.0-SNAPSHOT.1', same for 'BREAKING', etc...
The goal is to work for GitFlow based development, with two principal branches, e.g. 'main' and 'develop'.
On the 'develop' branch, we generate SNAPSHOT to try if everything's ok, and when it is, we merge on 'main' to remove the suffix and release the final release version '0.1.1'.
INPUT | Description | Default |
---|---|---|
bump-tag |
Bump Tag to Git repository | true |
file-update |
Updates file with new semver and add change to last commit | true |
file-path |
Path to the file to update | package.json |
major |
Keyword for MAJOR | BREAKING |
minor |
Keyword for MINOR | feat |
prefix |
Set prefix to your tag | |
enable-snapshot |
Generate SNAPSHOT instead of RELEASE | false |
snapshot-suffix |
Suffix keyword for SNAPSHOT versioning | SNAPSHOT |
OUTPUT | Description | Example |
---|---|---|
semver |
Your next SemVer as string | 0.1.1 or v0.1.1 or 0.1.1-SNAPSHOT.1 |
COMPLETE WORKFLOW with INPUTS and OUTPUT
name: AutoBashed SemVer
on: push
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: "Generate Next SemVer"
id: version
uses: bencatlab/autobashed-semver@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
bump-tag: 'true' # Bump tag to Git repository
file-update: 'true' # Updates file with new semver and add change to last commit
file-path: 'package.json' # Path to the file to update
major: 'BREAKING CHANGE' # Keyword for MAJOR
minor: 'feature' # Keyword for MINOR
prefix: 'v' # Set a prefix to your tag
enable-snapshot: 'true' # Generate as SNAPSHOT instead of RELEASE
snapshot-suffix: 'beta' # Suffix for SNAPSHOT versioning (e.g. 1.0.1-beta.1)
- name: "Output SemVer from previous Step"
run: echo "${{ steps.version.outputs.semver }}"
USING RELEASE with OUTPUT
- name: "Generate Next SemVer"
id: version
uses: bencatlab/autobashed-semver@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
bump-tag: 'false'
file-path: 'version.json'
prefix: ''
- name: "Output SemVer from previous Step"
run: echo "${{ steps.version.outputs.semver }}"
USING SNAPSHOT with OUTPUT
- name: "Generate Next SemVer"
id: version
uses: bencatlab/autobashed-semver@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file-update: 'false'
prefix: 'v'
enable-snapshot: 'true'
snapshot-suffix: 'beta'
- name: "Output SemVer from previous Step"
run: echo "${{ steps.version.outputs.semver }}"
A few things that I currently work on to complet v2
- Update any kind of files
- Option to define default version
- Option to handle patch keyword in addition to major and minor
- 🎉
Option to define SNAPSHOT suffix keyword - Implement all conventional-commit keyword
- Update multiple files at once
- Handle more error cases
Non exhaustive list, I guess... 😣
- If two tags are on the same commit (you should not but... let's imagine), the latest one cannot be determined
- [SOLUTION] Keep only one tag on the same commit. Simple, basic
- If you change 'snapshot-suffix' value while you've already start using another, the new one will be paste after the older instead of being replaced
- [SOLUTION] Be sure that the latest tag is not a SNAPSHOTed version, e.g. '1.0.1'
- I'm French, and my English is limited... so, please
- [SOLUTION] Open new PR to correct this README and help me to improve myself !
- If you find a new one, please
- [SOLUTION] Open new issue, it would be very appreciated 💌
Feel free to contact me 📧