From c4321d9d98c19b8f493b7b2cce8790c6bf529442 Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 18 Aug 2023 13:58:56 +0300 Subject: [PATCH 1/4] init --- entrypoint.sh | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 83e3d39a..ce24347b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,6 +21,8 @@ minor_string_token=${MINOR_STRING_TOKEN:-#minor} patch_string_token=${PATCH_STRING_TOKEN:-#patch} none_string_token=${NONE_STRING_TOKEN:-#none} branch_history=${BRANCH_HISTORY:-compare} +major_sticky_version=${MAJOR_STICKY_VERSION} +minor_sticky_version=${MINOR_STICKY_VERSION} # since https://github.blog/2022-04-12-git-security-vulnerability-announced/ runner uses? git config --global --add safe.directory /github/workspace @@ -55,7 +57,7 @@ fi setOutput() { echo "${1}=${2}" >> "${GITHUB_OUTPUT}" } - +pwd current_branch=$(git rev-parse --abbrev-ref HEAD) pre_release="$prerelease" @@ -77,8 +79,35 @@ 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]+)$" +tagFmt='' +if [ -z "$major_sticky_version" ] +then + tagFmt='[0-9]+' +else + tagFmt="$major_sticky_version" +fi + +if [ -z "$minor_sticky_version" ] +then + tagFmt="$tagFmt\.[0-9]+" +else + tagFmt="$tagFmt\.$minor_sticky_version" +fi + +preTagFmt="$tagFmt\.[0-9]+(-$suffix\.[0-9]+)$" +tagFmt="$tagFmt\.[0-9]+$" + +if $with_v +then + tagFmt="^v$tagFmt" + preTagFmt="^v$preTagFmt" +else + tagFmt="^$tagFmt" + preTagFmt="^$preTagFmt" +fi + +echo "tagFmt = $tagFmt" +echo "preTagFmt = $preTagFmt" # get the git refs git_refs= From 911db27971f3355e7f71f4c4e9585d715ce4fb6e Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 18 Aug 2023 15:03:24 +0300 Subject: [PATCH 2/4] fix --- README.md | 2 ++ entrypoint.sh | 85 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 6a9672f1..0a874277 100755 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` or newer to be sure you ret - `full`: attempt to show all history, does not work on rebase and squash due missing HEAD [should be deprecated in v2 is breaking many workflows] - `last`: show the single last commit - `compare`: show all commits since previous repo tag number +- **MAJOR_STICKY_VERSION** _(optional)_ - Set the `X` part of `X.Y.Z` version to be constant +- **MINOR_STICKY_VERSION** _(optional)_ - Set the `Y` part of `X.Y.Z` version to be constant. Should be used with `MAJOR_STICKY_VERSION` ### Outputs diff --git a/entrypoint.sh b/entrypoint.sh index ce24347b..0e7a7ebb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -79,12 +79,20 @@ echo "pre_release = $pre_release" # fetch tags git fetch --tags -tagFmt='' +if [ -z "$major_sticky_version" ] && ! [ -z "$minor_sticky_version" ] +then + echo "invalid sticky version" + exit 1 +fi + +tagFmt= +sticky_prefix= if [ -z "$major_sticky_version" ] then tagFmt='[0-9]+' else tagFmt="$major_sticky_version" + sticky_prefix="$major_sticky_version" fi if [ -z "$minor_sticky_version" ] @@ -92,6 +100,7 @@ then tagFmt="$tagFmt\.[0-9]+" else tagFmt="$tagFmt\.$minor_sticky_version" + sticky_prefix="$sticky_prefix.$minor_sticky_version" fi preTagFmt="$tagFmt\.[0-9]+(-$suffix\.[0-9]+)$" @@ -99,15 +108,20 @@ tagFmt="$tagFmt\.[0-9]+$" if $with_v then - tagFmt="^v$tagFmt" - preTagFmt="^v$preTagFmt" + tagFmt="^v$tagFmt" + preTagFmt="^v$preTagFmt" else - tagFmt="^$tagFmt" - preTagFmt="^$preTagFmt" + tagFmt="^$tagFmt" + preTagFmt="^$preTagFmt" fi -echo "tagFmt = $tagFmt" -echo "preTagFmt = $preTagFmt" +case "$initial_version" in + "$sticky_prefix"* ) + initial_version="$initial_version";; + * ) echo "fixing initial version $initial_version" + initial_version="$major_sticky_version.${minor_sticky_version:-0}.0" + echo "initial_version=$initial_version";; +esac # get the git refs git_refs= @@ -153,13 +167,13 @@ 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" ] -then - echo "No new commits since previous tag. Skipping..." - setOutput "new_tag" "$tag" - setOutput "tag" "$tag" - exit 0 -fi +#if [ "$tag_commit" == "$commit" ] +#then +# echo "No new commits since previous tag. Skipping..." +# setOutput "new_tag" "$tag" +# setOutput "tag" "$tag" +# exit 0 +#fi # sanitize that the default_branch is set (via env var when running on PRs) else find it natively if [ -z "${default_branch}" ] && [ "$branch_history" == "full" ] @@ -184,31 +198,38 @@ declare -A history_type=( log=${history_type[${branch_history}]} printf "History:\n---\n%s\n---\n" "$log" +part= 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";; - *$none_string_token* ) + *$major_string_token* ) part="major";; + *$minor_string_token* ) part="minor";; + *$patch_string_token* ) part="patch";; + *$none_string_token* ) part="none";; + * ) part="$default_semvar_bump";; +esac + +if ! [ -z "$major_sticky_version" ] && [ "$part" == "major" ]; +then + part="minor"; +fi + +if ! [ -z "$minor_sticky_version" ] && [ "$part" == "minor" ]; +then + part="patch"; +fi + + + +case "$part" in + major ) new=$(semver -i major "$tag"); part="major";; + minor ) new=$(semver -i minor "$tag"); part="minor";; + patch ) new=$(semver -i patch "$tag"); part="patch";; + * ) echo "Default bump was set to none. Skipping..." setOutput "old_tag" "$tag" setOutput "new_tag" "$tag" setOutput "tag" "$tag" setOutput "part" "$default_semvar_bump" exit 0;; - * ) - if [ "$default_semvar_bump" == "none" ] - then - echo "Default bump was set to none. Skipping..." - setOutput "old_tag" "$tag" - setOutput "new_tag" "$tag" - setOutput "tag" "$tag" - setOutput "part" "$default_semvar_bump" - exit 0 - else - new=$(semver -i "${default_semvar_bump}" "$tag") - part=$default_semvar_bump - fi - ;; esac if $pre_release From fa29f393ebd357f5bde2c7d559867e54c32608c4 Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 18 Aug 2023 15:06:39 +0300 Subject: [PATCH 3/4] fix --- entrypoint.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0e7a7ebb..89e5c57c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -57,7 +57,6 @@ fi setOutput() { echo "${1}=${2}" >> "${GITHUB_OUTPUT}" } -pwd current_branch=$(git rev-parse --abbrev-ref HEAD) pre_release="$prerelease" From 90978523ddcede18292c3884d8c459e6326eb5d8 Mon Sep 17 00:00:00 2001 From: akvlad Date: Fri, 18 Aug 2023 15:22:49 +0300 Subject: [PATCH 4/4] uncomment exit on no commits --- entrypoint.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 89e5c57c..4dc2afbe 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -166,13 +166,13 @@ 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" ] -#then -# echo "No new commits since previous tag. Skipping..." -# setOutput "new_tag" "$tag" -# setOutput "tag" "$tag" -# exit 0 -#fi +if [ "$tag_commit" == "$commit" ] +then + echo "No new commits since previous tag. Skipping..." + setOutput "new_tag" "$tag" + setOutput "tag" "$tag" + exit 0 +fi # sanitize that the default_branch is set (via env var when running on PRs) else find it natively if [ -z "${default_branch}" ] && [ "$branch_history" == "full" ]