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

Sticky version #281

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
91 changes: 70 additions & 21 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -55,7 +57,6 @@ fi
setOutput() {
echo "${1}=${2}" >> "${GITHUB_OUTPUT}"
}

current_branch=$(git rev-parse --abbrev-ref HEAD)

pre_release="$prerelease"
Expand All @@ -77,8 +78,49 @@ 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]+)$"
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" ]
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]+)$"
tagFmt="$tagFmt\.[0-9]+$"

if $with_v
then
tagFmt="^v$tagFmt"
preTagFmt="^v$preTagFmt"
else
tagFmt="^$tagFmt"
preTagFmt="^$preTagFmt"
fi

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=
Expand Down Expand Up @@ -155,31 +197,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
Expand Down