Skip to content

Commit 3acdde7

Browse files
committed
Added TAG_PREFIX
1 parent 777684d commit 3acdde7

2 files changed

Lines changed: 33 additions & 38 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` or newer to be sure you ret
8585
- **GITHUB_TOKEN** **_(required)_** - Required for permission to tag the repo.
8686
- **DEFAULT_BUMP** _(optional)_ - Which type of bump to use when none explicitly provided (default: `minor`).
8787
- **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.
88+
- **WITH_V** _(optional, depricated)_ - Tag version with `v` character. Replaced by TAG_PREFIX
8989
- **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` ...
9090
- **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!**
9191
- **SOURCE** _(optional)_ - Operate on a relative path under $GITHUB_WORKSPACE.
9292
- **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).
9393
- **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
94+
- **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
9595
- **TAG_CONTEXT** _(optional)_ - Set the context of the previous tag. Possible values are `repo` (default) or `branch`.
96+
- **TAG_PREFIX** _(optional)_ - Prefix to add to the tag. eg `v` to create `v0.0.0`, WITH_V takes precidance for backwards compatibility
9697
- **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).
9798
- **PRERELEASE_SUFFIX** _(optional)_ - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch.
9899
- **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: 30 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}
@@ -40,6 +41,7 @@ echo -e "\tDRY_RUN: ${dryrun}"
4041
echo -e "\tGIT_API_TAGGING: ${git_api_tagging}"
4142
echo -e "\tINITIAL_VERSION: ${initial_version}"
4243
echo -e "\tTAG_CONTEXT: ${tag_context}"
44+
echo -e "\tTAG_PREFIX: ${tag_prefix}"
4345
echo -e "\tPRERELEASE: ${prerelease}"
4446
echo -e "\tPRERELEASE_SUFFIX: ${suffix}"
4547
echo -e "\tVERBOSE: ${verbose}"
@@ -82,8 +84,23 @@ echo "pre_release = $pre_release"
8284
# fetch tags
8385
git fetch --tags
8486

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

88105
# get the git refs
89106
git_refs=
@@ -107,20 +124,10 @@ pre_tag=$(head -n 1 <<< "$matching_pre_tag_refs")
107124
# if there are none, start tags at initial version
108125
if [ -z "$tag" ]
109126
then
110-
if $with_v
111-
then
112-
tag="v$initial_version"
113-
else
114-
tag="$initial_version"
115-
fi
127+
tag="$tagPrefix$initial_version"
116128
if [ -z "$pre_tag" ] && $pre_release
117129
then
118-
if $with_v
119-
then
120-
pre_tag="v$initial_version"
121-
else
122-
pre_tag="$initial_version"
123-
fi
130+
pre_tag="$tagPrefix$initial_version"
124131
fi
125132
fi
126133

@@ -129,7 +136,7 @@ tag_commit=$(git rev-list -n 1 "$tag" || true )
129136
# get current commit hash
130137
commit=$(git rev-parse HEAD)
131138
# skip if there are no new commits for non-pre_release
132-
if [ "$tag_commit" == "$commit" ] && [ "$force_without_changes" == "false" ]
139+
if [ "$tag_commit" == "$commit" ] && [ "$force_without_changes" == "false" ]
133140
then
134141
echo "No new commits since previous tag. Skipping..."
135142
setOutput "new_tag" "$tag"
@@ -160,10 +167,11 @@ declare -A history_type=(
160167
log=${history_type[${branch_history}]}
161168
printf "History:\n---\n%s\n---\n" "$log"
162169

170+
current_tag="$(echo ${tag}| sed "s/${tagPrefix}//g")"
163171
case "$log" in
164-
*$major_string_token* ) new=$(semver -i major "$tag"); part="major";;
165-
*$minor_string_token* ) new=$(semver -i minor "$tag"); part="minor";;
166-
*$patch_string_token* ) new=$(semver -i patch "$tag"); part="patch";;
172+
*$major_string_token* ) new=${tagPrefix}$(semver -i major "${current_tag}"); part="major";;
173+
*$minor_string_token* ) new=${tagPrefix}$(semver -i minor "${current_tag}"); part="minor";;
174+
*$patch_string_token* ) new=${tagPrefix}$(semver -i patch "${current_tag}"); part="patch";;
167175
*$none_string_token* )
168176
echo "Default bump was set to none. Skipping..."
169177
setOutput "old_tag" "$tag"
@@ -181,7 +189,7 @@ case "$log" in
181189
setOutput "part" "$default_semvar_bump"
182190
exit 0
183191
else
184-
new=$(semver -i "${default_semvar_bump}" "$tag")
192+
new=${tagPrefix}$(semver -i "${default_semvar_bump}" "${current_tag}")
185193
part=$default_semvar_bump
186194
fi
187195
;;
@@ -192,7 +200,7 @@ then
192200
# get current commit hash for tag
193201
pre_tag_commit=$(git rev-list -n 1 "$pre_tag" || true)
194202
# skip if there are no new commits for pre_release
195-
if [ "$pre_tag_commit" == "$commit" ] && [ "$force_without_changes_pre" == "false" ]
203+
if [ "$pre_tag_commit" == "$commit" ] && [ "$force_without_changes_pre" == "false" ]
196204
then
197205
echo "No new commits since previous pre_tag. Skipping..."
198206
setOutput "new_tag" "$pre_tag"
@@ -202,28 +210,14 @@ then
202210
# already a pre-release available, bump it
203211
if [[ "$pre_tag" =~ $new ]] && [[ "$pre_tag" =~ $suffix ]]
204212
then
205-
if $with_v
206-
then
207-
new=v$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
208-
else
209-
new=$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
210-
fi
213+
new=${tagPrefix}$(semver -i prerelease "${pre_tag}" --preid "${suffix}")
211214
echo -e "Bumping ${suffix} pre-tag ${pre_tag}. New pre-tag ${new}"
212215
else
213-
if $with_v
214-
then
215-
new="v$new-$suffix.0"
216-
else
217-
new="$new-$suffix.0"
218-
fi
216+
new="${tagPrefix}${new}-${suffix}.0"
219217
echo -e "Setting ${suffix} pre-tag ${pre_tag} - With pre-tag ${new}"
220218
fi
221219
part="pre-$part"
222220
else
223-
if $with_v
224-
then
225-
new="v$new"
226-
fi
227221
echo -e "Bumping tag ${tag} - New tag ${new}"
228222
fi
229223

0 commit comments

Comments
 (0)