Skip to content

Commit da70c4e

Browse files
authored
Merge pull request #326 from timothyclarke/Issue_320/prefix
Added TAG_PREFIX so more descriptive tags can be used
2 parents f278d49 + ed6507f commit da70c4e

2 files changed

Lines changed: 38 additions & 40 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
uses: anothrNick/github-tag-action@v1 # Don't use @master or @v1 unless you're happy to test the latest version
3939
env:
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
41-
WITH_V: false
4241
```
4342
4443
```yaml
@@ -67,7 +66,7 @@ jobs:
6766
uses: anothrNick/github-tag-action@v1 # Don't use @master or @v1 unless you're happy to test the latest version
6867
env:
6968
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # if you don't want to set write permissions use a PAT token
70-
WITH_V: true
69+
TAG_PREFIX: v
7170
PRERELEASE: true
7271

7372
```
@@ -85,14 +84,15 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` or newer to be sure you ret
8584
- **GITHUB_TOKEN** **_(required)_** - Required for permission to tag the repo.
8685
- **DEFAULT_BUMP** _(optional)_ - Which type of bump to use when none explicitly provided (default: `minor`).
8786
- **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.
88-
- **WITH_V** _(optional)_ - Tag version with `v` character.
87+
- **WITH_V** _(optional, deprecated)_ - Tag version with `v` character. Replaced by TAG_PREFIX
8988
- **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` ...
9089
- **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!**
9190
- **SOURCE** _(optional)_ - Operate on a relative path under $GITHUB_WORKSPACE.
9291
- **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).
9392
- **GIT_API_TAGGING** _(optional)_ - Set if using git cli or git api calls for tag push operations. Possible values are `false` and `true` (default).
94-
- **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
93+
- **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
9594
- **TAG_CONTEXT** _(optional)_ - Set the context of the previous tag. Possible values are `repo` (default) or `branch`.
95+
- **TAG_PREFIX** _(optional)_ - Prefix to add to the tag. eg `v` to create `v0.0.0`. This takes precidance over WITH_V
9696
- **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).
9797
- **PRERELEASE_SUFFIX** _(optional)_ - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch.
9898
- **VERBOSE** _(optional)_ - Print git logs. For some projects these logs may be very large. Possible values are `true` (default) and `false`.

entrypoint.sh

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dryrun=${DRY_RUN:-false}
1313
git_api_tagging=${GIT_API_TAGGING:-true}
1414
initial_version=${INITIAL_VERSION:-0.0.0}
1515
tag_context=${TAG_CONTEXT:-repo}
16+
tag_prefix=${TAG_PREFIX:-false}
1617
prerelease=${PRERELEASE:-false}
1718
suffix=${PRERELEASE_SUFFIX:-beta}
1819
verbose=${VERBOSE:-false}
@@ -41,6 +42,7 @@ echo -e "\tDRY_RUN: ${dryrun}"
4142
echo -e "\tGIT_API_TAGGING: ${git_api_tagging}"
4243
echo -e "\tINITIAL_VERSION: ${initial_version}"
4344
echo -e "\tTAG_CONTEXT: ${tag_context}"
45+
echo -e "\tTAG_PREFIX: ${tag_prefix}"
4446
echo -e "\tPRERELEASE: ${prerelease}"
4547
echo -e "\tPRERELEASE_SUFFIX: ${suffix}"
4648
echo -e "\tVERBOSE: ${verbose}"
@@ -84,8 +86,22 @@ echo "pre_release = $pre_release"
8486
# fetch tags
8587
git fetch --tags
8688

87-
tagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+$"
88-
preTagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)$"
89+
# Set no tag prefix (not even v)
90+
tagPrefix=""
91+
92+
if $with_v
93+
then
94+
tagPrefix="v"
95+
fi
96+
97+
# If a tag_prefix is supplied use that
98+
if [[ "${tag_prefix}" != "false" ]]
99+
then
100+
tagPrefix=$tag_prefix
101+
fi
102+
103+
tagFmt="^$tagPrefix?[0-9]+\.[0-9]+\.[0-9]+$"
104+
preTagFmt="^$tagPrefix?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)$"
89105

90106
# get the git refs
91107
git_refs=
@@ -109,20 +125,10 @@ pre_tag=$(head -n 1 <<< "$matching_pre_tag_refs")
109125
# if there are none, start tags at initial version
110126
if [ -z "$tag" ]
111127
then
112-
if $with_v
113-
then
114-
tag="v$initial_version"
115-
else
116-
tag="$initial_version"
117-
fi
128+
tag="$tagPrefix$initial_version"
118129
if [ -z "$pre_tag" ] && $pre_release
119130
then
120-
if $with_v
121-
then
122-
pre_tag="v$initial_version"
123-
else
124-
pre_tag="$initial_version"
125-
fi
131+
pre_tag="$tagPrefix$initial_version"
126132
fi
127133
fi
128134

@@ -131,7 +137,7 @@ tag_commit=$(git rev-list -n 1 "$tag" || true )
131137
# get current commit hash
132138
commit=$(git rev-parse HEAD)
133139
# skip if there are no new commits for non-pre_release
134-
if [ "$tag_commit" == "$commit" ] && [ "$force_without_changes" == "false" ]
140+
if [ "$tag_commit" == "$commit" ] && [ "$force_without_changes" == "false" ]
135141
then
136142
echo "No new commits since previous tag. Skipping..."
137143
setOutput "new_tag" "$tag"
@@ -162,10 +168,16 @@ declare -A history_type=(
162168
log=${history_type[${branch_history}]}
163169
printf "History:\n---\n%s\n---\n" "$log"
164170

171+
if [ -z "$tagPrefix" ]
172+
then
173+
current_tag=${tag}
174+
else
175+
current_tag="$(echo ${tag}| sed "s/${tagPrefix}//g")"
176+
fi
165177
case "$log" in
166-
*$major_string_token* ) new=$(semver -i major "$tag"); part="major";;
167-
*$minor_string_token* ) new=$(semver -i minor "$tag"); part="minor";;
168-
*$patch_string_token* ) new=$(semver -i patch "$tag"); part="patch";;
178+
*$major_string_token* ) new=${tagPrefix}$(semver -i major "${current_tag}"); part="major";;
179+
*$minor_string_token* ) new=${tagPrefix}$(semver -i minor "${current_tag}"); part="minor";;
180+
*$patch_string_token* ) new=${tagPrefix}$(semver -i patch "${current_tag}"); part="patch";;
169181
*$none_string_token* )
170182
echo "Default bump was set to none. Skipping..."
171183
setOutput "old_tag" "$tag"
@@ -183,7 +195,7 @@ case "$log" in
183195
setOutput "part" "$default_semvar_bump"
184196
exit 0
185197
else
186-
new=$(semver -i "${default_semvar_bump}" "$tag")
198+
new=${tagPrefix}$(semver -i "${default_semvar_bump}" "${current_tag}")
187199
part=$default_semvar_bump
188200
fi
189201
;;
@@ -194,7 +206,7 @@ then
194206
# get current commit hash for tag
195207
pre_tag_commit=$(git rev-list -n 1 "$pre_tag" || true)
196208
# skip if there are no new commits for pre_release
197-
if [ "$pre_tag_commit" == "$commit" ] && [ "$force_without_changes_pre" == "false" ]
209+
if [ "$pre_tag_commit" == "$commit" ] && [ "$force_without_changes_pre" == "false" ]
198210
then
199211
echo "No new commits since previous pre_tag. Skipping..."
200212
setOutput "new_tag" "$pre_tag"
@@ -204,28 +216,14 @@ then
204216
# already a pre-release available, bump it
205217
if [[ "$pre_tag" =~ $new ]] && [[ "$pre_tag" =~ $suffix ]]
206218
then
207-
if $with_v
208-
then
209-
new=v$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
210-
else
211-
new=$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
212-
fi
219+
new=${tagPrefix}$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
213220
echo -e "Bumping ${suffix} pre-tag ${pre_tag}. New pre-tag ${new}"
214221
else
215-
if $with_v
216-
then
217-
new="v$new-$suffix.0"
218-
else
219-
new="$new-$suffix.0"
220-
fi
222+
new="${tagPrefix}${new}-${suffix}.0"
221223
echo -e "Setting ${suffix} pre-tag ${pre_tag} - With pre-tag ${new}"
222224
fi
223225
part="pre-$part"
224226
else
225-
if $with_v
226-
then
227-
new="v$new"
228-
fi
229227
echo -e "Bumping tag ${tag} - New tag ${new}"
230228
fi
231229

0 commit comments

Comments
 (0)