diff --git a/entrypoint.sh b/entrypoint.sh index 81f8065..3dfc947 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -36,8 +36,8 @@ current_branch=$(git rev-parse --abbrev-ref HEAD) pre_release="true" IFS=',' read -ra branch <<< "$release_branches" for b in "${branch[@]}"; do - echo "Is $b a match for ${current_branch}" - if [[ "${current_branch}" =~ $b ]] + # check if ${current_branch} is in ${release_branches} + if [[ "$current_branch" == "$b" ]] then pre_release="false" fi @@ -46,50 +46,55 @@ 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="^v?[0-9]+\.[0-9]+\.[0-9]+$" +preTagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)$" # get latest tag that looks like a semver (with or without v) case "$tag_context" in *repo*) - taglist="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$tagFmt")" - tag="$(semver $taglist | tail -n 1)" - - pre_taglist="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$preTagFmt")" - pre_tag="$(semver "$pre_taglist" | tail -n 1)" + tag="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$tagFmt" | head -n 1)" + pre_tag="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$preTagFmt" | head -n 1)" ;; *branch*) - taglist="$(git tag --list --merged HEAD --sort=-v:refname | grep -E "$tagFmt")" - tag="$(semver $taglist | tail -n 1)" - - pre_taglist="$(git tag --list --merged HEAD --sort=-v:refname | grep -E "$preTagFmt")" - pre_tag=$(semver "$pre_taglist" | tail -n 1) + tag="$(git tag --list --merged HEAD --sort=-v:refname | grep -E "$tagFmt" | head -n 1)" + pre_tag="$(git tag --list --merged HEAD --sort=-v:refname | grep -E "$preTagFmt" | head -n 1)" ;; - * ) echo "Unrecognised context"; exit 1;; + * ) echo "Unrecognised context" + exit 1;; esac - # if there are none, start tags at INITIAL_VERSION which defaults to 0.0.0 if [ -z "$tag" ] then - log=$(git log --pretty='%B') - tag="$initial_version" + log=$(git log --pretty='%B' --) + if $with_v + then + tag="v$initial_version" + else + tag="$initial_version" + fi if [ -z "$pre_tag" ] && $pre_release then - pre_tag="$initial_version" + if $with_v + then + pre_tag="v$initial_version" + else + pre_tag="$initial_version" + fi fi else - log=$(git log $tag..HEAD --pretty='%B') + log=$(git log ${tag}..HEAD --pretty='%B' --) fi # get current commit hash for tag -tag_commit=$(git rev-list -n 1 $tag) +tag_commit=$(git rev-list -n 1 ${tag}) # get current commit hash commit=$(git rev-parse HEAD) -if [ "$tag_commit" == "$commit" ]; then +if [ "$tag_commit" == "$commit" ] +then echo "No new commits since previous tag. Skipping..." echo ::set-output name=tag::$tag exit 0 @@ -102,16 +107,24 @@ then fi case "$log" 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";; + *#major* ) new=$(semver -i major ${tag}); part="major";; + *#minor* ) new=$(semver -i minor ${tag}); part="minor";; + *#patch* ) new=$(semver -i patch ${tag}); part="patch";; *#none* ) - echo "Default bump was set to none. Skipping..."; echo ::set-output name=new_tag::$tag; echo ::set-output name=tag::$tag; exit 0;; + echo "Default bump was set to none. Skipping..." + echo ::set-output name=new_tag::$tag + echo ::set-output name=tag::$tag + exit 0;; * ) - if [ "$default_semvar_bump" == "none" ]; then - echo "Default bump was set to none. Skipping..."; echo ::set-output name=new_tag::$tag; echo ::set-output name=tag::$tag; exit 0 + if [ "$default_semvar_bump" == "none" ] + then + echo "Default bump was set to none. Skipping..." + echo ::set-output name=new_tag::$tag + echo ::set-output name=tag::$tag + exit 0 else - new=$(semver -i "${default_semvar_bump}" $tag); part=$default_semvar_bump + new=$(semver -i "${default_semvar_bump}" ${tag}) + part=$default_semvar_bump fi ;; esac @@ -119,33 +132,39 @@ esac if $pre_release then # Already a prerelease available, bump it - if [[ "$pre_tag" == *"$new"* ]]; then - new=$(semver -i prerelease $pre_tag --preid $suffix); part="pre-$part" + 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 + echo -e "Bumping ${suffix} pre-tag ${pre_tag}. New pre-tag ${new}" else - new="$new-$suffix.1"; part="pre-$part" + if $with_v + then + new="v$new-$suffix.0" + else + new="$new-$suffix.0" + fi + echo -e "Setting ${suffix} pre-tag ${pre_tag}. With pre-tag ${new}" + fi + part="pre-$part" +else + echo -e "Bumping tag ${tag}. New tag ${new}" + if $with_v + then + new="v$new" fi fi -echo $part - -# prefix with 'v' -if $with_v -then - new="v$new" -fi - -if [ ! -z $custom_tag ] +# as defined in readme if CUSTOM_TAG is used any semver calculations are irrelevant. +if ! [ -z "$custom_tag" ] then new="$custom_tag" fi -if $pre_release -then - echo -e "Bumping tag ${pre_tag}. \n\tNew tag ${new}" -else - echo -e "Bumping tag ${tag}. \n\tNew tag ${new}" -fi - # set outputs echo ::set-output name=new_tag::$new echo ::set-output name=part::$part @@ -160,7 +179,7 @@ fi echo ::set-output name=tag::$new # create local git tag -git tag $new +git tag "$new" # push new tag ref to github dt=$(date '+%Y-%m-%dT%H:%M:%SZ') @@ -184,7 +203,8 @@ EOF git_ref_posted=$( echo "${git_refs_response}" | jq .ref | tr -d '"' ) echo "::debug::${git_refs_response}" -if [ "${git_ref_posted}" = "refs/tags/${new}" ]; then +if [ "${git_ref_posted}" = "refs/tags/${new}" ] +then exit 0 else echo "::error::Tag was not created properly."