Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TAG_PREFIX so more descriptive tags can be used #326

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
uses: anothrNick/github-tag-action@v1 # Don't use @master or @v1 unless you're happy to test the latest version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
WITH_V: false
```

```yaml
Expand Down Expand Up @@ -67,7 +66,7 @@ jobs:
uses: anothrNick/github-tag-action@v1 # Don't use @master or @v1 unless you're happy to test the latest version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
WITH_V: true
TAG_PREFIX: v
PRERELEASE: true

```
Expand All @@ -85,14 +84,15 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` or newer to be sure you ret
- **GITHUB_TOKEN** **_(required)_** - Required for permission to tag the repo.
- **DEFAULT_BUMP** _(optional)_ - Which type of bump to use when none explicitly provided (default: `minor`).
- **DEFAULT_BRANCH** _(optional)_ - Overwrite the default branch its read from GitHub Runner env var but can be overwritten (default: `$GITHUB_BASE_REF`). Strongly recommended to set this var if using anything else than master or main as default branch otherwise in combination with history full will error.
- **WITH_V** _(optional)_ - Tag version with `v` character.
- **WITH_V** _(optional, depricated)_ - Tag version with `v` character. Replaced by TAG_PREFIX

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **WITH_V** _(optional, depricated)_ - Tag version with `v` character. Replaced by TAG_PREFIX
- **WITH_V** _(optional, deprecated)_ - Tag version with `v` character. Replaced by TAG_PREFIX

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robw-raviga Thanks. Fixed in ed6507f

- **RELEASE_BRANCHES** _(optional)_ - Comma separated list of branches (bash reg exp accepted) that will generate the release tags. Other branches and pull-requests generate versions postfixed with the commit hash and do not generate any tag. Examples: `master` or `.*` or `release.*,hotfix.*,master` ...
- **CUSTOM_TAG** _(optional)_ - Set a custom tag, useful when generating tag based on f.ex FROM image in a docker image. **Setting this tag will invalidate any other settings set!**
- **SOURCE** _(optional)_ - Operate on a relative path under $GITHUB_WORKSPACE.
- **DRY_RUN** _(optional)_ - Determine the next version without tagging the branch. The workflow can use the outputs `new_tag` and `tag` in subsequent steps. Possible values are `true` and `false` (default).
- **GIT_API_TAGGING** _(optional)_ - Set if using git cli or git api calls for tag push operations. Possible values are `false` and `true` (default).
- **INITIAL_VERSION** _(optional)_ - Set initial version before bump. Default `0.0.0`. MAKE SURE NOT TO USE vX.X.X here if combined WITH_V
- **INITIAL_VERSION** _(optional)_ - Set initial version before bump. Default `0.0.0`. MAKE SURE NOT TO USE vX.X.X here if combined TAG_PREFIX
- **TAG_CONTEXT** _(optional)_ - Set the context of the previous tag. Possible values are `repo` (default) or `branch`.
- **TAG_PREFIX** _(optional)_ - Prefix to add to the tag. eg `v` to create `v0.0.0`. This takes precidance over WITH_V
- **PRERELEASE** _(optional)_ - Define if workflow runs in prerelease mode, `false` by default. Note this will be overwritten if using complex suffix release branches. Use it with checkout `ref: ${{ github.sha }}` for consistency see [issue 266](https://github.com/anothrNick/github-tag-action/issues/266).
- **PRERELEASE_SUFFIX** _(optional)_ - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch.
- **VERBOSE** _(optional)_ - Print git logs. For some projects these logs may be very large. Possible values are `true` (default) and `false`.
Expand Down
70 changes: 34 additions & 36 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dryrun=${DRY_RUN:-false}
git_api_tagging=${GIT_API_TAGGING:-true}
initial_version=${INITIAL_VERSION:-0.0.0}
tag_context=${TAG_CONTEXT:-repo}
tag_prefix=${TAG_PREFIX:-false}
prerelease=${PRERELEASE:-false}
suffix=${PRERELEASE_SUFFIX:-beta}
verbose=${VERBOSE:-false}
Expand Down Expand Up @@ -40,6 +41,7 @@ echo -e "\tDRY_RUN: ${dryrun}"
echo -e "\tGIT_API_TAGGING: ${git_api_tagging}"
echo -e "\tINITIAL_VERSION: ${initial_version}"
echo -e "\tTAG_CONTEXT: ${tag_context}"
echo -e "\tTAG_PREFIX: ${tag_prefix}"
echo -e "\tPRERELEASE: ${prerelease}"
echo -e "\tPRERELEASE_SUFFIX: ${suffix}"
echo -e "\tVERBOSE: ${verbose}"
Expand Down Expand Up @@ -82,8 +84,22 @@ echo "pre_release = $pre_release"
# fetch tags
git fetch --tags

tagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+$"
preTagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)$"
# Set no tag prefix (not even v)
tagPrefix=""

