A GitHub Action which gets version from the current github repository considering:
- optional tag matching (default match is
*- any latest tag). - optional version bumping (default bump is
none- no bumping). - optional version formatting (default format is semver format).
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # <-- This is required!
- id: get-version
uses: muravjev/get-version-action
- run: echo ${{ steps.get-version.outputs.version }}-
Tag is determined
- Match the latest tag that satisfy provided pattern (
matchparameter). - If provided pattern is
*(default) then the latest tag is taken. - If there is no matched tag found then a default value (
defaultparameter) used as a tag.
- Match the latest tag that satisfy provided pattern (
-
Version parameters determined
prefix,major,minor,patch,prereleaseandmetadataparameters are extracted from the tag, considering that the tag has semver format with optional prefix.hashparameter is determined as the latest commit hash.commitsparameter is calculated as a number of commits between latest commit and matched tag. If there is no matched tag, total number of commits is taken.
-
Bumping (optional)
Version parameters
major,minor,patchare adjusted in accordance with provided bumping scheme (bumpparameter). -
Version is formatted
Version is formatted in accordance with provided pattern (
formatandtrimparameters) where version parameters placeholders are replaced with actual version parameters.
-
match - pattern to match the latest tag to extract the version from.
format: glob(7) pattern.
default:*. -
default - tag to extract version if no tag exists or matched by
matchpattern.
values: semver version tag (e.g.1.2.3), semver tag with prefix (package@1.2.3-beta.4+build.567).
default:1.0.0 -
bump - type of the bump to perform over version values.
values:major,minor,patchornone
default:none- no bump.details
Example:
Consider that we have the following version values:major minor patch 1 2 3 Then the following will be true:
bump major minor patch none1 2 3 major200minor1 30patch1 2 4
-
format - format of the output version.
format:{prefix}{major}.{minor}.{patch}-{prerelease}+{metadata}#{commits}@{hash}.
default:{major}.{minor}.{patch}-{prerelease}+{metadata}. -
trim - fields which prefixes should be removed if its value is 'empty'.
values: pipe separated version fields.
default:prerelease|metadata|commits.details
Available fields to trim and its corresponded values considered as 'empty':
field 'empty' value prefix ''prerelease ''metadata ''patch ''or0commits ''or0Example:
Consider that we have provided the following format
{major}.{minor}.{patch}+build.{commits},
then the following will be true:major minor patch commits trim result 1 2 3 4 doesn't matter 1.2.3+build.4 1 3 0 0 none 1.2.0+build.0 1 2 0 0 patch|commits1.2 1 2 0 0 patch1.2+build.0 1 2 0 0 commits1.2.0
- version - Formatted version.
Want to contribute? Awesome! The most basic way to show your support is to star ⭐ the project, or to raise issues. If you want to open a pull request, please read the Contributing Guidelines.
| If you found this project helpful, consider |
|---|
| buying me a coffee, donate by paypal or just leave a star⭐ |
| Thanks for your support, it is much appreciated! |