if $with_v
then
tagPrefix="v"
fi

# If a tag_prefix is supplied use that
if [[ "${tag_prefix}" != "false" ]]
then
tagPrefix=$tag_prefix
fi

tagFmt="^$tagPrefix?[0-9]+\.[0-9]+\.[0-9]+$"
preTagFmt="^$tagPrefix?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)$"

# get the git refs
git_refs=
Expand All @@ -107,20 +123,10 @@ pre_tag=$(head -n 1 <<< "$matching_pre_tag_refs")
# if there are none, start tags at initial version
if [ -z "$tag" ]
then
if $with_v
then
tag="v$initial_version"
else
tag="$initial_version"
fi
tag="$tagPrefix$initial_version"
if [ -z "$pre_tag" ] && $pre_release
then
if $with_v
then
pre_tag="v$initial_version"
else
pre_tag="$initial_version"
fi
pre_tag="$tagPrefix$initial_version"
fi
fi

Expand All @@ -129,7 +135,7 @@ tag_commit=$(git rev-list -n 1 "$tag" || true )
# get current commit hash
commit=$(git rev-parse HEAD)
# skip if there are no new commits for non-pre_release
if [ "$tag_commit" == "$commit" ] && [ "$force_without_changes" == "false" ]
if [ "$tag_commit" == "$commit" ] && [ "$force_without_changes" == "false" ]
then
echo "No new commits since previous tag. Skipping..."
setOutput "new_tag" "$tag"
Expand Down Expand Up @@ -160,10 +166,16 @@ declare -A history_type=(
log=${history_type[${branch_history}]}
printf "History:\n---\n%s\n---\n" "$log"

if [ -z "$tagPrefix" ]
then
current_tag=${tag}
else
current_tag="$(echo ${tag}| sed "s/${tagPrefix}//g")"
fi
case "$log" in
*$major_string_token* ) new=$(semver -i major "$tag"); part="major";;
*$minor_string_token* ) new=$(semver -i minor "$tag"); part="minor";;
*$patch_string_token* ) new=$(semver -i patch "$tag"); part="patch";;
*$major_string_token* ) new=${tagPrefix}$(semver -i major "${current_tag}"); part="major";;
*$minor_string_token* ) new=${tagPrefix}$(semver -i minor "${current_tag}"); part="minor";;
*$patch_string_token* ) new=${tagPrefix}$(semver -i patch "${current_tag}"); part="patch";;
*$none_string_token* )
echo "Default bump was set to none. Skipping..."
setOutput "old_tag" "$tag"
Expand All @@ -181,7 +193,7 @@ case "$log" in
setOutput "part" "$default_semvar_bump"
exit 0
else
new=$(semver -i "${default_semvar_bump}" "$tag")
new=${tagPrefix}$(semver -i "${default_semvar_bump}" "${current_tag}")
part=$default_semvar_bump
fi
;;
Expand All @@ -192,7 +204,7 @@ then
# get current commit hash for tag
pre_tag_commit=$(git rev-list -n 1 "$pre_tag" || true)
# skip if there are no new commits for pre_release
if [ "$pre_tag_commit" == "$commit" ] && [ "$force_without_changes_pre" == "false" ]
if [ "$pre_tag_commit" == "$commit" ] && [ "$force_without_changes_pre" == "false" ]
then
echo "No new commits since previous pre_tag. Skipping..."
setOutput "new_tag" "$pre_tag"
Expand All @@ -202,28 +214,14 @@ then
# already a pre-release available, bump it
if [[ "$pre_tag" =~ $new ]] && [[ "$pre_tag" =~ $suffix ]]
then
if $with_v
then
new=v$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
else
new=$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
fi
new=${tagPrefix}$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
echo -e "Bumping ${suffix} pre-tag ${pre_tag}. New pre-tag ${new}"
else
if $with_v
then
new="v$new-$suffix.0"
else
new="$new-$suffix.0"
fi
new="${tagPrefix}${new}-${suffix}.0"
echo -e "Setting ${suffix} pre-tag ${pre_tag} - With pre-tag ${new}"
fi
part="pre-$part"
else
if $with_v
then
new="v$new"
fi
echo -e "Bumping tag ${tag} - New tag ${new}"
fi

Expand Down