From e2b50856d854c67daa74033beda8d2650a0d9b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 22 Nov 2020 02:18:47 +0100 Subject: [PATCH 01/63] Added new optional PREFIX parameter to define a tag prefix --- entrypoint.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2988c600..4036913f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,7 +4,7 @@ set -o pipefail # config default_semvar_bump=${DEFAULT_BUMP:-minor} -with_v=${WITH_V:-false} +prefix=${PREFIX} release_branches=${RELEASE_BRANCHES:-master,main} custom_tag=${CUSTOM_TAG} source=${SOURCE:-.} @@ -18,7 +18,7 @@ cd ${GITHUB_WORKSPACE}/${source} echo "*** CONFIGURATION ***" echo -e "\tDEFAULT_BUMP: ${default_semvar_bump}" -echo -e "\tWITH_V: ${with_v}" +echo -e "\tPREFIX: ${prefix}" echo -e "\tRELEASE_BRANCHES: ${release_branches}" echo -e "\tCUSTOM_TAG: ${custom_tag}" echo -e "\tSOURCE: ${source}" @@ -85,6 +85,7 @@ then echo $log fi +tagWithoutPrefix=${tag#"$prefix"} case "$log" in *#major* ) new=$(semver -i major $tag); part="major";; *#minor* ) new=$(semver -i minor $tag); part="minor";; @@ -95,7 +96,7 @@ case "$log" in 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}" $tagWithoutPrefix); part=$default_semvar_bump fi ;; esac @@ -116,9 +117,9 @@ echo $part if [ ! -z "$new" ] then # prefix with 'v' - if $with_v + if [ ! -z "$prefix" ] then - new="v$new" + new="$prefix$new" fi fi @@ -136,6 +137,7 @@ fi # set outputs echo ::set-output name=new_tag::$new +echo ::set-output name=new_tag_without_prefix::$tagWithoutPrefix echo ::set-output name=part::$part # use dry run to determine the next tag From 070e22197acdedec2ea4cf8e94f354c11421999f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Fri, 5 Feb 2021 17:42:51 +0100 Subject: [PATCH 02/63] Implemented versioning based on multiple commit messages --- README.md | 12 ++++++---- action.yml | 4 +++- entrypoint.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index edbf8d8c..bfed5e8d 100755 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ jobs: uses: anothrNick/github-tag-action@1.26.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - WITH_V: true + PREFIX: prefix ``` _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all commits to look for the semver commit message._ @@ -40,7 +40,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **GITHUB_TOKEN** ***(required)*** - Required for permission to tag the repo. * **DEFAULT_BUMP** *(optional)* - Which type of bump to use when none explicitly provided (default: `minor`). -* **WITH_V** *(optional)* - Tag version with `v` character. +* **PREFIX** *(optional)* - Adds a prefix before version number. * **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` ... * **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!** * **SOURCE** *(optional)* - Operate on a relative path under $GITHUB_WORKSPACE. @@ -49,12 +49,14 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. * **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. * **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. +* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Useful e.g. in case of running the action in a pull request. If not specified the current commit is used. #### Outputs -* **new_tag** - The value of the newly created tag. -* **tag** - The value of the latest tag after running this action. -* **part** - The part of version which was bumped. +* **new_tag** - The value of the newly created tag, e.g. my-prefix-1.2.3 +* **new_tag_without_prefix** - The value of the newly created tag without specified prefix, e.g 1.2.3 +* **tag** - The value of the latest tag before bumping it by running this action, e.g. 1.2.2 +* **part** - The part of version which was bumped, e.g. minor > ***Note:*** This action creates a [lightweight tag](https://developer.github.com/v3/git/refs/#create-a-reference). diff --git a/action.yml b/action.yml index 360e4f5f..98d48b0c 100644 --- a/action.yml +++ b/action.yml @@ -7,8 +7,10 @@ runs: outputs: new_tag: description: 'Generated tag' + new_tag_without_prefix: + description: 'Generated tag without specified prefix' tag: - description: 'The latest tag after running this action' + description: 'The latest tag before running this action' part: description: 'The part of version which was bumped' branding: diff --git a/entrypoint.sh b/entrypoint.sh index 4036913f..4e1efe87 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,6 +13,7 @@ initial_version=${INITIAL_VERSION:-0.0.0} tag_context=${TAG_CONTEXT:-repo} suffix=${PRERELEASE_SUFFIX:-beta} verbose=${VERBOSE:-true} +head_commit=$HEAD_COMMIT cd ${GITHUB_WORKSPACE}/${source} @@ -27,6 +28,8 @@ echo -e "\tINITIAL_VERSION: ${initial_version}" echo -e "\tTAG_CONTEXT: ${tag_context}" echo -e "\tPRERELEASE_SUFFIX: ${suffix}" echo -e "\tVERBOSE: ${verbose}" +echo -e "\tHEAD_COMMIT: ${head_commit}" +echo -e "*********************\n" current_branch=$(git rev-parse --abbrev-ref HEAD) @@ -79,10 +82,48 @@ if [ "$tag_commit" == "$commit" ]; then exit 0 fi -# echo log if verbose is wanted +# calculate new tag + + # Get number of occurrences of bump key words in + # all commits between the "head_commit" and the last tag + # or in all commits of a current branch if the are no tags with + # a given prefix in the repository + +if [ -z $head_commit ]; then + head_commit=$commit +fi + +if [ $tag = $initial_version ]; then + + if $verbose + then + echo -e "\n*****Commit messages taken into account*****" + git log $current_branch --pretty=format:%B + echo -e "********************************************\n" + fi + + number_of_major=$(git log $current_branch --pretty=format:%B | grep -E "#major" -c) + number_of_minor=$(git log $current_branch --pretty=format:%B | grep -E "#minor" -c) + number_of_patch=$(git log $current_branch --pretty=format:%B | grep -E "#patch" -c) +else + + if $verbose + then + echo -e "\n*****Commit messages taken into account*****" + git log $head_commit...$tag --pretty=format:%B + echo -e "********************************************\n" + fi + + number_of_major=$(git log $head_commit...$tag --pretty=format:%B | grep -E "#major" -c) + number_of_minor=$(git log $head_commit...$tag --pretty=format:%B | grep -E "#minor" -c) + number_of_patch=$(git log $head_commit...$tag --pretty=format:%B | grep -E "#patch" -c) +fi + if $verbose then - echo $log + echo "number of #major tag occurrences ${number_of_major}" + echo "number of #minor tag occurrences ${number_of_minor}" + echo "number of #patch tag occurrences ${number_of_patch}" fi tagWithoutPrefix=${tag#"$prefix"} @@ -111,18 +152,18 @@ then fi fi -echo $part # did we get a new tag? if [ ! -z "$new" ] then - # prefix with 'v' + # prefix with 'prefix' if [ ! -z "$prefix" ] then new="$prefix$new" fi fi +# set a new tag to a provider CUSTOM_TAG - discard calculated tag if [ ! -z $custom_tag ] then new="$custom_tag" @@ -132,22 +173,30 @@ if $pre_release then echo -e "Bumping tag ${pre_tag}. \n\tNew tag ${new}" else - echo -e "Bumping tag ${tag}. \n\tNew tag ${new}" + echo -e "Bumping tag ${tag}. \n\tNew tag ${new}\n" fi # set outputs +new_tag_without_prefix=${new#"$prefix"} +echo "New tag without prefix: $new_tag_without_prefix" +echo "New tag: $new" +echo "Prefix: $prefix" +echo -e "Part incremented: $part\n\n" + echo ::set-output name=new_tag::$new -echo ::set-output name=new_tag_without_prefix::$tagWithoutPrefix +echo ::set-output name=new_tag_without_prefix::$new_tag_without_prefix echo ::set-output name=part::$part +# set the old tag value as an output +echo ::set-output name=tag::$tag + + # use dry run to determine the next tag if $dryrun then - echo ::set-output name=tag::$tag exit 0 fi -echo ::set-output name=tag::$new # create local git tag git tag $new From e66606bb2e37a6226633b668939028172de677f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 24 Mar 2021 12:56:06 +0100 Subject: [PATCH 03/63] Prefix parameter versioning based on multiple messages (#1) * Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bfed5e8d..ba5039fd 100755 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. * **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. * **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. -* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Useful e.g. in case of running the action in a pull request. If not specified the current commit is used. +* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. #### Outputs From 5a98e7f810498e2477c845db1be4aebe7f35071f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Fri, 30 Jul 2021 17:46:58 +0200 Subject: [PATCH 04/63] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba5039fd..041685ef 100755 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. * **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. * **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. -* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. +* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. #### Outputs From 3067bbc962cfd49177ba9a6fec991959dd47daf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Tue, 3 Aug 2021 23:53:26 +0200 Subject: [PATCH 05/63] Applied suggestions from PR --- README.md | 4 +- entrypoint.sh | 136 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 96 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 041685ef..9225fc34 100755 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ jobs: uses: anothrNick/github-tag-action@1.26.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true PREFIX: prefix ``` @@ -40,6 +41,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **GITHUB_TOKEN** ***(required)*** - Required for permission to tag the repo. * **DEFAULT_BUMP** *(optional)* - Which type of bump to use when none explicitly provided (default: `minor`). +* **WITH_V** *(optional)* - Tag version with `v` character. * **PREFIX** *(optional)* - Adds a prefix before version number. * **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` ... * **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!** @@ -49,7 +51,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. * **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. * **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. -* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. +* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. #### Outputs diff --git a/entrypoint.sh b/entrypoint.sh index 4e1efe87..c5a0cdf6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,6 +4,7 @@ set -o pipefail # config default_semvar_bump=${DEFAULT_BUMP:-minor} +with_v=${WITH_V} prefix=${PREFIX} release_branches=${RELEASE_BRANCHES:-master,main} custom_tag=${CUSTOM_TAG} @@ -14,11 +15,13 @@ tag_context=${TAG_CONTEXT:-repo} suffix=${PRERELEASE_SUFFIX:-beta} verbose=${VERBOSE:-true} head_commit=$HEAD_COMMIT +use_last_commit_only=${USE_LAST_COMMIT_ONLY:-true} cd ${GITHUB_WORKSPACE}/${source} echo "*** CONFIGURATION ***" echo -e "\tDEFAULT_BUMP: ${default_semvar_bump}" +echo -e "\tWITH_V: ${with_v}" echo -e "\tPREFIX: ${prefix}" echo -e "\tRELEASE_BRANCHES: ${release_branches}" echo -e "\tCUSTOM_TAG: ${custom_tag}" @@ -29,15 +32,32 @@ echo -e "\tTAG_CONTEXT: ${tag_context}" echo -e "\tPRERELEASE_SUFFIX: ${suffix}" echo -e "\tVERBOSE: ${verbose}" echo -e "\tHEAD_COMMIT: ${head_commit}" +echo -e "\tUSE_LAST_COMMIT_ONLY: ${use_last_commit_only}" echo -e "*********************\n" +# Handle deprecated WITH_V parameter +if [ ! -z "$with_v" ]; +then + echo -e "WARNING: WITH_V parameter field has been deprecated. Use PREFIX instead." + if [ ! -z "$prefix" ]; + then + echo -e "WARNING: Both WITH_V and PREFIX parameters have been set. Value of WITH_V will be ignored" + else + if $with_v; + then + echo -e "WITH_V is set to true and PREFIX parameter have not been set. PREFIX will be set to 'v'" + prefix="v" + fi + fi +fi + 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 ]] + echo -e "\n\nIs $b a match for ${current_branch}" + if [[ "${current_branch}" =~ $b ]]; then pre_release="false" fi @@ -47,7 +67,7 @@ echo "pre_release = $pre_release" # fetch tags git fetch --tags -# get latest tag that looks like a semver (with or without v) +# get latest tag that looks like a semver (with or without prefix) case "$tag_context" in *repo*) tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^v?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) @@ -60,14 +80,26 @@ case "$tag_context" in * ) echo "Unrecognised context"; exit 1;; esac +echo_previous_tags() { + if $verbose; + then + echo -e "\n******************************************" + echo -e $1 + echo -e "tag: ${tag}" + echo -e "pre_tag: ${pre_tag}" + echo -e "********************************************\n" + fi +} + # if there are none, start tags at INITIAL_VERSION which defaults to 0.0.0 -if [ -z "$tag" ] +if [ -z "$tag" ]; then log=$(git log --pretty='%B') tag="$initial_version" pre_tag="$initial_version" + echo_previous_tags "No tag was found. INITIAL_VERSION will be used instead." else - log=$(git log $tag..HEAD --pretty='%B') + echo_previous_tags "Previous tag was found." fi # get current commit hash for tag @@ -93,37 +125,54 @@ if [ -z $head_commit ]; then head_commit=$commit fi -if [ $tag = $initial_version ]; then - - if $verbose - then - echo -e "\n*****Commit messages taken into account*****" - git log $current_branch --pretty=format:%B - echo -e "********************************************\n" - fi - - number_of_major=$(git log $current_branch --pretty=format:%B | grep -E "#major" -c) - number_of_minor=$(git log $current_branch --pretty=format:%B | grep -E "#minor" -c) - number_of_patch=$(git log $current_branch --pretty=format:%B | grep -E "#patch" -c) -else +if $verbose; +then + echo -e "\n******************************************" + echo -e "current branch: ${current_branch}" + echo -e "commit for last found tag: ${tag_commit}" + echo -e "current commit: ${commit}" + echo -e "HEAD_COMMIT: ${head_commit}" + echo -e "********************************************\n" +fi - if $verbose +set_number_of_found_keywords() { + if $verbose; then - echo -e "\n*****Commit messages taken into account*****" - git log $head_commit...$tag --pretty=format:%B + echo -e "\n********************************************" + echo -e "Commit messages taken into account" + if $3; + then + echo "First commit: $2" + git log $2 --pretty=format:%B | awk 'NF' + else + git log $head_commit...$tag --pretty=format:%B | awk 'NF' + fi echo -e "********************************************\n" fi - number_of_major=$(git log $head_commit...$tag --pretty=format:%B | grep -E "#major" -c) - number_of_minor=$(git log $head_commit...$tag --pretty=format:%B | grep -E "#minor" -c) - number_of_patch=$(git log $head_commit...$tag --pretty=format:%B | grep -E "#patch" -c) -fi + number_of_major=$(git log $1...$2 --pretty=format:%B | grep -E "#major" -c) + number_of_minor=$(git log $1...$2 --pretty=format:%B | grep -E "#minor" -c) + number_of_patch=$(git log $1...$2 --pretty=format:%B | grep -E "#patch" -c) + number_of_commits=$(git log $1...$2 --pretty=format:%B | awk 'NF' | grep "" -c) -if $verbose -then - echo "number of #major tag occurrences ${number_of_major}" - echo "number of #minor tag occurrences ${number_of_minor}" - echo "number of #patch tag occurrences ${number_of_patch}" + if $verbose; + then + echo -e "\n********************************************" + echo "number of #major tag occurrences ${number_of_major}" + echo "number of #minor tag occurrences ${number_of_minor}" + echo "number of #patch tag occurrences ${number_of_patch}" + echo "number of commits taken into account ${number_of_commits}" + echo -e "********************************************\n" + fi +} + +if [ $tag = $initial_version ]; then + first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) + is_first_commit_used=true + set_number_of_found_keywords $head_commit $first_commit_of_repo $is_first_commit_used +else + is_first_commit_used=false + set_number_of_found_keywords $head_commit $tag $is_first_commit_used fi tagWithoutPrefix=${tag#"$prefix"} @@ -142,7 +191,7 @@ case "$log" in ;; esac -if $pre_release +if $pre_release; then # Already a prerelease available, bump it if [[ "$pre_tag" == *"$new"* ]]; then @@ -152,9 +201,8 @@ then fi fi - # did we get a new tag? -if [ ! -z "$new" ] +if [ ! -z "$new" ]; then # prefix with 'prefix' if [ ! -z "$prefix" ] @@ -163,25 +211,27 @@ then fi fi -# set a new tag to a provider CUSTOM_TAG - discard calculated tag -if [ ! -z $custom_tag ] +# set a new tag to a provided CUSTOM_TAG - discard calculated tag +if [ ! -z $custom_tag ]; then new="$custom_tag" fi -if $pre_release +if $pre_release; then - echo -e "Bumping tag ${pre_tag}. \n\tNew tag ${new}" + echo -e "\nBumping tag\n\told tag: ${pre_tag}\n\tnew tag: ${new}" else - echo -e "Bumping tag ${tag}. \n\tNew tag ${new}\n" + echo -e "\nBumping tag\n\told tag: ${tag}\n\tnew tag: ${new}" fi # set outputs +echo -e "\nSetting outputs" + new_tag_without_prefix=${new#"$prefix"} -echo "New tag without prefix: $new_tag_without_prefix" -echo "New tag: $new" -echo "Prefix: $prefix" -echo -e "Part incremented: $part\n\n" +echo -e "\tNew tag without prefix: $new_tag_without_prefix" +echo -e "\tNew tag: $new" +echo -e "\tPrefix: $prefix" +echo -e "\tPart incremented: $part\n\n" echo ::set-output name=new_tag::$new echo ::set-output name=new_tag_without_prefix::$new_tag_without_prefix @@ -192,7 +242,7 @@ echo ::set-output name=tag::$tag # use dry run to determine the next tag -if $dryrun +if $dryrun; then exit 0 fi From d0bf5152e3cbbe45bed158817c71dd057a22c98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 4 Aug 2021 00:00:23 +0200 Subject: [PATCH 06/63] Updated description of WITH_V variable in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9225fc34..cb696d23 100755 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **GITHUB_TOKEN** ***(required)*** - Required for permission to tag the repo. * **DEFAULT_BUMP** *(optional)* - Which type of bump to use when none explicitly provided (default: `minor`). -* **WITH_V** *(optional)* - Tag version with `v` character. +* **WITH_V** **(deprecated)** *(optional)* - Tag version with `v` character. Deprecated variable - use `PREFIX` instead. * **PREFIX** *(optional)* - Adds a prefix before version number. * **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` ... * **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!** From 37e66bdd1f1a0fe086c356b276d11b25e149c380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 4 Aug 2021 00:08:31 +0200 Subject: [PATCH 07/63] Added description for USE_LAST_COMMIT_ONLY variable in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cb696d23..52fad585 100755 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. * **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. * **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. +* **USE_LAST_COMMIT_ONLY** *(optional)* - True by default. If true only last commit is taken into account while bumping the version, otherwise all commits from the commit with the latest tag contribute to new tag calculation #### Outputs From 23b0f66e61e9b7eb2288703daa5066493715aee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 4 Aug 2021 00:13:10 +0200 Subject: [PATCH 08/63] Fixed README description for HEAD_COMMIT variable --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52fad585..3beef467 100755 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. * **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. * **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. -* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. +* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. * **USE_LAST_COMMIT_ONLY** *(optional)* - True by default. If true only last commit is taken into account while bumping the version, otherwise all commits from the commit with the latest tag contribute to new tag calculation #### Outputs From 19edbd9664131f2f56cb2a9a4626868b5bec63a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 4 Aug 2021 00:23:04 +0200 Subject: [PATCH 09/63] Restored logic broken after rebase --- entrypoint.sh | 75 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index c5a0cdf6..7ec92345 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -70,12 +70,12 @@ git fetch --tags # get latest tag that looks like a semver (with or without prefix) case "$tag_context" in *repo*) - tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^v?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) - pre_tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^v?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) + tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) + pre_tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) ;; *branch*) - tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^v?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) - pre_tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^v?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) + tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) + pre_tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) ;; * ) echo "Unrecognised context"; exit 1;; esac @@ -176,20 +176,59 @@ else fi tagWithoutPrefix=${tag#"$prefix"} -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";; - *#none* ) - 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}" $tagWithoutPrefix); part=$default_semvar_bump - fi - ;; -esac + +bump_version () { + new=$tagWithoutPrefix + + eval count_var_name=number_of_$1 + count="${!count_var_name}" + + if $use_last_commit_only; + then + echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. $1 will be incremented only by 1" + eval number_of_$1=1 + count=1 + else + echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. $1 will be incremented by ${count}" + fi + + for (( c=1; c<=$count; c++ )) + do + new=$(semver -i $1 $new); part=$1 + done +} + +if [ $number_of_major != 0 ]; then + bump_version "major" +fi + +if [ $number_of_major = 0 ] && [ $number_of_minor != 0 ] && [ -z $new ]; then + bump_version "minor" +fi + +if [ $number_of_major == 0 ] && [ $number_of_minor == 0 ] && [ -z $new ]; then + bump_version "patch" +fi + + +if [ -z $new ]; then + if [ "$default_semvar_bump" == "none" ]; then + echo "Default bump was set to none. Skipping..."; + else + new=$tagWithoutPrefix + if $use_last_commit_only; then + echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented only by 1" + new=$(semver -i "${default_semvar_bump}" $new); part=$default_semvar_bump + else + echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented by ${number_of_commits}" + + for (( c=1; c<=$number_of_commits; c++ )) + do + new=$(semver -i "${default_semvar_bump}" $new); part=$default_semvar_bump + done + fi + fi +fi if $pre_release; then From dc90ed76ef20cd411e1a7f0eee77350030821ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 27 Oct 2021 01:00:52 +0200 Subject: [PATCH 10/63] Add BRANCH_LATEST_COMMIT parameter, fix logic, refactor --- README.md | 2 +- entrypoint.sh | 268 +++++++++++++++++++++++++------------------------- 2 files changed, 135 insertions(+), 135 deletions(-) diff --git a/README.md b/README.md index 5302b0af..c237401c 100755 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all * **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. * **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. * **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. -* **HEAD_COMMIT** *(optional)* - Commit messages between the last tag and *HEAD_COMMIT* will be used to determine a new version number. Specifying commit is useful when using this action for pull requests - one can set environment variable as follows: `HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. +* **BRANCH_LATEST_COMMIT** *(optional)* - Commit messages for commits of a given branch will be taken into account while calculating a new tag. Specifying bramch is useful when using this action for pull requests - one can set environment variable as follows: `BRANCH_LATEST_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. * **USE_LAST_COMMIT_ONLY** *(optional)* - True by default. If true only last commit is taken into account while bumping the version, otherwise all commits from the commit with the latest tag contribute to new tag calculation #### Outputs diff --git a/entrypoint.sh b/entrypoint.sh index 576ebc3d..c245ff28 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,7 +14,7 @@ initial_version=${INITIAL_VERSION:-0.0.0} tag_context=${TAG_CONTEXT:-repo} suffix=${PRERELEASE_SUFFIX:-beta} verbose=${VERBOSE:-true} -head_commit=$HEAD_COMMIT +branch_latest_commit=$BRANCH_LATEST_COMMIT use_last_commit_only=${USE_LAST_COMMIT_ONLY:-true} cd ${GITHUB_WORKSPACE}/${source} @@ -31,34 +31,30 @@ echo -e "\tINITIAL_VERSION: ${initial_version}" echo -e "\tTAG_CONTEXT: ${tag_context}" echo -e "\tPRERELEASE_SUFFIX: ${suffix}" echo -e "\tVERBOSE: ${verbose}" -echo -e "\tHEAD_COMMIT: ${head_commit}" +echo -e "\tBRANCH_NAME: ${branch_latest_commit}" echo -e "\tUSE_LAST_COMMIT_ONLY: ${use_last_commit_only}" echo -e "*********************\n" # Handle deprecated WITH_V parameter -if [ ! -z "$with_v" ]; -then +if [ -n "$with_v" ]; then echo -e "WARNING: WITH_V parameter field has been deprecated. Use PREFIX instead." - if [ ! -z "$prefix" ]; - then - echo -e "WARNING: Both WITH_V and PREFIX parameters have been set. Value of WITH_V will be ignored" - else - if $with_v; - then + if [ -n "$prefix" ]; then + echo -e "WARNING: Both WITH_V and PREFIX parameters have been set. Value of WITH_V will be ignored" + else + if $with_v; then echo -e "WITH_V is set to true and PREFIX parameter have not been set. PREFIX will be set to 'v'" prefix="v" fi - fi + fi fi current_branch=$(git rev-parse --abbrev-ref HEAD) pre_release="true" -IFS=',' read -ra branch <<< "$release_branches" +IFS=',' read -ra branch <<<"$release_branches" for b in "${branch[@]}"; do echo -e "\n\nIs $b a match for ${current_branch}" - if [[ "${current_branch}" =~ $b ]]; - then + if [[ "${current_branch}" =~ $b ]]; then pre_release="false" fi done @@ -69,33 +65,33 @@ git fetch --tags # get latest tag that looks like a semver (with or without prefix) case "$tag_context" in - *repo*) - tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) - pre_tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) - ;; - *branch*) - tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) - pre_tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) - ;; - * ) echo "Unrecognised context"; exit 1;; +*repo*) + latest_tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) + pre_tag=$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) + ;; +*branch*) + latest_tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+$" | head -n1) + pre_tag=$(git tag --list --merged HEAD --sort=-v:refname | grep -E "^($prefix)?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)?$" | head -n1) + ;; +*) + echo "Unrecognised context" + exit 1 + ;; esac echo_previous_tags() { - if $verbose; - then + if $verbose; then echo -e "\n******************************************" - echo -e $1 - echo -e "tag: ${tag}" + echo -e "$1" + echo -e "latest_tag: ${latest_tag}" echo -e "pre_tag: ${pre_tag}" echo -e "********************************************\n" fi } # 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" +if [ -z "$latest_tag" ]; then + latest_tag="$initial_version" pre_tag="$initial_version" echo_previous_tags "No tag was found. INITIAL_VERSION will be used instead." @@ -104,60 +100,52 @@ else fi # get current commit hash for tag -tag_commit=$(git rev-list -n 1 $tag) +latest_tag_commit=$(git rev-list -n 1 "$latest_tag") # get current commit hash -commit=$(git rev-parse HEAD) +current_commit=$(git rev-parse HEAD) -if [ "$tag_commit" == "$commit" ]; then +if [ "$latest_tag_commit" == "$current_commit" ]; then echo "No new commits since previous tag. Skipping..." - echo ::set-output name=tag::$tag + echo ::set-output name=tag::"$latest_tag" exit 0 fi # calculate new tag - # Get number of occurrences of bump key words in - # all commits between the "head_commit" and the last tag - # or in all commits of a current branch if the are no tags with - # a given prefix in the repository - -if [ -z $head_commit ]; then - head_commit=$commit -fi +# Get number of occurrences of bump key words in +# all commits between the "branch_latest_commit" and the last tag +# or in all commits of a current branch if the are no tags with +# a given prefix in the repository -if $verbose; -then +if $verbose; then echo -e "\n******************************************" echo -e "current branch: ${current_branch}" - echo -e "commit for last found tag: ${tag_commit}" - echo -e "current commit: ${commit}" - echo -e "HEAD_COMMIT: ${head_commit}" + echo -e "commit for last found tag: ${latest_tag_commit}" + echo -e "current commit: ${current_commit}" + echo -e "branch_latest_commit: ${branch_latest_commit}" echo -e "********************************************\n" fi set_number_of_found_keywords() { - if $verbose; - then - echo -e "\n********************************************" - echo -e "Commit messages taken into account" - if $3; - then - echo "First commit: $2" - git log $2 --pretty=format:%B | awk 'NF' - else - git log $head_commit...$tag --pretty=format:%B | awk 'NF' - fi - echo -e "********************************************\n" - fi - - number_of_major=$(git log $1...$2 --pretty=format:%B | grep -E "#major" -c) - number_of_minor=$(git log $1...$2 --pretty=format:%B | grep -E "#minor" -c) - number_of_patch=$(git log $1...$2 --pretty=format:%B | grep -E "#patch" -c) - number_of_commits=$(git log $1...$2 --pretty=format:%B | awk 'NF' | grep "" -c) - - if $verbose; - then + if $verbose; then + echo -e "\n********************************************" + echo -e "Commit messages taken into account" + if $3; then + echo "First commit: $2" + git log "$2" --pretty=format:%B | awk 'NF' + else + git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF' + fi + echo -e "********************************************\n" + fi + + number_of_major=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "#major" -c) + number_of_minor=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "#minor" -c) + number_of_patch=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "#patch" -c) + number_of_commits=$(git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF' | grep "" -c) + + if $verbose; then echo -e "\n********************************************" echo "number of #major tag occurrences ${number_of_major}" echo "number of #minor tag occurrences ${number_of_minor}" @@ -167,101 +155,116 @@ set_number_of_found_keywords() { fi } -if [ $tag = $initial_version ]; then - first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) - is_first_commit_used=true - set_number_of_found_keywords $head_commit $first_commit_of_repo $is_first_commit_used -else - is_first_commit_used=false - set_number_of_found_keywords $head_commit $tag $is_first_commit_used +if [ "$latest_tag" = "$initial_version" ]; then + first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) + is_first_commit_used=true + set_number_of_found_keywords "$branch_latest_commit" "$first_commit_of_repo" "$is_first_commit_used" +else + + is_first_commit_used=false + if [ -z "$branch_latest_commit" ]; then + next_commit_after_current_tag=$(git log --pretty=format:"%H" --reverse --ancestry-path "$latest_tag"^.."$current_commit" | sed -n 2p) + if $verbose; then + echo -e "\n********************************************" + echo "next commit after current tag commit ${number_of_commits}" + echo -e "********************************************\n" + fi + set_number_of_found_keywords "$current_commit" "$next_commit_after_current_tag" "$is_first_commit_used" + else + base_branch_commit_on_parent_branch=$(diff -u <(git rev-list --first-parent "$branch_latest_commit") <(git rev-list --first-parent "$current_commit") | sed -ne 's/^ //p' | head -1) + first_separate_commit_on_branch=$(git log --pretty=format:"%H" --reverse --ancestry-path "$base_branch_commit_on_parent_branch"^.."$branch_latest_commit" | sed -n 2p) + if $verbose; then + echo -e "\n********************************************" + echo "base branch commit on parent branch ${base_branch_commit_on_parent_branch}" + echo "first separate commit on branch ${first_separate_commit_on_branch}" + echo -e "********************************************\n" + fi + set_number_of_found_keywords "$branch_latest_commit" "$first_separate_commit_on_branch" "$is_first_commit_used" + fi fi -tagWithoutPrefix=${tag#"$prefix"} +tagWithoutPrefix=${latest_tag#"$prefix"} -bump_version () { +bump_version() { new=$tagWithoutPrefix - eval count_var_name=number_of_$1 + eval count_var_name=number_of_"$1" count="${!count_var_name}" - if $use_last_commit_only; - then + if $use_last_commit_only; then echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. $1 will be incremented only by 1" - eval number_of_$1=1 + eval number_of_"$1"=1 count=1 else echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. $1 will be incremented by ${count}" fi - for (( c=1; c<=$count; c++ )) - do - new=$(semver -i $1 $new); part=$1 + for ((c = 1; c <= $count; c++)); do + new=$(semver -i "$1" "$new") + part=$1 done } -if [ $number_of_major != 0 ]; then +if [ "$number_of_major" != 0 ]; then bump_version "major" fi -if [ $number_of_major = 0 ] && [ $number_of_minor != 0 ] && [ -z $new ]; then +if [ "$number_of_major" = 0 ] && [ "$number_of_minor" != 0 ] && [ -z "$new" ]; then bump_version "minor" fi -if [ $number_of_major == 0 ] && [ $number_of_minor == 0 ] && [ -z $new ]; then +if [ "$number_of_major" == 0 ] && [ "$number_of_minor" == 0 ] && [ -z "$new" ]; then bump_version "patch" fi - -if [ -z $new ]; then +if [ -z "$new" ]; then if [ "$default_semvar_bump" == "none" ]; then - echo "Default bump was set to none. Skipping..."; - else + echo "Default bump was set to none. Skipping..." + else new=$tagWithoutPrefix if $use_last_commit_only; then echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented only by 1" - new=$(semver -i "${default_semvar_bump}" $new); part=$default_semvar_bump + new=$(semver -i "${default_semvar_bump}" "$new") + part=$default_semvar_bump else - echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented by ${number_of_commits}" + echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented by ${number_of_commits}" - for (( c=1; c<=$number_of_commits; c++ )) - do - new=$(semver -i "${default_semvar_bump}" $new); part=$default_semvar_bump - done + for ((c = 1; c <= $number_of_commits; c++)); do + new=$(semver -i "${default_semvar_bump}" "$new") + part=$default_semvar_bump + done fi - fi + fi fi -if $pre_release; -then +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" + new=$(semver -i prerelease "$pre_tag" --preid "$suffix") + part="pre-$part" else - new="$new-$suffix.1"; part="pre-$part" + new="$new-$suffix.1" + part="pre-$part" fi fi # did we get a new tag? -if [ ! -z "$new" ]; -then - # prefix with 'prefix' - if [ ! -z "$prefix" ] - then - new="$prefix$new" - fi +if [ -n "$new" ]; then + # prefix with 'prefix' + if [ -n "$prefix" ]; then + new="$prefix$new" + fi fi # set a new tag to a provided CUSTOM_TAG - discard calculated tag -if [ ! -z $custom_tag ]; -then +if [ -n "$custom_tag" ]; then new="$custom_tag" fi -if $pre_release; -then +if $pre_release; then echo -e "\nBumping tag\n\told tag: ${pre_tag}\n\tnew tag: ${new}" else - echo -e "\nBumping tag\n\told tag: ${tag}\n\tnew tag: ${new}" + echo -e "\nBumping tag\n\told tag: ${latest_tag}\n\tnew tag: ${new}" fi # set outputs @@ -273,49 +276,46 @@ echo -e "\tNew tag: $new" echo -e "\tPrefix: $prefix" echo -e "\tPart incremented: $part\n\n" -echo ::set-output name=new_tag::$new -echo ::set-output name=new_tag_without_prefix::$new_tag_without_prefix -echo ::set-output name=part::$part +echo ::set-output name=new_tag::"$new" +echo ::set-output name=new_tag_without_prefix::"$new_tag_without_prefix" +echo ::set-output name=part::"$part" # set the old tag value as an output -echo ::set-output name=tag::$tag - +echo ::set-output name=tag::"$latest_tag" # use dry run to determine the next tag -if $dryrun; -then +if $dryrun; then exit 0 -fi - +fi # create local git tag -git tag $new +git tag "$new" # push new tag ref to github dt=$(date '+%Y-%m-%dT%H:%M:%SZ') full_name=$GITHUB_REPOSITORY -git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g') +git_refs_url=$(jq .repository.git_refs_url "$GITHUB_EVENT_PATH" | tr -d '"' | sed 's/{\/sha}//g') echo "$dt: **pushing tag $new to repo $full_name" git_refs_response=$( -curl -s -X POST $git_refs_url \ --H "Authorization: token $GITHUB_TOKEN" \ --d @- << EOF + curl -s -X POST "$git_refs_url" \ + -H "Authorization: token $GITHUB_TOKEN" \ + -d @- < Date: Wed, 27 Oct 2021 02:38:17 +0200 Subject: [PATCH 11/63] Print info about discarding calculated tag when custom tag is provided --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index c245ff28..7f1d87db 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -258,6 +258,7 @@ fi # set a new tag to a provided CUSTOM_TAG - discard calculated tag if [ -n "$custom_tag" ]; then + echo "!!! Custom tag has been provided, so it'll be used instead of a calculated tag !!!" new="$custom_tag" fi From 94705e4bfdb62ca88a6f19551d780c1f98f07bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 27 Oct 2021 02:39:58 +0200 Subject: [PATCH 12/63] Fixed printed variable name --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7f1d87db..85be185c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -31,7 +31,7 @@ echo -e "\tINITIAL_VERSION: ${initial_version}" echo -e "\tTAG_CONTEXT: ${tag_context}" echo -e "\tPRERELEASE_SUFFIX: ${suffix}" echo -e "\tVERBOSE: ${verbose}" -echo -e "\tBRANCH_NAME: ${branch_latest_commit}" +echo -e "\BRANCH_LATEST_COMMIT: ${branch_latest_commit}" echo -e "\tUSE_LAST_COMMIT_ONLY: ${use_last_commit_only}" echo -e "*********************\n" From e2e8a8e00574e50a4339ad7946352c60c61fdd00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Thu, 28 Oct 2021 16:46:13 +0200 Subject: [PATCH 13/63] Remove ShellCheck warnings --- entrypoint.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 85be185c..41ec7109 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/bash +# shellcheck disable=SC2153,2164 + set -o pipefail # config @@ -17,7 +19,7 @@ verbose=${VERBOSE:-true} branch_latest_commit=$BRANCH_LATEST_COMMIT use_last_commit_only=${USE_LAST_COMMIT_ONLY:-true} -cd ${GITHUB_WORKSPACE}/${source} +cd "${GITHUB_WORKSPACE}"/"${source}" echo "*** CONFIGURATION ***" echo -e "\tDEFAULT_BUMP: ${default_semvar_bump}" @@ -189,6 +191,7 @@ bump_version() { new=$tagWithoutPrefix eval count_var_name=number_of_"$1" + # shellcheck disable=SC2154 count="${!count_var_name}" if $use_last_commit_only; then @@ -199,7 +202,7 @@ bump_version() { echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. $1 will be incremented by ${count}" fi - for ((c = 1; c <= $count; c++)); do + for ((c = 1; c <= count; c++)); do new=$(semver -i "$1" "$new") part=$1 done @@ -229,7 +232,7 @@ if [ -z "$new" ]; then else echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented by ${number_of_commits}" - for ((c = 1; c <= $number_of_commits; c++)); do + for ((c = 1; c <= number_of_commits; c++)); do new=$(semver -i "${default_semvar_bump}" "$new") part=$default_semvar_bump done From 824a7be1325f4c9e6cdfde89f6e64beace4b3504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Fri, 29 Oct 2021 02:08:43 +0200 Subject: [PATCH 14/63] Fixed logic for calculating new tag --- entrypoint.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 41ec7109..e052ed0e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,7 +16,7 @@ initial_version=${INITIAL_VERSION:-0.0.0} tag_context=${TAG_CONTEXT:-repo} suffix=${PRERELEASE_SUFFIX:-beta} verbose=${VERBOSE:-true} -branch_latest_commit=$BRANCH_LATEST_COMMIT +branch_latest_commit=${BRANCH_LATEST_COMMIT} use_last_commit_only=${USE_LAST_COMMIT_ONLY:-true} cd "${GITHUB_WORKSPACE}"/"${source}" @@ -33,7 +33,7 @@ echo -e "\tINITIAL_VERSION: ${initial_version}" echo -e "\tTAG_CONTEXT: ${tag_context}" echo -e "\tPRERELEASE_SUFFIX: ${suffix}" echo -e "\tVERBOSE: ${verbose}" -echo -e "\BRANCH_LATEST_COMMIT: ${branch_latest_commit}" +echo -e "\tBRANCH_LATEST_COMMIT: ${branch_latest_commit}" echo -e "\tUSE_LAST_COMMIT_ONLY: ${use_last_commit_only}" echo -e "*********************\n" @@ -204,7 +204,7 @@ bump_version() { for ((c = 1; c <= count; c++)); do new=$(semver -i "$1" "$new") - part=$1 + part=$1 # TODO: Is this line needed? done } @@ -212,11 +212,11 @@ if [ "$number_of_major" != 0 ]; then bump_version "major" fi -if [ "$number_of_major" = 0 ] && [ "$number_of_minor" != 0 ] && [ -z "$new" ]; then +if [ "$number_of_major" == 0 ] && [ "$number_of_minor" != 0 ] && [ -z "$new" ]; then bump_version "minor" fi -if [ "$number_of_major" == 0 ] && [ "$number_of_minor" == 0 ] && [ -z "$new" ]; then +if [ "$number_of_major" == 0 ] && [ "$number_of_minor" == 0 ] && [ "$number_of_patch" != 0 ] && [ -z "$new" ]; then bump_version "patch" fi From ab9c79fcb0c672a487e6318194903a9e332cb92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Fri, 29 Oct 2021 02:28:40 +0200 Subject: [PATCH 15/63] If custom tag is provided no calculations are performed --- entrypoint.sh | 149 +++++++++++++++++++++++++++++--------------------- 1 file changed, 86 insertions(+), 63 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index e052ed0e..f14cab53 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,6 +37,91 @@ echo -e "\tBRANCH_LATEST_COMMIT: ${branch_latest_commit}" echo -e "\tUSE_LAST_COMMIT_ONLY: ${use_last_commit_only}" echo -e "*********************\n" +push_new_tag() { + + # use dry run to determine the next tag + if $dryrun; then + echo "!!!! DRY_RUN set to true, tag will not be updated !!!!" + exit 0 + fi + + git tag "$1" + # push new tag ref to github + dt=$(date '+%Y-%m-%dT%H:%M:%SZ') + full_name=$GITHUB_REPOSITORY + git_refs_url=$(jq .repository.git_refs_url "$GITHUB_EVENT_PATH" | tr -d '"' | sed 's/{\/sha}//g') + + echo "$dt: **pushing tag $1 to repo $full_name" + + git_refs_response=$( + curl -s -X POST "$git_refs_url" \ + -H "Authorization: token $GITHUB_TOKEN" \ + -d @- < Date: Fri, 15 Apr 2022 13:41:37 +0200 Subject: [PATCH 16/63] Fix syntax --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index f14cab53..00f6b092 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -19,7 +19,7 @@ verbose=${VERBOSE:-true} branch_latest_commit=${BRANCH_LATEST_COMMIT} use_last_commit_only=${USE_LAST_COMMIT_ONLY:-true} -cd "${GITHUB_WORKSPACE}"/"${source}" +cd "${GITHUB_WORKSPACE}/${source}" echo "*** CONFIGURATION ***" echo -e "\tDEFAULT_BUMP: ${default_semvar_bump}" From 964d8ed49e5014101b0b30110479084e85b802d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Fri, 15 Apr 2022 13:44:51 +0200 Subject: [PATCH 17/63] Restore syntax for bullet point list in readme --- README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c237401c..01684fa0 100755 --- a/README.md +++ b/README.md @@ -39,27 +39,27 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all **Environment Variables** -* **GITHUB_TOKEN** ***(required)*** - Required for permission to tag the repo. -* **DEFAULT_BUMP** *(optional)* - Which type of bump to use when none explicitly provided (default: `minor`). -* **WITH_V** **(deprecated)** *(optional)* - Tag version with `v` character. Deprecated variable - use `PREFIX` instead. -* **PREFIX** *(optional)* - Adds a prefix before version number. -* **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` ... -* **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!** -* **SOURCE** *(optional)* - Operate on a relative path under $GITHUB_WORKSPACE. -* **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). -* **INITIAL_VERSION** *(optional)* - Set initial version before bump. Default `0.0.0`. -* **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. -* **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. -* **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. -* **BRANCH_LATEST_COMMIT** *(optional)* - Commit messages for commits of a given branch will be taken into account while calculating a new tag. Specifying bramch is useful when using this action for pull requests - one can set environment variable as follows: `BRANCH_LATEST_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. -* **USE_LAST_COMMIT_ONLY** *(optional)* - True by default. If true only last commit is taken into account while bumping the version, otherwise all commits from the commit with the latest tag contribute to new tag calculation +- **GITHUB_TOKEN** ***(required)*** - Required for permission to tag the repo. +- **DEFAULT_BUMP** *(optional)* - Which type of bump to use when none explicitly provided (default: `minor`). +- **WITH_V** **(deprecated)** *(optional)* - Tag version with `v` character. Deprecated variable - use `PREFIX` instead. +- **PREFIX** *(optional)* - Adds a prefix before version number. +- **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` ... +- **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!** +- **SOURCE** *(optional)* - Operate on a relative path under $GITHUB_WORKSPACE. +- **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). +- **INITIAL_VERSION** *(optional)* - Set initial version before bump. Default `0.0.0`. +- **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. +- **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. +- **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. +- **BRANCH_LATEST_COMMIT** *(optional)* - Commit messages for commits of a given branch will be taken into account while calculating a new tag. Specifying bramch is useful when using this action for pull requests - one can set environment variable as follows: `BRANCH_LATEST_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. +- **USE_LAST_COMMIT_ONLY** *(optional)* - True by default. If true only last commit is taken into account while bumping the version, otherwise all commits from the commit with the latest tag contribute to new tag calculation #### Outputs -* **new_tag** - The value of the newly created tag, e.g. my-prefix-1.2.3 -* **new_tag_without_prefix** - The value of the newly created tag without specified prefix, e.g 1.2.3 -* **tag** - The value of the latest tag before bumping it by running this action, e.g. my-prefix-1.2.2 -* **part** - The part of version which was bumped, e.g. minor +- **new_tag** - The value of the newly created tag, e.g. my-prefix-1.2.3 +- **new_tag_without_prefix** - The value of the newly created tag without specified prefix, e.g 1.2.3 +- **tag** - The value of the latest tag before bumping it by running this action, e.g. my-prefix-1.2.2 +- **part** - The part of version which was bumped, e.g. minor > **_Note:_** This action creates a [lightweight tag](https://developer.github.com/v3/git/refs/#create-a-reference). From 20eda4a6a0ac40d157bfbe4c8f1226db5feabffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 18 May 2022 10:14:07 +0200 Subject: [PATCH 18/63] Fix typos in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01684fa0..4443928c 100755 --- a/README.md +++ b/README.md @@ -51,8 +51,8 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` to be sure you retrieve all - **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. - **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. - **VERBOSE** *(optional)* - Print git logs. For some projects these logs may be very large. Possible values are ```true``` (default) and ```false```. -- **BRANCH_LATEST_COMMIT** *(optional)* - Commit messages for commits of a given branch will be taken into account while calculating a new tag. Specifying bramch is useful when using this action for pull requests - one can set environment variable as follows: `BRANCH_LATEST_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. -- **USE_LAST_COMMIT_ONLY** *(optional)* - True by default. If true only last commit is taken into account while bumping the version, otherwise all commits from the commit with the latest tag contribute to new tag calculation +- **BRANCH_LATEST_COMMIT** *(optional)* - Commit messages for commits of a given branch will be taken into account while calculating a new tag. Specifying branch is useful when using this action for pull requests - one can set environment variable as follows: `BRANCH_LATEST_COMMIT: ${{ github.event.pull_request.head.sha }}` to calculate a new version basing on commits from a given PR. If not specified the current commit is used. +- **USE_LAST_COMMIT_ONLY** *(optional)* - True by default. If true only last commit is taken into account while bumping the version, otherwise all commits from the branch with the latest tag contribute to new tag calculation #### Outputs From 2dc729e38606cc033663224c2029e30db8a60b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 28 Sep 2022 22:47:55 +0200 Subject: [PATCH 19/63] Add VSCode task to run tests locally with Act --- .act/.env | 1 + .vscode/tasks.json | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .act/.env create mode 100644 .vscode/tasks.json diff --git a/.act/.env b/.act/.env new file mode 100644 index 00000000..e1834937 --- /dev/null +++ b/.act/.env @@ -0,0 +1 @@ +GITHUB_STEP_SUMMARY=/dev/stdout \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..f734902e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "act - run tests", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "test-action", + "--env-file", + ".act/.env", + ], + "type": "shell", + } + ] +} \ No newline at end of file From a01546695a1b9f9da8ae3040874b1dc4cf2686b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Thu, 29 Sep 2022 00:14:47 +0200 Subject: [PATCH 20/63] Add tests --- .github/workflows/test.yml | 233 ++++++++++++++---- .github/workflows/tests/_assert.sh | 11 + ...if_tag_with_given_prefix_does_not_exist.sh | 14 ++ ...if_tag_with_given_prefix_already_exists.sh | 14 ++ .github/workflows/tests/default-bump.sh | 14 ++ .../tests/several_commits_default_bump.sh | 17 ++ ...ommits_major_takes_precedence_over_path.sh | 20 ++ ...ral_mixed_tagged_and_not_tagged_commits.sh | 17 ++ .vscode/tasks.json | 111 ++++++++- entrypoint.sh | 50 ++-- 10 files changed, 423 insertions(+), 78 deletions(-) mode change 100644 => 100755 .github/workflows/test.yml create mode 100755 .github/workflows/tests/_assert.sh create mode 100755 .github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh create mode 100755 .github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh create mode 100755 .github/workflows/tests/default-bump.sh create mode 100755 .github/workflows/tests/several_commits_default_bump.sh create mode 100755 .github/workflows/tests/several_commits_major_takes_precedence_over_path.sh create mode 100755 .github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml old mode 100644 new mode 100755 index 2081e12f..a5956ad7 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,7 @@ on: - edited - reopened - synchronize + workflow_dispatch: permissions: pull-requests: write @@ -15,75 +16,199 @@ permissions: contents: read jobs: - test-action: + default-bump-undefined: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: '0' - - # Use the action to generate a tag for itself - - name: Test action main - id: test_main + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/default-bump.sh + - name: Create a tag + id: create-tag uses: ./ env: DRY_RUN: true - WITH_V: true VERBOSE: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Use the action to generate a tag for itself - - name: Test action pre-release - id: test_pre + SOURCE: test-repo + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.2.0" + default-bump-set-to-patch: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/default-bump.sh + - name: Create a tag + id: create-tag uses: ./ env: DRY_RUN: true - WITH_V: true - PRERELEASE: true - PRERELEASE_SUFFIX: test VERBOSE: true + DEFAULT_BUMP: patch GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Check if the action created the expected output + SOURCE: test-repo - name: Check if the tag would have been created shell: bash run: | - set -x - MAIN_OUTPUT_TAG=${{ steps.test_main.outputs.old_tag }} - MAIN_OUTPUT_NEWTAG=${{ steps.test_main.outputs.new_tag }} - MAIN_OUTPUT_PART=${{ steps.test_main.outputs.part }} - PRE_OUTPUT_TAG=${{ steps.test_pre.outputs.old_tag }} - PRE_OUTPUT_NEWTAG=${{ steps.test_pre.outputs.new_tag }} - PRE_OUTPUT_PART=${{ steps.test_pre.outputs.part }} - - echo "Outputs from running the action:" >> $GITHUB_STEP_SUMMARY - echo "MAIN Tag: $MAIN_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY - echo "MAIN New tag: $MAIN_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY - echo "MAIN Part: $MAIN_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY - echo "PRE Tag: $PRE_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY - echo "PRE New tag: $PRE_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY - echo "PRE Part: $PRE_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY - - # check that the original tag got bumped either major, minor, patch - verlte() { - [ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] - } - verlt() { - [ "$1" = "$2" ] && return 1 || verlte $1 $2 - } - - main="$(verlt $MAIN_OUTPUT_TAG $MAIN_OUTPUT_NEWTAG && true || false)" - pre="$(verlt $PRE_OUTPUT_TAG $PRE_OUTPUT_NEWTAG && true || false)" - - if $main && $pre - then - echo "The tags were created correctly" >> $GITHUB_STEP_SUMMARY - else - echo "Tags not created correctly" >> $GITHUB_STEP_SUMMARY - exit 1 - fi - - # todo add test for #none bump - + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.1.2" + default-bump-set-to-major: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/default-bump.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "2.0.0" + several-commits-default-bump: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/several_commits_default_bump.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "6.0.0" + several-commits-mix-tagged-and-not-tagged-commits: + name: "Several commits: if tagged and not tagged commits present then only tagged are taken into account" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.3.0" + several-commits-major-takes-precedence-over-path: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/several_commits_major_takes_precedence_over_path.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.4.0" + custom-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + PREFIX: prefix- + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-1.1.2" + custom-tag-of-initial-value-with-prefix-is-created-if-tag-with-given-prefix-does-not-exist: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + # PREFIX: prefix- + # INITIAL_VERSION: 5.6.7 + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-1.1.0" diff --git a/.github/workflows/tests/_assert.sh b/.github/workflows/tests/_assert.sh new file mode 100755 index 00000000..a85c0a49 --- /dev/null +++ b/.github/workflows/tests/_assert.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +OUTPUT_NEWTAG=$1 +CORRECT_TAG=$2 + +if [[ $OUTPUT_NEWTAG == "${CORRECT_TAG}" ]]; then + echo "The tag was created correctly" >>$GITHUB_STEP_SUMMARY +else + echo "The tag was not created correctly, expected $CORRECT_TAG got $OUTPUT_NEWTAG" >>$GITHUB_STEP_SUMMARY + exit 1 +fi diff --git a/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh b/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh new file mode 100755 index 00000000..fda0bec6 --- /dev/null +++ b/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1.txt" +touch 2.txt && git add . && git commit -m "2.txt" +git tag SOME_TAG-1.1.1 +touch 3.txt && git add . && git commit -m "#patch" \ No newline at end of file diff --git a/.github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh b/.github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh new file mode 100755 index 00000000..0f47f760 --- /dev/null +++ b/.github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1.txt" +touch 2.txt && git add . && git commit -m "2.txt" +git tag prefix-1.1.1 +touch 3.txt && git add . && git commit -m "#patch 3.txt" \ No newline at end of file diff --git a/.github/workflows/tests/default-bump.sh b/.github/workflows/tests/default-bump.sh new file mode 100755 index 00000000..431b4310 --- /dev/null +++ b/.github/workflows/tests/default-bump.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1.txt" +touch 2.txt && git add . && git commit -m "2.txt" +git tag 1.1.1 +touch 3.txt && git add . && git commit -m "3.txt" diff --git a/.github/workflows/tests/several_commits_default_bump.sh b/.github/workflows/tests/several_commits_default_bump.sh new file mode 100755 index 00000000..6dd8ac5e --- /dev/null +++ b/.github/workflows/tests/several_commits_default_bump.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1.txt" +git tag 1.1.1 +touch 2.txt && git add . && git commit -m "2.txt" +touch 3.txt && git add . && git commit -m "3.txt" +touch 4.txt && git add . && git commit -m "4.txt" +touch 5.txt && git add . && git commit -m "5.txt" +touch 6.txt && git add . && git commit -m "6.txt" \ No newline at end of file diff --git a/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh b/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh new file mode 100755 index 00000000..78203988 --- /dev/null +++ b/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1.txt" +git tag 1.1.1 +touch 2.txt && git add . && git commit -m "2.txt" +touch 3.txt && git add . && git commit -m "#patch 3.txt" +touch 4.txt && git add . && git commit -m "4.txt" +touch 5.txt && git add . && git commit -m "5.txt #patch" +touch 7.txt && git add . && git commit -m "6.txt #patch" +touch 8.txt && git add . && git commit -m "6.txt #minor" +touch 9.txt && git add . && git commit -m "6.txt #minor" +touch 10.txt && git add . && git commit -m "#minor_6.txt" \ No newline at end of file diff --git a/.github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh b/.github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh new file mode 100755 index 00000000..ba673971 --- /dev/null +++ b/.github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1.txt" +git tag 1.1.1 +touch 2.txt && git add . && git commit -m "2.txt" +touch 3.txt && git add . && git commit -m "#minor 3.txt" +touch 4.txt && git add . && git commit -m "4.txt" +touch 5.txt && git add . && git commit -m "5.txt #minor" +touch 6.txt && git add . && git commit -m "6.txt" \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f734902e..f57ba6ad 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,7 +2,7 @@ "version": "2.0.0", "tasks": [ { - "label": "act - run tests", + "label": "act - test default-bump-undefined", "command": "act", "options": { "cwd": "${workspaceFolder}" @@ -10,11 +10,116 @@ "args": [ "--rebuild", "--job", - "test-action", + "default-bump-undefined", "--env-file", ".act/.env", ], "type": "shell", - } + }, + { + "label": "act - test default-bump-set-to-patch", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "default-bump-set-to-patch", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test default-bump-set-to-major", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "default-bump-set-to-major", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test several-commits-default-bump", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "several-commits-default-bump", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test several-commits-mix-tagged-and-not-tagged-commits", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "several-commits-mix-tagged-and-not-tagged-commits", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test several-commits-major-takes-precedence-over-path", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "several-commits-major-takes-precedence-over-path", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test custom-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "custom-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test custom-tag-of-initial-value-with-prefix-is-created-if-tag-with-given-prefix-does-not-exist", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "custom-tag-of-initial-value-with-prefix-is-created-if-tag-with-given-prefix-does-not-exist", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, ] } \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index d59afece..b547c809 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -50,10 +50,10 @@ echo -e "\tNONE_STRING_TOKEN: ${none_string_token}" echo -e "*********************\n" # verbose, show everything -if $verbose -then - set -x -fi +# if $verbose TODO: restore +# then +# set -x +# fi push_new_tag_if_not_dry_run() { @@ -107,7 +107,7 @@ echo_previous_tags() { set_number_of_found_keywords() { if $verbose; then echo -e "\n********************************************" - echo -e "Commit messages taken into account" + echo -e "Commit messages taken into account:" if $3; then echo "First commit: $2" git log "$2" --pretty=format:%B | awk 'NF' @@ -140,11 +140,11 @@ bump_version() { count="${!count_var_name}" if $use_last_commit_only; then - echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. $1 will be incremented only by 1" + echo -e "USE_LAST_COMMIT_ONLY set to: '${use_last_commit_only}'. $1 will be incremented only by 1" eval number_of_"$1"=1 count=1 else - echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. $1 will be incremented by ${count}" + echo -e "USE_LAST_COMMIT_ONLY set to: '${use_last_commit_only}'. $1 will be incremented by ${count}" fi for ((c = 1; c <= count; c++)); do @@ -240,8 +240,12 @@ then else tag="$initial_version" fi + echo "tag to be created: $tag" + echo "tag to be created, pre_release: $pre_release" + echo "tag to be created, pre_tag: $pre_tag" if [ -z "$pre_tag" ] && $pre_release then + echo "XXXXXXXX" if [ -n "${prefix}" ] then pre_tag="$initial_version" @@ -251,12 +255,18 @@ then fi else echo_previous_tags "Previous tag was found." - log=$(git log "$tag"..HEAD --pretty='%B' --) fi # get current commit hash for tag -tag_commit=$(git rev-list -n 1 "$tag") + +if [ "$tag" = "$initial_version" ] +then + first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) + tag_commit=first_commit_of_repo +else + tag_commit=$(git rev-list -n 1 "$tag") +fi # get current commit hash commit=$(git rev-parse HEAD) @@ -269,9 +279,11 @@ then exit 0 fi -# get the merge commit message looking for #bumps -log=$(git show -s --format=%s) -echo "Last commit message: $log" +# echo log if verbose is wanted +if $verbose; then + echo "git log for commits between current tag and HEAD:" + echo "$log" +fi # calculate new tag @@ -297,16 +309,14 @@ else is_first_commit_used=false if [ -z "$branch_latest_commit" ]; then - next_commit_after_current_tag=$(git log --pretty=format:"%H" --reverse --ancestry-path "$tag"^.."$commit" | sed -n 2p) + next_commit_after_current_tag=$(git log --pretty=format:"%H" --reverse --ancestry-path "$tag".."$commit" | sed -n 1p) if $verbose; then - echo -e "\n********************************************" - echo "next commit after current tag commit ${number_of_commits}" - echo -e "********************************************\n" + echo "next commit after current tag commit ${next_commit_after_current_tag}" fi set_number_of_found_keywords "$commit" "$next_commit_after_current_tag" "$is_first_commit_used" else base_branch_commit_on_parent_branch=$(diff -u <(git rev-list --first-parent "$branch_latest_commit") <(git rev-list --first-parent "$commit") | sed -ne 's/^ //p' | head -1) - first_separate_commit_on_branch=$(git log --pretty=format:"%H" --reverse --ancestry-path "$base_branch_commit_on_parent_branch"^.."$branch_latest_commit" | sed -n 2p) + first_separate_commit_on_branch=$(git log --pretty=format:"%H" --reverse --ancestry-path "$base_branch_commit_on_parent_branch".."$branch_latest_commit" | sed -n 1p) if $verbose; then echo -e "\n********************************************" echo "base branch commit on parent branch ${base_branch_commit_on_parent_branch}" @@ -331,18 +341,17 @@ if [ "$number_of_major" == 0 ] && [ "$number_of_minor" == 0 ] && [ "$number_of_p bump_version "patch" fi - if [ -z "$new" ]; then if [ "$default_semvar_bump" == "${none_string_token}" ]; then echo "Default bump was set to none. Skipping..." else new=$tagWithoutPrefix if $use_last_commit_only; then - echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented only by 1" + echo -e "USE_LAST_COMMIT_ONLY set to: '${use_last_commit_only}'. default_semvar_bump=${default_semvar_bump} will be incremented only by 1" new=$(semver -i "${default_semvar_bump}" "$new") part=$default_semvar_bump else - echo -e "USE_LAST_COMMIT_ONLY set to: ${use_last_commit_only}. default_semvar_bump=${default_semvar_bump} will be incremented by ${number_of_commits}" + echo -e "USE_LAST_COMMIT_ONLY set to: '${use_last_commit_only}'. default_semvar_bump=${default_semvar_bump} will be incremented by ${number_of_commits}" for ((c = 1; c <= number_of_commits; c++)); do new=$(semver -i "${default_semvar_bump}" "$new") @@ -383,7 +392,6 @@ else echo -e "Bumping tag ${tag} - New tag ${new}" fi - # set outputs echo -e "\nSetting outputs" From e3223ab69ab28ddad8667a4f72d89e5c9cd1ea9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Tue, 4 Oct 2022 14:03:50 +0200 Subject: [PATCH 21/63] custom_string_token --- .github/workflows/test.yml | 78 +++++++++++++++++++ .../workflows/tests/custom_string_token.sh | 21 +++++ .vscode/tasks.json | 45 +++++++++++ 3 files changed, 144 insertions(+) create mode 100755 .github/workflows/tests/custom_string_token.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a5956ad7..02ee028e 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,6 +87,84 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "2.0.0" + custom-string-token-major: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/custom_string_token.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + MAJOR_STRING_TOKEN: ma + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "3.0.0" + custom-string-token-minor: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/custom_string_token.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + MINOR_STRING_TOKEN: mi + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.4.0" + custom-string-token-patch: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/custom_string_token.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + PATCH_STRING_TOKEN: pa + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.1.2" several-commits-default-bump: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/tests/custom_string_token.sh b/.github/workflows/tests/custom_string_token.sh new file mode 100755 index 00000000..31173265 --- /dev/null +++ b/.github/workflows/tests/custom_string_token.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1.txt" +git tag 1.1.1 +touch 2.txt && git add . && git commit -m "2.txt" +touch 3.txt && git add . && git commit -m "ma 3.txt" +touch 4.txt && git add . && git commit -m "4.txt" +touch 5.txt && git add . && git commit -m "ma 5.txt" +touch 6.txt && git add . && git commit -m "6.txt" +touch 7.txt && git add . && git commit -m "mi 7.txt" +touch 8.txt && git add . && git commit -m "pa 8.txt" +touch 9.txt && git add . && git commit -m "mi 9.txt" +touch 10.txt && git add . && git commit -m "mi 10.txt" \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f57ba6ad..88c59aac 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -121,5 +121,50 @@ ], "type": "shell", }, + { + "label": "act - test custom-string-token-major", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "custom-string-token-major", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test custom-string-token-minor", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "custom-string-token-minor", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test custom-string-token-patch", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "custom-string-token-patch", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, ] } \ No newline at end of file From c03197d0d9adfa1455991baefa955c6498436e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Thu, 6 Oct 2022 12:51:37 +0200 Subject: [PATCH 22/63] Initial tag creation tests - don't pass --- .github/workflows/test.yml | 89 +++++++++++++++++-- .../workflows/tests/initial_tag_creation.sh | 12 +++ .vscode/tasks.json | 45 ++++++++++ 3 files changed, 137 insertions(+), 9 deletions(-) create mode 100755 .github/workflows/tests/initial_tag_creation.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 02ee028e..72a2b331 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - name: Check if the tag would have been created @@ -55,7 +54,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: patch GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -79,7 +77,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -103,7 +100,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -129,7 +125,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -155,7 +150,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -181,7 +175,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -207,7 +200,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -232,7 +224,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -241,6 +232,86 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.4.0" + initial-tag-creation: + name: initial tag creation sets initial value regardless of bump tokens + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/initial_tag_creation.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "0.0.0" + initial-tag-creation-custom-with-initial-version: + name: initial tag creation with custom initial version sets initial value regardless of bump tokens + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/initial_tag_creation.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + INITIAL_VERSION: 6.7.8 + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "0.0.0" + initial-tag-creation-with-prefix: + name: initial tag creation with prefix sets initial value regardless of bump tokens + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/initial_tag_creation.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + PREFIX: prefix- + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-0.0.0" custom-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/tests/initial_tag_creation.sh b/.github/workflows/tests/initial_tag_creation.sh new file mode 100755 index 00000000..ff930d27 --- /dev/null +++ b/.github/workflows/tests/initial_tag_creation.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "#major 1.txt" +touch 2.txt && git add . && git commit -m "#major 2.txt" \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 88c59aac..3ce41f89 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -166,5 +166,50 @@ ], "type": "shell", }, + { + "label": "act - test initial-tag-creation", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "initial-tag-creation", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test initial-tag-creation-custom-with-initial-version", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "initial-tag-creation-custom-with-initial-version", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, + { + "label": "act - test initial-tag-creation-with-prefix", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "initial-tag-creation-with-prefix", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, ] } \ No newline at end of file From 1ea1756e2bb0eea71c1a6db608caad017960f4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Thu, 6 Oct 2022 13:09:13 +0200 Subject: [PATCH 23/63] Fix initial tag logic --- .github/workflows/test.yml | 4 +--- entrypoint.sh | 11 +++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 72a2b331..eda5d24d 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -249,7 +249,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -275,7 +274,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -284,7 +282,7 @@ jobs: - name: Check if the tag would have been created shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "0.0.0" + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "6.7.8" initial-tag-creation-with-prefix: name: initial tag creation with prefix sets initial value regardless of bump tokens runs-on: ubuntu-latest diff --git a/entrypoint.sh b/entrypoint.sh index b547c809..845783d4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -301,10 +301,17 @@ if $verbose; then echo -e "********************************************\n" fi -if [ "$tag" = "$initial_version" ]; then +if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ]; then first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) is_first_commit_used=true - set_number_of_found_keywords "$branch_latest_commit" "$first_commit_of_repo" "$is_first_commit_used" + + if [ -z "$branch_latest_commit" ]; then + echo "*set_number_of_found_keywords: first_commit_of_repo commit is_first_commit_used" + set_number_of_found_keywords "$first_commit_of_repo" "$commit" "$is_first_commit_used" + else + echo "*set_number_of_found_keywords: branch_latest_commit first_commit_of_repo is_first_commit_used" + set_number_of_found_keywords "$branch_latest_commit" "$first_commit_of_repo" "$is_first_commit_used" + fi else is_first_commit_used=false From bad55198e7895bb6f565d32619c7d5f1259f4f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Thu, 6 Oct 2022 14:08:39 +0200 Subject: [PATCH 24/63] bug fix --- .github/workflows/test.yml | 28 +++++++++++++++++-- ...if_tag_with_given_prefix_does_not_exist.sh | 6 ++-- .vscode/tasks.json | 15 ++++++++++ entrypoint.sh | 8 ++++-- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eda5d24d..40a1111a 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -235,6 +235,31 @@ jobs: initial-tag-creation: name: initial tag creation sets initial value regardless of bump tokens runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: "0" + - name: Create test repo + shell: bash + run: | + .github/workflows/tests/initial_tag_creation.sh + - name: Create a tag + id: create-tag + uses: ./ + env: + DRY_RUN: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: true + - name: Check if the tag would have been created + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "0.0.0" + initial-tag-creation-do-not-use-last-commit-only: + name: initial tag creation sets initial value regardless of bump tokens - USE_LAST_COMMIT_ONLY is false + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 @@ -277,7 +302,6 @@ jobs: DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - USE_LAST_COMMIT_ONLY: false INITIAL_VERSION: 6.7.8 - name: Check if the tag would have been created shell: bash @@ -304,7 +328,6 @@ jobs: DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - USE_LAST_COMMIT_ONLY: false PREFIX: prefix- - name: Check if the tag would have been created shell: bash @@ -353,6 +376,7 @@ jobs: VERBOSE: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false # PREFIX: prefix- # INITIAL_VERSION: 5.6.7 - name: Check if the tag would have been created diff --git a/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh b/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh index fda0bec6..3135af5e 100755 --- a/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh +++ b/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh @@ -9,6 +9,6 @@ git config --global user.name "Your Name" git init touch 1.txt && git add . && git commit -m "1.txt" -touch 2.txt && git add . && git commit -m "2.txt" -git tag SOME_TAG-1.1.1 -touch 3.txt && git add . && git commit -m "#patch" \ No newline at end of file +# touch 2.txt && git add . && git commit -m "2.txt" +# git tag SOME_TAG-1.1.1 +# touch 3.txt && git add . && git commit -m "#major" \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3ce41f89..2b6da9f8 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -181,6 +181,21 @@ ], "type": "shell", }, + { + "label": "act - test initial-tag-creation-do-not-use-last-commit-only", + "command": "act", + "options": { + "cwd": "${workspaceFolder}" + }, + "args": [ + "--rebuild", + "--job", + "initial-tag-creation-do-not-use-last-commit-only", + "--env-file", + ".act/.env", + ], + "type": "shell", + }, { "label": "act - test initial-tag-creation-custom-with-initial-version", "command": "act", diff --git a/entrypoint.sh b/entrypoint.sh index 845783d4..f673c3b3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -245,7 +245,6 @@ then echo "tag to be created, pre_tag: $pre_tag" if [ -z "$pre_tag" ] && $pre_release then - echo "XXXXXXXX" if [ -n "${prefix}" ] then pre_tag="$initial_version" @@ -260,7 +259,7 @@ fi # get current commit hash for tag -if [ "$tag" = "$initial_version" ] +if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ] then first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) tag_commit=first_commit_of_repo @@ -353,7 +352,10 @@ if [ -z "$new" ]; then echo "Default bump was set to none. Skipping..." else new=$tagWithoutPrefix - if $use_last_commit_only; then + if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ]; then + echo "Initial version will be used" + new=$tag + elif $use_last_commit_only; then echo -e "USE_LAST_COMMIT_ONLY set to: '${use_last_commit_only}'. default_semvar_bump=${default_semvar_bump} will be incremented only by 1" new=$(semver -i "${default_semvar_bump}" "$new") part=$default_semvar_bump From e848625debf56e6894386d92042c1a9229d6dc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sat, 8 Oct 2022 02:13:41 +0200 Subject: [PATCH 25/63] Remove redundant test, rename another --- .github/workflows/test.yml | 30 ++----------------- ...if_tag_with_given_prefix_does_not_exist.sh | 14 --------- ...f_tag_with_given_prefix_already_exists.sh} | 0 .vscode/tasks.json | 4 +-- 4 files changed, 4 insertions(+), 44 deletions(-) delete mode 100755 .github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh rename .github/workflows/tests/{custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh => tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 40a1111a..b0d8c964 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -333,7 +333,7 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-0.0.0" - custom-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists: + tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists: runs-on: ubuntu-latest steps: - name: Checkout @@ -343,7 +343,7 @@ jobs: - name: Create test repo shell: bash run: | - .github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh + .github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh - name: Create a tag id: create-tag uses: ./ @@ -357,29 +357,3 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-1.1.2" - custom-tag-of-initial-value-with-prefix-is-created-if-tag-with-given-prefix-does-not-exist: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo - shell: bash - run: | - .github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh - - name: Create a tag - id: create-tag - uses: ./ - env: - DRY_RUN: true - VERBOSE: true - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SOURCE: test-repo - USE_LAST_COMMIT_ONLY: false - # PREFIX: prefix- - # INITIAL_VERSION: 5.6.7 - - name: Check if the tag would have been created - shell: bash - run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-1.1.0" diff --git a/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh b/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh deleted file mode 100755 index 3135af5e..00000000 --- a/.github/workflows/tests/custom_tag_of_initial_value_with_prefix_is_created_if_tag_with_given_prefix_does_not_exist.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -mkdir test-repo -cd test-repo || exit 1 - -git config --global init.defaultBranch master -git config --global user.email "you@example.com" -git config --global user.name "Your Name" - -git init -touch 1.txt && git add . && git commit -m "1.txt" -# touch 2.txt && git add . && git commit -m "2.txt" -# git tag SOME_TAG-1.1.1 -# touch 3.txt && git add . && git commit -m "#major" \ No newline at end of file diff --git a/.github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh b/.github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh similarity index 100% rename from .github/workflows/tests/custom_tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh rename to .github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2b6da9f8..4311d6c2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -92,7 +92,7 @@ "type": "shell", }, { - "label": "act - test custom-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", + "label": "act - test tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", "command": "act", "options": { "cwd": "${workspaceFolder}" @@ -100,7 +100,7 @@ "args": [ "--rebuild", "--job", - "custom-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", + "tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", "--env-file", ".act/.env", ], From 6dab57bf430aea3b919157063b8b4757fa41a301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sat, 8 Oct 2022 02:37:00 +0200 Subject: [PATCH 26/63] remove `is_first_commit_used' param from set_number_of_found_keywords --- entrypoint.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f673c3b3..a51460e4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -108,12 +108,12 @@ set_number_of_found_keywords() { if $verbose; then echo -e "\n********************************************" echo -e "Commit messages taken into account:" - if $3; then - echo "First commit: $2" + # if $3; then + # echo "First commit: $2" git log "$2" --pretty=format:%B | awk 'NF' - else - git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF' - fi + # else + # git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF' + # fi echo -e "********************************************\n" fi @@ -302,24 +302,23 @@ fi if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ]; then first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) - is_first_commit_used=true if [ -z "$branch_latest_commit" ]; then echo "*set_number_of_found_keywords: first_commit_of_repo commit is_first_commit_used" - set_number_of_found_keywords "$first_commit_of_repo" "$commit" "$is_first_commit_used" + set_number_of_found_keywords "$first_commit_of_repo" "$commit" else echo "*set_number_of_found_keywords: branch_latest_commit first_commit_of_repo is_first_commit_used" - set_number_of_found_keywords "$branch_latest_commit" "$first_commit_of_repo" "$is_first_commit_used" + set_number_of_found_keywords "$branch_latest_commit" "$first_commit_of_repo" fi else - is_first_commit_used=false if [ -z "$branch_latest_commit" ]; then next_commit_after_current_tag=$(git log --pretty=format:"%H" --reverse --ancestry-path "$tag".."$commit" | sed -n 1p) if $verbose; then echo "next commit after current tag commit ${next_commit_after_current_tag}" fi - set_number_of_found_keywords "$commit" "$next_commit_after_current_tag" "$is_first_commit_used" + echo "*set_number_of_found_keywords: commit next_commit_after_current_tag is_first_commit_used" + set_number_of_found_keywords "$commit" "$next_commit_after_current_tag" else base_branch_commit_on_parent_branch=$(diff -u <(git rev-list --first-parent "$branch_latest_commit") <(git rev-list --first-parent "$commit") | sed -ne 's/^ //p' | head -1) first_separate_commit_on_branch=$(git log --pretty=format:"%H" --reverse --ancestry-path "$base_branch_commit_on_parent_branch".."$branch_latest_commit" | sed -n 1p) @@ -329,7 +328,7 @@ else echo "first separate commit on branch ${first_separate_commit_on_branch}" echo -e "********************************************\n" fi - set_number_of_found_keywords "$branch_latest_commit" "$first_separate_commit_on_branch" "$is_first_commit_used" + set_number_of_found_keywords "$branch_latest_commit" "$first_separate_commit_on_branch" fi fi From e6b3aaf6d03354e3fabbf675ad590fffde48fbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sat, 8 Oct 2022 03:11:27 +0200 Subject: [PATCH 27/63] Clean code related to logging --- entrypoint.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index a51460e4..5c5cf4cc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -47,7 +47,7 @@ echo -e "\tMAJOR_STRING_TOKEN: ${major_string_token}" echo -e "\tMINOR_STRING_TOKEN: ${minor_string_token}" echo -e "\tPATCH_STRING_TOKEN: ${patch_string_token}" echo -e "\tNONE_STRING_TOKEN: ${none_string_token}" -echo -e "*********************\n" +echo -e "******************************************\n" # verbose, show everything # if $verbose TODO: restore @@ -124,6 +124,9 @@ set_number_of_found_keywords() { if $verbose; then echo -e "\n********************************************" + echo -e "Commit messages taken into account:\n" + echo "${commit_messages_taken_into_account}" + echo -e "\n" echo "number of major_string_token tag occurrences ${number_of_major}" echo "number of minor_string_token tag occurrences ${number_of_minor}" echo "number of patch_string_token tag occurrences ${number_of_patch}" @@ -233,7 +236,6 @@ if [ -z "$tag" ] then echo_previous_tags "No tag was found. INITIAL_VERSION will be used instead." - log=$(git log --pretty='%B' --) if [ -n "${prefix}" ] then tag="${prefix}${initial_version}" @@ -254,7 +256,6 @@ then fi else echo_previous_tags "Previous tag was found." - log=$(git log "$tag"..HEAD --pretty='%B' --) fi # get current commit hash for tag @@ -278,12 +279,6 @@ then exit 0 fi -# echo log if verbose is wanted -if $verbose; then - echo "git log for commits between current tag and HEAD:" - echo "$log" -fi - # calculate new tag # Get number of occurrences of bump key words in From 8fbdd745cec42803d158ebc3f6513e5ca4ece57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sat, 8 Oct 2022 03:12:21 +0200 Subject: [PATCH 28/63] Handle the case of a repo with a single commit --- entrypoint.sh | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5c5cf4cc..5bfba451 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -105,22 +105,20 @@ echo_previous_tags() { } set_number_of_found_keywords() { - if $verbose; then - echo -e "\n********************************************" - echo -e "Commit messages taken into account:" - # if $3; then - # echo "First commit: $2" - git log "$2" --pretty=format:%B | awk 'NF' - # else - # git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF' - # fi - echo -e "********************************************\n" - fi - number_of_major=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "${major_string_token}" -c) - number_of_minor=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "${minor_string_token}" -c) - number_of_patch=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "${patch_string_token}" -c) - number_of_commits=$(git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF' | grep "" -c) + if [[ "${1}" == "${2}" ]]; then # handle the case of a repo with a single commit + commit_messages_taken_into_account=$(git log "$1"..."$2" --pretty=format:%B | awk 'NF') + number_of_major=$(git log "$1"..."$2" --pretty=format:%B | grep -E "${major_string_token}" -c) + number_of_minor=$(git log "$1"..."$2" --pretty=format:%B | grep -E "${minor_string_token}" -c) + number_of_patch=$(git log "$1"..."$2" --pretty=format:%B | grep -E "${patch_string_token}" -c) + number_of_commits=$(git log "$1"..."$2" --pretty=format:%B | awk 'NF' | grep "" -c) + else + commit_messages_taken_into_account=$(git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF') + number_of_major=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "${major_string_token}" -c) + number_of_minor=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "${minor_string_token}" -c) + number_of_patch=$(git log "$1"..."$2"~1 --pretty=format:%B | grep -E "${patch_string_token}" -c) + number_of_commits=$(git log "$1"..."$2"~1 --pretty=format:%B | awk 'NF' | grep "" -c) + fi if $verbose; then echo -e "\n********************************************" From 2f4c3b24f35bf97af18f1e735608a6a32fa00aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sat, 8 Oct 2022 12:26:38 +0200 Subject: [PATCH 29/63] All tests are ran in a single job --- .github/workflows/test.yml | 252 ++++++++++------------------- .github/workflows/tests/_assert.sh | 2 + .vscode/tasks.json | 216 +------------------------ 3 files changed, 90 insertions(+), 380 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0d8c964..5b7adce2 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,87 +16,70 @@ permissions: contents: read jobs: - default-bump-undefined: + run-tests: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: "0" - - name: Create test repo + # default-bump-undefined + - name: "Create test repo: default-bump-undefined" shell: bash run: | .github/workflows/tests/default-bump.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: default-bump-undefined" + id: create-tag-default-bump-undefined uses: ./ env: DRY_RUN: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - - name: Check if the tag would have been created + - name: "Assert the created tag: default-bump-undefined" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.2.0" - default-bump-set-to-patch: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-undefined.outputs.new_tag }} "1.2.0" + # default-bump-set-to-patch + - name: "Create test repo: default-bump-set-to-patch" shell: bash run: | .github/workflows/tests/default-bump.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: default-bump-set-to-patch" + id: create-tag-default-bump-set-to-patch uses: ./ env: DRY_RUN: true DEFAULT_BUMP: patch GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - - name: Check if the tag would have been created + - name: "Assert the created tag: default-bump-set-to-patch" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.1.2" - default-bump-set-to-major: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-set-to-patch.outputs.new_tag }} "1.1.2" + # default-bump-set-to-major + - name: "Create test repo: default-bump-set-to-major" shell: bash run: | .github/workflows/tests/default-bump.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: default-bump-set-to-major" + id: create-tag-default-bump-set-to-major uses: ./ env: DRY_RUN: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - - name: Check if the tag would have been created + - name: "Assert the created tag: default-bump-set-to-major" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "2.0.0" - custom-string-token-major: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-set-to-major.outputs.new_tag }} "2.0.0" + # custom-string-token-major: + - name: "Create test repo: custom-string-token-major" shell: bash run: | .github/workflows/tests/custom_string_token.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: custom-string-token-major" + id: create-tag-custom-string-token-major uses: ./ env: DRY_RUN: true @@ -105,23 +88,17 @@ jobs: SOURCE: test-repo USE_LAST_COMMIT_ONLY: false MAJOR_STRING_TOKEN: ma - - name: Check if the tag would have been created + - name: "Assert the created tag: custom-string-token-major" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "3.0.0" - custom-string-token-minor: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-major.outputs.new_tag }} "3.0.0" + # custom-string-token-minor: + - name: "Create test repo: custom-string-token-minor" shell: bash run: | .github/workflows/tests/custom_string_token.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: custom-string-token-minor" + id: create-tag-custom-string-token-minor uses: ./ env: DRY_RUN: true @@ -130,23 +107,17 @@ jobs: SOURCE: test-repo USE_LAST_COMMIT_ONLY: false MINOR_STRING_TOKEN: mi - - name: Check if the tag would have been created + - name: "Assert the created tag: custom-string-token-minor" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.4.0" - custom-string-token-patch: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-minor.outputs.new_tag }} "1.4.0" + # custom-string-token-patch: + - name: "Create test repo: custom-string-token-patch" shell: bash run: | .github/workflows/tests/custom_string_token.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: custom-string-token-patch" + id: create-tag-custom-string-token-patch uses: ./ env: DRY_RUN: true @@ -155,23 +126,17 @@ jobs: SOURCE: test-repo USE_LAST_COMMIT_ONLY: false PATCH_STRING_TOKEN: pa - - name: Check if the tag would have been created + - name: "Assert the created tag: custom-string-token-patch" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.1.2" - several-commits-default-bump: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-patch.outputs.new_tag }} "1.1.2" + # several-commits-default-bump: + - name: "Create test repo: several-commits-default-bump" shell: bash run: | .github/workflows/tests/several_commits_default_bump.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: several-commits-default-bump" + id: create-tag-several-commits-default-bump uses: ./ env: DRY_RUN: true @@ -179,24 +144,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo USE_LAST_COMMIT_ONLY: false - - name: Check if the tag would have been created + - name: "Assert the created tag: several-commits-default-bump" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "6.0.0" - several-commits-mix-tagged-and-not-tagged-commits: - name: "Several commits: if tagged and not tagged commits present then only tagged are taken into account" - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-default-bump.outputs.new_tag }} "6.0.0" + # several-commits-mix-tagged-and-not-tagged-commits: + - name: "Create test repo: several-commits-mix-tagged-and-not-tagged-commits" shell: bash run: | .github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: several-commits-mix-tagged-and-not-tagged-commits" + id: create-tag-several-commits-mix-tagged-and-not-tagged-commits uses: ./ env: DRY_RUN: true @@ -204,23 +162,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo USE_LAST_COMMIT_ONLY: false - - name: Check if the tag would have been created + - name: "Assert the created tag: several-commits-mix-tagged-and-not-tagged-commits" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.3.0" - several-commits-major-takes-precedence-over-path: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-mix-tagged-and-not-tagged-commits.outputs.new_tag }} "1.3.0" + # several-commits-major-takes-precedence-over-path: + - name: "Create test repo: several-commits-major-takes-precedence-over-path" shell: bash run: | .github/workflows/tests/several_commits_major_takes_precedence_over_path.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: several-commits-major-takes-precedence-over-path" + id: create-tag-several-commits-major-takes-precedence-over-path uses: ./ env: DRY_RUN: true @@ -228,24 +180,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo USE_LAST_COMMIT_ONLY: false - - name: Check if the tag would have been created + - name: "Assert the created tag: " shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "1.4.0" - initial-tag-creation: - name: initial tag creation sets initial value regardless of bump tokens - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-major-takes-precedence-over-path.outputs.new_tag }} "1.4.0" + # initial-tag-creation: + - name: "Create test repo: initial-tag-creation" shell: bash run: | .github/workflows/tests/initial_tag_creation.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: initial-tag-creation" + id: create-tag-initial-tag-creation uses: ./ env: DRY_RUN: true @@ -253,24 +198,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo USE_LAST_COMMIT_ONLY: true - - name: Check if the tag would have been created + - name: "Assert the created tag: initial-tag-creation" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "0.0.0" - initial-tag-creation-do-not-use-last-commit-only: - name: initial tag creation sets initial value regardless of bump tokens - USE_LAST_COMMIT_ONLY is false - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation.outputs.new_tag }} "0.0.0" + # initial-tag-creation-do-not-use-last-commit-only: + - name: "Create test repo: initial-tag-creation-do-not-use-last-commit-only" shell: bash run: | .github/workflows/tests/initial_tag_creation.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: initial-tag-creation-do-not-use-last-commit-only" + id: create-tag-initial-tag-creation-do-not-use-last-commit-only uses: ./ env: DRY_RUN: true @@ -278,24 +216,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo USE_LAST_COMMIT_ONLY: false - - name: Check if the tag would have been created + - name: "Assert the created tag: initial-tag-creation-do-not-use-last-commit-only" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "0.0.0" - initial-tag-creation-custom-with-initial-version: - name: initial tag creation with custom initial version sets initial value regardless of bump tokens - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-do-not-use-last-commit-only.outputs.new_tag }} "0.0.0" + # initial-tag-creation-custom-with-initial-version: + - name: "Create test repo: initial-tag-creation-custom-with-initial-version" shell: bash run: | .github/workflows/tests/initial_tag_creation.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: initial-tag-creation-custom-with-initial-version" + id: create-tag-initial-tag-creation-custom-with-initial-version uses: ./ env: DRY_RUN: true @@ -303,24 +234,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo INITIAL_VERSION: 6.7.8 - - name: Check if the tag would have been created + - name: "Assert the created tag: initial-tag-creation-custom-with-initial-version" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "6.7.8" - initial-tag-creation-with-prefix: - name: initial tag creation with prefix sets initial value regardless of bump tokens - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-custom-with-initial-version.outputs.new_tag }} "6.7.8" + # initial-tag-creation-with-prefix: + - name: "Create test repo: initial-tag-creation-with-prefix" shell: bash run: | .github/workflows/tests/initial_tag_creation.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: initial-tag-creation-with-prefix" + id: create-tag-initial-tag-creation-with-prefix uses: ./ env: DRY_RUN: true @@ -329,23 +253,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo PREFIX: prefix- - - name: Check if the tag would have been created + - name: "Assert the created tag: initial-tag-creation-with-prefix" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-0.0.0" - tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: "0" - - name: Create test repo + .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-with-prefix.outputs.new_tag }} "prefix-0.0.0" + # tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists: + - name: "Create test repo: tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists" shell: bash run: | .github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh - - name: Create a tag - id: create-tag + - name: "Create a tag: tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists" + id: create-tag-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists uses: ./ env: DRY_RUN: true @@ -353,7 +271,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo PREFIX: prefix- - - name: Check if the tag would have been created + - name: "Assert the created tag: tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag.outputs.new_tag }} "prefix-1.1.2" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists.outputs.new_tag }} "prefix-1.1.2" diff --git a/.github/workflows/tests/_assert.sh b/.github/workflows/tests/_assert.sh index a85c0a49..435032f2 100755 --- a/.github/workflows/tests/_assert.sh +++ b/.github/workflows/tests/_assert.sh @@ -5,7 +5,9 @@ CORRECT_TAG=$2 if [[ $OUTPUT_NEWTAG == "${CORRECT_TAG}" ]]; then echo "The tag was created correctly" >>$GITHUB_STEP_SUMMARY + rm -rf test-repo else echo "The tag was not created correctly, expected $CORRECT_TAG got $OUTPUT_NEWTAG" >>$GITHUB_STEP_SUMMARY + rm -rf test-repo exit 1 fi diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4311d6c2..15e85850 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,7 +2,7 @@ "version": "2.0.0", "tasks": [ { - "label": "act - test default-bump-undefined", + "label": "act - test run-tests", "command": "act", "options": { "cwd": "${workspaceFolder}" @@ -10,221 +10,11 @@ "args": [ "--rebuild", "--job", - "default-bump-undefined", + "run-tests", "--env-file", ".act/.env", ], "type": "shell", - }, - { - "label": "act - test default-bump-set-to-patch", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "default-bump-set-to-patch", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test default-bump-set-to-major", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "default-bump-set-to-major", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test several-commits-default-bump", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "several-commits-default-bump", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test several-commits-mix-tagged-and-not-tagged-commits", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "several-commits-mix-tagged-and-not-tagged-commits", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test several-commits-major-takes-precedence-over-path", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "several-commits-major-takes-precedence-over-path", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test custom-tag-of-initial-value-with-prefix-is-created-if-tag-with-given-prefix-does-not-exist", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "custom-tag-of-initial-value-with-prefix-is-created-if-tag-with-given-prefix-does-not-exist", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test custom-string-token-major", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "custom-string-token-major", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test custom-string-token-minor", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "custom-string-token-minor", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test custom-string-token-patch", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "custom-string-token-patch", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test initial-tag-creation", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "initial-tag-creation", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test initial-tag-creation-do-not-use-last-commit-only", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "initial-tag-creation-do-not-use-last-commit-only", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test initial-tag-creation-custom-with-initial-version", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "initial-tag-creation-custom-with-initial-version", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, - { - "label": "act - test initial-tag-creation-with-prefix", - "command": "act", - "options": { - "cwd": "${workspaceFolder}" - }, - "args": [ - "--rebuild", - "--job", - "initial-tag-creation-with-prefix", - "--env-file", - ".act/.env", - ], - "type": "shell", - }, + } ] } \ No newline at end of file From a58ad8e41e3b45f7a2bf95eba84cbd93d8294617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sat, 8 Oct 2022 12:33:10 +0200 Subject: [PATCH 30/63] Fix shellcheck warnings --- .github/workflows/tests/_assert.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests/_assert.sh b/.github/workflows/tests/_assert.sh index 435032f2..bbb9a078 100755 --- a/.github/workflows/tests/_assert.sh +++ b/.github/workflows/tests/_assert.sh @@ -4,10 +4,10 @@ OUTPUT_NEWTAG=$1 CORRECT_TAG=$2 if [[ $OUTPUT_NEWTAG == "${CORRECT_TAG}" ]]; then - echo "The tag was created correctly" >>$GITHUB_STEP_SUMMARY + echo "The tag was created correctly" >>"$GITHUB_STEP_SUMMARY" rm -rf test-repo else - echo "The tag was not created correctly, expected $CORRECT_TAG got $OUTPUT_NEWTAG" >>$GITHUB_STEP_SUMMARY + echo "The tag was not created correctly, expected $CORRECT_TAG got $OUTPUT_NEWTAG" >>"$GITHUB_STEP_SUMMARY" rm -rf test-repo exit 1 fi From b3b6ee9a73d28b2ca9341993c20d54b7edef8c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 16 Nov 2022 22:03:05 +0100 Subject: [PATCH 31/63] Fix a bug with duplicated prefix --- entrypoint.sh | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5bfba451..4abf4cb6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -230,27 +230,15 @@ if [ -n "$with_v" ]; then fi # if there are none, start tags at INITIAL_VERSION -if [ -z "$tag" ] -then +if [ -z "$tag" ]; then echo_previous_tags "No tag was found. INITIAL_VERSION will be used instead." - if [ -n "${prefix}" ] - then - tag="${prefix}${initial_version}" - else - tag="$initial_version" - fi + tag="$initial_version" echo "tag to be created: $tag" echo "tag to be created, pre_release: $pre_release" echo "tag to be created, pre_tag: $pre_tag" - if [ -z "$pre_tag" ] && $pre_release - then - if [ -n "${prefix}" ] - then - pre_tag="$initial_version" - else - pre_tag="${prefix}$initial_version" - fi + if [ -z "$pre_tag" ] && $pre_release; then + pre_tag="${prefix}$initial_version" fi else echo_previous_tags "Previous tag was found." From f4fab4530189512066f661be4da6341d30face80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 16 Nov 2022 22:16:29 +0100 Subject: [PATCH 32/63] Fix create-tag-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists test --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b7adce2..68296061 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -268,6 +268,7 @@ jobs: env: DRY_RUN: true VERBOSE: true + DEFAULT_BUMP: patch GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo PREFIX: prefix- From e8eeee1847df41fb629e6ec5479e09c9477de1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 16 Nov 2022 22:17:30 +0100 Subject: [PATCH 33/63] Remove unnecesseray output assignment --- entrypoint.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4abf4cb6..099be3a1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -403,8 +403,6 @@ then exit 0 fi -echo "::set-output name=tag::$new" - # create local git tag git tag "$new" From bedffb2c631136984c5805076c79ace92debe3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 16 Nov 2022 22:22:58 +0100 Subject: [PATCH 34/63] Fix formatting --- .../workflows/tests/custom_string_token.sh | 2 +- .../workflows/tests/initial_tag_creation.sh | 2 +- .../tests/several_commits_default_bump.sh | 2 +- ...ommits_major_takes_precedence_over_path.sh | 2 +- ...ral_mixed_tagged_and_not_tagged_commits.sh | 2 +- ...if_tag_with_given_prefix_already_exists.sh | 2 +- entrypoint.sh | 82 ++++++++----------- 7 files changed, 41 insertions(+), 53 deletions(-) diff --git a/.github/workflows/tests/custom_string_token.sh b/.github/workflows/tests/custom_string_token.sh index 31173265..c633ee47 100755 --- a/.github/workflows/tests/custom_string_token.sh +++ b/.github/workflows/tests/custom_string_token.sh @@ -18,4 +18,4 @@ touch 6.txt && git add . && git commit -m "6.txt" touch 7.txt && git add . && git commit -m "mi 7.txt" touch 8.txt && git add . && git commit -m "pa 8.txt" touch 9.txt && git add . && git commit -m "mi 9.txt" -touch 10.txt && git add . && git commit -m "mi 10.txt" \ No newline at end of file +touch 10.txt && git add . && git commit -m "mi 10.txt" diff --git a/.github/workflows/tests/initial_tag_creation.sh b/.github/workflows/tests/initial_tag_creation.sh index ff930d27..cc13f00f 100755 --- a/.github/workflows/tests/initial_tag_creation.sh +++ b/.github/workflows/tests/initial_tag_creation.sh @@ -9,4 +9,4 @@ git config --global user.name "Your Name" git init touch 1.txt && git add . && git commit -m "#major 1.txt" -touch 2.txt && git add . && git commit -m "#major 2.txt" \ No newline at end of file +touch 2.txt && git add . && git commit -m "#major 2.txt" diff --git a/.github/workflows/tests/several_commits_default_bump.sh b/.github/workflows/tests/several_commits_default_bump.sh index 6dd8ac5e..c60c172e 100755 --- a/.github/workflows/tests/several_commits_default_bump.sh +++ b/.github/workflows/tests/several_commits_default_bump.sh @@ -14,4 +14,4 @@ touch 2.txt && git add . && git commit -m "2.txt" touch 3.txt && git add . && git commit -m "3.txt" touch 4.txt && git add . && git commit -m "4.txt" touch 5.txt && git add . && git commit -m "5.txt" -touch 6.txt && git add . && git commit -m "6.txt" \ No newline at end of file +touch 6.txt && git add . && git commit -m "6.txt" diff --git a/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh b/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh index 78203988..4b727bb2 100755 --- a/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh +++ b/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh @@ -17,4 +17,4 @@ touch 5.txt && git add . && git commit -m "5.txt #patch" touch 7.txt && git add . && git commit -m "6.txt #patch" touch 8.txt && git add . && git commit -m "6.txt #minor" touch 9.txt && git add . && git commit -m "6.txt #minor" -touch 10.txt && git add . && git commit -m "#minor_6.txt" \ No newline at end of file +touch 10.txt && git add . && git commit -m "#minor_6.txt" diff --git a/.github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh b/.github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh index ba673971..d398ce7c 100755 --- a/.github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh +++ b/.github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh @@ -14,4 +14,4 @@ touch 2.txt && git add . && git commit -m "2.txt" touch 3.txt && git add . && git commit -m "#minor 3.txt" touch 4.txt && git add . && git commit -m "4.txt" touch 5.txt && git add . && git commit -m "5.txt #minor" -touch 6.txt && git add . && git commit -m "6.txt" \ No newline at end of file +touch 6.txt && git add . && git commit -m "6.txt" diff --git a/.github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh b/.github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh index 0f47f760..30a9f08a 100755 --- a/.github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh +++ b/.github/workflows/tests/tag_with_prefix_is_bumped_if_tag_with_given_prefix_already_exists.sh @@ -11,4 +11,4 @@ git init touch 1.txt && git add . && git commit -m "1.txt" touch 2.txt && git add . && git commit -m "2.txt" git tag prefix-1.1.1 -touch 3.txt && git add . && git commit -m "#patch 3.txt" \ No newline at end of file +touch 3.txt && git add . && git commit -m "#patch 3.txt" diff --git a/entrypoint.sh b/entrypoint.sh index 099be3a1..9a4b9f16 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -157,16 +157,14 @@ bump_version() { current_branch=$(git rev-parse --abbrev-ref HEAD) pre_release="$prerelease" -IFS=',' read -ra branch <<< "$release_branches" +IFS=',' read -ra branch <<<"$release_branches" for b in "${branch[@]}"; do # check if ${current_branch} is in ${release_branches} | exact branch match - if [[ "$current_branch" == "$b" ]] - then + if [[ "$current_branch" == "$b" ]]; then pre_release="false" fi # verify non specific branch names like .* release/* if wildcard filter then =~ - if [ "$b" != "${b//[\[\]|.? +*]/}" ] && [[ "$current_branch" =~ $b ]] - then + if [ "$b" != "${b//[\[\]|.? +*]/}" ] && [[ "$current_branch" =~ $b ]]; then pre_release="false" fi done @@ -180,16 +178,18 @@ preTagFmt="^$prefix?[0-9]+\.[0-9]+\.[0-9]+(-$suffix\.[0-9]+)$" # get latest tag that looks like a semver (with or without prefix) case "$tag_context" in - *repo*) - 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*) - 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;; +*repo*) + 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*) + 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 + ;; esac # as defined in readme if CUSTOM_TAG is used any semver calculations are irrelevant. @@ -246,19 +246,17 @@ fi # get current commit hash for tag -if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ] -then +if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ]; then first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) tag_commit=first_commit_of_repo -else +else tag_commit=$(git rev-list -n 1 "$tag") fi # 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=new_tag::$tag" echo "::set-output name=tag::$tag" @@ -281,14 +279,12 @@ if $verbose; then echo -e "********************************************\n" fi -if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ]; then +if [ "$tag" = "$initial_version" ] || [ "$tag" = "${prefix}${initial_version}" ]; then #TODO: Comment each branch first_commit_of_repo=$(git rev-list --max-parents=0 HEAD) if [ -z "$branch_latest_commit" ]; then - echo "*set_number_of_found_keywords: first_commit_of_repo commit is_first_commit_used" set_number_of_found_keywords "$first_commit_of_repo" "$commit" else - echo "*set_number_of_found_keywords: branch_latest_commit first_commit_of_repo is_first_commit_used" set_number_of_found_keywords "$branch_latest_commit" "$first_commit_of_repo" fi else @@ -298,11 +294,11 @@ else if $verbose; then echo "next commit after current tag commit ${next_commit_after_current_tag}" fi - echo "*set_number_of_found_keywords: commit next_commit_after_current_tag is_first_commit_used" set_number_of_found_keywords "$commit" "$next_commit_after_current_tag" else base_branch_commit_on_parent_branch=$(diff -u <(git rev-list --first-parent "$branch_latest_commit") <(git rev-list --first-parent "$commit") | sed -ne 's/^ //p' | head -1) first_separate_commit_on_branch=$(git log --pretty=format:"%H" --reverse --ancestry-path "$base_branch_commit_on_parent_branch".."$branch_latest_commit" | sed -n 1p) + if $verbose; then echo -e "\n********************************************" echo "base branch commit on parent branch ${base_branch_commit_on_parent_branch}" @@ -350,22 +346,17 @@ if [ -z "$new" ]; then fi fi - -if $pre_release -then +if $pre_release; then # already a pre-release available, bump it - if [[ "$pre_tag" =~ $new ]] && [[ "$pre_tag" =~ $suffix ]] - then - if [ -n "${prefix}" ] - then + if [[ "$pre_tag" =~ $new ]] && [[ "$pre_tag" =~ $suffix ]]; then + if [ -n "${prefix}" ]; then new=${prefix}$(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 - if [ -n "${prefix}" ] - then + if [ -n "${prefix}" ]; then new="${prefix}$new-$suffix.0" else new="$new-$suffix.0" @@ -374,8 +365,7 @@ then fi part="pre-$part" else - if [ -n "${prefix}" ] - then + if [ -n "${prefix}" ]; then new="${prefix}${new}" fi echo -e "Bumping tag ${tag} - New tag ${new}" @@ -397,11 +387,10 @@ echo "::set-output name=tag::$new" # this needs to go in v2 is breaking change echo "::set-output name=old_tag::$tag" # use dry run to determine the next tag -if $dryrun -then +if $dryrun; then echo "::set-output name=tag::$tag" exit 0 -fi +fi # create local git tag git tag "$new" @@ -414,9 +403,9 @@ git_refs_url=$(jq .repository.git_refs_url "$GITHUB_EVENT_PATH" | tr -d '"' | se echo "$dt: **pushing tag $new to repo $full_name" git_refs_response=$( -curl -s -X POST "$git_refs_url" \ --H "Authorization: token $GITHUB_TOKEN" \ --d @- << EOF + curl -s -X POST "$git_refs_url" \ + -H "Authorization: token $GITHUB_TOKEN" \ + -d @- < Date: Wed, 21 Dec 2022 18:18:00 +0100 Subject: [PATCH 35/63] Fix typo path->patch --- .github/workflows/test.yml | 12 ++++++------ ...ral_commits_major_takes_precedence_over_patch.sh} | 0 2 files changed, 6 insertions(+), 6 deletions(-) rename .github/workflows/tests/{several_commits_major_takes_precedence_over_path.sh => several_commits_major_takes_precedence_over_patch.sh} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 68296061..51efa98b 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -166,13 +166,13 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-mix-tagged-and-not-tagged-commits.outputs.new_tag }} "1.3.0" - # several-commits-major-takes-precedence-over-path: - - name: "Create test repo: several-commits-major-takes-precedence-over-path" + # several-commits-major-takes-precedence-over-patch: + - name: "Create test repo: several-commits-major-takes-precedence-over-patch" shell: bash run: | - .github/workflows/tests/several_commits_major_takes_precedence_over_path.sh - - name: "Create a tag: several-commits-major-takes-precedence-over-path" - id: create-tag-several-commits-major-takes-precedence-over-path + .github/workflows/tests/several_commits_major_takes_precedence_over_patch.sh + - name: "Create a tag: several-commits-major-takes-precedence-over-patch" + id: create-tag-several-commits-major-takes-precedence-over-patch uses: ./ env: DRY_RUN: true @@ -183,7 +183,7 @@ jobs: - name: "Assert the created tag: " shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-major-takes-precedence-over-path.outputs.new_tag }} "1.4.0" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-major-takes-precedence-over-patch.outputs.new_tag }} "1.4.0" # initial-tag-creation: - name: "Create test repo: initial-tag-creation" shell: bash diff --git a/.github/workflows/tests/several_commits_major_takes_precedence_over_path.sh b/.github/workflows/tests/several_commits_major_takes_precedence_over_patch.sh similarity index 100% rename from .github/workflows/tests/several_commits_major_takes_precedence_over_path.sh rename to .github/workflows/tests/several_commits_major_takes_precedence_over_patch.sh From 0beaa438abb8b1ae7247a0ff117c40e4f5a8dba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 14:37:06 +0100 Subject: [PATCH 36/63] Bug fix: properly create a tag when initial version is provided with a prefix --- .github/workflows/test.yml | 31 +++++++++++++++++++++++++------ entrypoint.sh | 5 +++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 51efa98b..cb00cab8 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -220,13 +220,13 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-do-not-use-last-commit-only.outputs.new_tag }} "0.0.0" - # initial-tag-creation-custom-with-initial-version: - - name: "Create test repo: initial-tag-creation-custom-with-initial-version" + # initial-tag-creation-with-initial-version: + - name: "Create test repo: initial-tag-creation-with-initial-version" shell: bash run: | .github/workflows/tests/initial_tag_creation.sh - - name: "Create a tag: initial-tag-creation-custom-with-initial-version" - id: create-tag-initial-tag-creation-custom-with-initial-version + - name: "Create a tag: initial-tag-creation-with-initial-version" + id: create-tag-initial-tag-creation-with-initial-version uses: ./ env: DRY_RUN: true @@ -234,10 +234,29 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo INITIAL_VERSION: 6.7.8 - - name: "Assert the created tag: initial-tag-creation-custom-with-initial-version" + - name: "Assert the created tag: initial-tag-creation-with-initial-version" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-custom-with-initial-version.outputs.new_tag }} "6.7.8" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-with-initial-version.outputs.new_tag }} "6.7.8" + # initial-tag-creation-with-prefixed-initial-version: + - name: "Create test repo: initial-tag-creation-with-prefixed-initial-version" + shell: bash + run: | + .github/workflows/tests/initial_tag_creation.sh + - name: "Create a tag: initial-tag-creation-with-prefixed-initial-version" + id: create-tag-initial-tag-creation-with-prefixed-initial-version + uses: ./ + env: + DRY_RUN: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + INITIAL_VERSION: someprefix-6.7.8 + PREFIX: someprefix- + - name: "Assert the created tag: initial-tag-creation-with-prefixed-initial-version" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-with-prefixed-initial-version.outputs.new_tag }} "someprefix-6.7.8" # initial-tag-creation-with-prefix: - name: "Create test repo: initial-tag-creation-with-prefix" shell: bash diff --git a/entrypoint.sh b/entrypoint.sh index 9a4b9f16..255771d3 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -233,6 +233,11 @@ fi if [ -z "$tag" ]; then echo_previous_tags "No tag was found. INITIAL_VERSION will be used instead." + pattern="^${prefix}[0-9]+\.[0-9]+\.[0-9]+$" + if [[ $initial_version =~ $pattern ]]; then + initial_version=${initial_version#"$prefix"} + fi + tag="$initial_version" echo "tag to be created: $tag" echo "tag to be created, pre_release: $pre_release" From 0d44d90d547e9ffa3d9e551179ad36e6f6747ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 16:45:42 +0100 Subject: [PATCH 37/63] Throw an error when INITIAL_VERSION is in incorrect format --- entrypoint.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 255771d3..b7a34747 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -233,11 +233,17 @@ fi if [ -z "$tag" ]; then echo_previous_tags "No tag was found. INITIAL_VERSION will be used instead." - pattern="^${prefix}[0-9]+\.[0-9]+\.[0-9]+$" - if [[ $initial_version =~ $pattern ]]; then + semver_pattern_with_prefix="^${prefix}[0-9]+\.[0-9]+\.[0-9]+$" + if [[ $initial_version =~ $semver_pattern_with_prefix ]]; then initial_version=${initial_version#"$prefix"} fi + semver_pattern="^[0-9]+\.[0-9]+\.[0-9]+$" + if ! [[ $initial_version =~ $semver_pattern ]]; then + echo "::error::Provided INITIAL_VERSION has incorrect format" + exit 1 + fi + tag="$initial_version" echo "tag to be created: $tag" echo "tag to be created, pre_release: $pre_release" From 4967baac9c1b837c8bf5361d0b2c4e83dcfbbaa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 17:02:59 +0100 Subject: [PATCH 38/63] Rename test cases --- .github/workflows/test.yml | 72 ++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cb00cab8..82173c97 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,13 +73,13 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-set-to-major.outputs.new_tag }} "2.0.0" - # custom-string-token-major: - - name: "Create test repo: custom-string-token-major" + # custom-string-token-major-multiple-commits: + - name: "Create test repo: custom-string-token-major-multiple-commits" shell: bash run: | .github/workflows/tests/custom_string_token.sh - - name: "Create a tag: custom-string-token-major" - id: create-tag-custom-string-token-major + - name: "Create a tag: custom-string-token-major-multiple-commits" + id: create-tag-custom-string-token-major-multiple-commits uses: ./ env: DRY_RUN: true @@ -88,17 +88,17 @@ jobs: SOURCE: test-repo USE_LAST_COMMIT_ONLY: false MAJOR_STRING_TOKEN: ma - - name: "Assert the created tag: custom-string-token-major" + - name: "Assert the created tag: custom-string-token-major-multiple-commits" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-major.outputs.new_tag }} "3.0.0" - # custom-string-token-minor: - - name: "Create test repo: custom-string-token-minor" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-major-multiple-commits.outputs.new_tag }} "3.0.0" + # custom-string-token-minor-multiple-commits: + - name: "Create test repo: custom-string-token-minor-multiple-commits" shell: bash run: | .github/workflows/tests/custom_string_token.sh - - name: "Create a tag: custom-string-token-minor" - id: create-tag-custom-string-token-minor + - name: "Create a tag: custom-string-token-minor-multiple-commits" + id: create-tag-custom-string-token-minor-multiple-commits uses: ./ env: DRY_RUN: true @@ -107,17 +107,17 @@ jobs: SOURCE: test-repo USE_LAST_COMMIT_ONLY: false MINOR_STRING_TOKEN: mi - - name: "Assert the created tag: custom-string-token-minor" + - name: "Assert the created tag: custom-string-token-minor-multiple-commits" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-minor.outputs.new_tag }} "1.4.0" - # custom-string-token-patch: - - name: "Create test repo: custom-string-token-patch" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-minor-multiple-commits.outputs.new_tag }} "1.4.0" + # custom-string-token-patch-multiple-commits: + - name: "Create test repo: custom-string-token-patch-multiple-commits" shell: bash run: | .github/workflows/tests/custom_string_token.sh - - name: "Create a tag: custom-string-token-patch" - id: create-tag-custom-string-token-patch + - name: "Create a tag: custom-string-token-patch-multiple-commits" + id: create-tag-custom-string-token-patch-multiple-commits uses: ./ env: DRY_RUN: true @@ -126,17 +126,17 @@ jobs: SOURCE: test-repo USE_LAST_COMMIT_ONLY: false PATCH_STRING_TOKEN: pa - - name: "Assert the created tag: custom-string-token-patch" + - name: "Assert the created tag: custom-string-token-patch-multiple-commits" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-patch.outputs.new_tag }} "1.1.2" - # several-commits-default-bump: - - name: "Create test repo: several-commits-default-bump" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-patch-multiple-commits.outputs.new_tag }} "1.1.2" + # sdefault-bump-multiple-commits: + - name: "Create test repo: sdefault-bump-multiple-commits" shell: bash run: | .github/workflows/tests/several_commits_default_bump.sh - - name: "Create a tag: several-commits-default-bump" - id: create-tag-several-commits-default-bump + - name: "Create a tag: sdefault-bump-multiple-commits" + id: create-tag-sdefault-bump-multiple-commits uses: ./ env: DRY_RUN: true @@ -144,17 +144,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo USE_LAST_COMMIT_ONLY: false - - name: "Assert the created tag: several-commits-default-bump" + - name: "Assert the created tag: sdefault-bump-multiple-commits" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-default-bump.outputs.new_tag }} "6.0.0" - # several-commits-mix-tagged-and-not-tagged-commits: - - name: "Create test repo: several-commits-mix-tagged-and-not-tagged-commits" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-sdefault-bump-multiple-commits.outputs.new_tag }} "6.0.0" + # mix-tagged-and-not-tagged-commits-mutliple-commits: + - name: "Create test repo: mix-tagged-and-not-tagged-commits-mutliple-commits" shell: bash run: | .github/workflows/tests/several_mixed_tagged_and_not_tagged_commits.sh - - name: "Create a tag: several-commits-mix-tagged-and-not-tagged-commits" - id: create-tag-several-commits-mix-tagged-and-not-tagged-commits + - name: "Create a tag: mix-tagged-and-not-tagged-commits-mutliple-commits" + id: create-tag-mix-tagged-and-not-tagged-commits-mutliple-commits uses: ./ env: DRY_RUN: true @@ -162,17 +162,17 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo USE_LAST_COMMIT_ONLY: false - - name: "Assert the created tag: several-commits-mix-tagged-and-not-tagged-commits" + - name: "Assert the created tag: mix-tagged-and-not-tagged-commits-mutliple-commits" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-mix-tagged-and-not-tagged-commits.outputs.new_tag }} "1.3.0" - # several-commits-major-takes-precedence-over-patch: - - name: "Create test repo: several-commits-major-takes-precedence-over-patch" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-mix-tagged-and-not-tagged-commits-mutliple-commits.outputs.new_tag }} "1.3.0" + # major-takes-precedence-over-patch-multiple-commits: + - name: "Create test repo: major-takes-precedence-over-patch-multiple-commits" shell: bash run: | .github/workflows/tests/several_commits_major_takes_precedence_over_patch.sh - - name: "Create a tag: several-commits-major-takes-precedence-over-patch" - id: create-tag-several-commits-major-takes-precedence-over-patch + - name: "Create a tag: major-takes-precedence-over-patch-multiple-commits" + id: create-tag-major-takes-precedence-over-patch-multiple-commits uses: ./ env: DRY_RUN: true @@ -183,7 +183,7 @@ jobs: - name: "Assert the created tag: " shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-several-commits-major-takes-precedence-over-patch.outputs.new_tag }} "1.4.0" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-major-takes-precedence-over-patch-multiple-commits.outputs.new_tag }} "1.4.0" # initial-tag-creation: - name: "Create test repo: initial-tag-creation" shell: bash @@ -197,7 +197,6 @@ jobs: DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - USE_LAST_COMMIT_ONLY: true - name: "Assert the created tag: initial-tag-creation" shell: bash run: | @@ -215,7 +214,6 @@ jobs: DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - USE_LAST_COMMIT_ONLY: false - name: "Assert the created tag: initial-tag-creation-do-not-use-last-commit-only" shell: bash run: | From bac2fd1bcb8bc00de489b4cab89f68de09872471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 17:09:41 +0100 Subject: [PATCH 39/63] Add custom-string-token-major-single-commit testcase --- .github/workflows/test.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 82173c97..73a9e359 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -92,6 +92,25 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-major-multiple-commits.outputs.new_tag }} "3.0.0" + # custom-string-token-major-single-commit: + - name: "Create test repo: custom-string-token-major-single-commit" + shell: bash + run: | + .github/workflows/tests/custom_string_token.sh + - name: "Create a tag: custom-string-token-major-single-commit" + id: create-tag-custom-string-token-major-single-commit + uses: ./ + env: + DRY_RUN: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: true + MAJOR_STRING_TOKEN: ma + - name: "Assert the created tag: custom-string-token-major-single-commit" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-major-single-commit.outputs.new_tag }} "2.0.0" # custom-string-token-minor-multiple-commits: - name: "Create test repo: custom-string-token-minor-multiple-commits" shell: bash From f9eeba899135ef72e0842489a105d0bb29da50c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 17:13:52 +0100 Subject: [PATCH 40/63] Add custom-string-token-major-minor-patch-multiple-commits testcase --- .github/workflows/test.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73a9e359..6c429694 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -149,7 +149,28 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-patch-multiple-commits.outputs.new_tag }} "1.1.2" - # sdefault-bump-multiple-commits: + # custom-string-token-major-minor-patch-multiple-commits: + - name: "Create test repo: custom-string-token-major-minor-patch-multiple-commits" + shell: bash + run: | + .github/workflows/tests/custom_string_token.sh + - name: "Create a tag: custom-string-token-major-minor-patch-multiple-commits" + id: custom-string-token-major-minor-patch-multiple-commits + uses: ./ + env: + DRY_RUN: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + MAJOR_STRING_TOKEN: ma + MINOR_STRING_TOKEN: mi + PATCH_STRING_TOKEN: pa + - name: "Assert the created tag: custom-string-token-major-minor-patch-multiple-commits" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.custom-string-token-major-minor-patch-multiple-commits.outputs.new_tag }} "3.0.0" + # default-bump-multiple-commits: - name: "Create test repo: sdefault-bump-multiple-commits" shell: bash run: | From a2a7310db558d952313fdf1f67e23b31865ead28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 23:39:25 +0100 Subject: [PATCH 41/63] Add tests for WITH_V parameter --- .github/workflows/test.yml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c429694..77b66f99 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -333,3 +333,43 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-tag-with-prefix-is-bumped-if-tag-with-given-prefix-already-exists.outputs.new_tag }} "prefix-1.1.2" + # tag-with-v-correct-prefix-is-added: + - name: "Create test repo: tag-with-v-correct-prefix-is-added" + shell: bash + run: | + .github/workflows/tests/initial_tag_creation.sh + - name: "Create a tag: tag-with-v-correct-prefix-is-added" + id: create-tag-tag-with-v-correct-prefix-is-added + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + INITIAL_VERSION: 1.0.0 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + # PREFIX: prefix- + WITH_V: true + - name: "Assert the created tag: tag-with-v-correct-prefix-is-added" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-tag-with-v-correct-prefix-is-added.outputs.new_tag }} "v1.0.0" + # tag-with-v-is-ignored-if-prefix-is-also-specified: + - name: "Create test repo: tag-with-v-is-ignored-if-prefix-is-also-specified" + shell: bash + run: | + .github/workflows/tests/initial_tag_creation.sh + - name: "Create a tag: tag-with-v-is-ignored-if-prefix-is-also-specified" + id: create-tag-tag-with-v-is-ignored-if-prefix-is-also-specified + uses: ./ + env: + DRY_RUN: true + VERBOSE: true + INITIAL_VERSION: 1.0.0 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + PREFIX: prefix- + WITH_V: true + - name: "Assert the created tag: tag-with-v-is-ignored-if-prefix-is-also-specified" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-tag-with-v-is-ignored-if-prefix-is-also-specified.outputs.new_tag }} "prefix-1.0.0" From 8bd3fd4fe12386ade620904e348d990e75c8508c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 23:39:45 +0100 Subject: [PATCH 42/63] Rename test to be more descriptive --- .github/workflows/test.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77b66f99..59246149 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -241,23 +241,24 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation.outputs.new_tag }} "0.0.0" - # initial-tag-creation-do-not-use-last-commit-only: - - name: "Create test repo: initial-tag-creation-do-not-use-last-commit-only" + # initial-tag-creation-sets-tag-to-initial-version-even-if-multiple-commits-used: + - name: "Create test repo: initial-tag-creation-sets-tag-to-initial-version-even-if-multiple-commits-used" shell: bash run: | .github/workflows/tests/initial_tag_creation.sh - - name: "Create a tag: initial-tag-creation-do-not-use-last-commit-only" - id: create-tag-initial-tag-creation-do-not-use-last-commit-only + - name: "Create a tag: initial-tag-creation-sets-tag-to-initial-version-even-if-multiple-commits-used" + id: create-tag-initial-tag-creation-sets-tag-to-initial-version-even-if-multiple-commits-used uses: ./ env: DRY_RUN: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - - name: "Assert the created tag: initial-tag-creation-do-not-use-last-commit-only" + USE_LAST_COMMIT_ONLY: false + - name: "Assert the created tag: initial-tag-creation-sets-tag-to-initial-version-even-if-multiple-commits-used" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-do-not-use-last-commit-only.outputs.new_tag }} "0.0.0" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-initial-tag-creation-sets-tag-to-initial-version-even-if-multiple-commits-used.outputs.new_tag }} "0.0.0" # initial-tag-creation-with-initial-version: - name: "Create test repo: initial-tag-creation-with-initial-version" shell: bash From 4b1ba1e49881ded3127bd12c6ff065fa409efd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 23:40:42 +0100 Subject: [PATCH 43/63] Remove verbose: true flags from tests --- .github/workflows/test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59246149..e16c336f 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -306,7 +306,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: major GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -325,7 +324,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true DEFAULT_BUMP: patch GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -344,7 +342,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true INITIAL_VERSION: 1.0.0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo @@ -364,7 +361,6 @@ jobs: uses: ./ env: DRY_RUN: true - VERBOSE: true INITIAL_VERSION: 1.0.0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo From c660f7c520c7e921c0024fa1e23a3466449e6c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 23:45:15 +0100 Subject: [PATCH 44/63] Add custom-tag-overrides-all-calculated-tags test --- .github/workflows/test.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e16c336f..bbc98355 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -92,6 +92,26 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-string-token-major-multiple-commits.outputs.new_tag }} "3.0.0" + # custom-tag-overrides-all-calculated-tags: + - name: "Create test repo: custom-tag-overrides-all-calculated-tags" + shell: bash + run: | + .github/workflows/tests/custom_string_token.sh + - name: "Create a tag: custom-tag-overrides-all-calculated-tags" + id: create-tag-custom-tag-overrides-all-calculated-tags + uses: ./ + env: + DRY_RUN: true + DEFAULT_BUMP: major + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + MAJOR_STRING_TOKEN: ma + CUSTOM_TAG: xyz + - name: "Assert the created tag: custom-tag-overrides-all-calculated-tags" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-custom-tag-overrides-all-calculated-tags.outputs.new_tag }} "xyz" # custom-string-token-major-single-commit: - name: "Create test repo: custom-string-token-major-single-commit" shell: bash From d2f1ce363aaf0fb7454d5bc65f83e97aae5f3f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Sun, 8 Jan 2023 23:45:50 +0100 Subject: [PATCH 45/63] Update readme with information about correct format of INITIAL_VERSION parameter --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 833bcc60..08c47445 100755 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ _NOTE: set the fetch-depth for `actions/checkout@v2` or newer to be sure you ret - **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!** - **SOURCE** *(optional)* - Operate on a relative path under $GITHUB_WORKSPACE. - **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). -- **INITIAL_VERSION** *(optional)* - Set initial version before bump. Default `0.0.0`. +- **INITIAL_VERSION** *(optional)* - Set initial version before bump. Default `0.0.0`. It must be in a valid semver version format (optionally it can also be prefixed with PREFIX param, but it's not necessary even if PREFIX is specified). If the format is incorrect error is thrown. - **TAG_CONTEXT** *(optional)* - Set the context of the previous tag. Possible values are `repo` (default) or `branch`. - **PRERELEASE** _(optional)_ - Define if workflow runs in prerelease mode, `false` by default. Note this will be overwritten if using complex suffix release branches. - **PRERELEASE_SUFFIX** *(optional)* - Suffix for your prerelease versions, `beta` by default. Note this will only be used if a prerelease branch. From 66e31fa00091c51d6f9b9031f6f6a2c402c523c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Tue, 10 Jan 2023 23:49:28 +0100 Subject: [PATCH 46/63] Add merge-branch-no-new-tags-on-master-since-branching-off-merge-commit test --- .github/workflows/test.yml | 19 ++++++++++++++ ...mmit_no_new_tags_on_master_merge_commit.sh | 26 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 .github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bbc98355..76584c75 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -390,3 +390,22 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-tag-with-v-is-ignored-if-prefix-is-also-specified.outputs.new_tag }} "prefix-1.0.0" + # merge-branch-no-new-tags-on-master-since-branching-off-merge-commit: + - name: "Create test repo: merge-branch-no-new-tags-on-master-since-branching-off-merge-commit" + id: create-test-repo-merge-branch-no-new-tags-on-master-since-branching-off-merge-commit + shell: bash + run: | + .github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh + - name: "Create a tag: merge-branch-no-new-tags-on-master-since-branching-off-merge-commit" + id: create-tag-merge-branch-no-new-tags-on-master-since-branching-off-merge-commit + uses: ./ + env: + DRY_RUN: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + BRANCH_LATEST_COMMIT: ${{ steps.create-test-repo-merge-branch-no-new-tags-on-master-since-branching-off-merge-commit.outputs.LATEST_FEATURE_BRANCH_COMMIT_SHA }} + - name: "Assert the created tag: merge-branch-no-new-tags-on-master-since-branching-off-merge-commit" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-merge-branch-no-new-tags-on-master-since-branching-off-merge-commit.outputs.new_tag }} "1.3.0" diff --git a/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh new file mode 100755 index 00000000..f60f60ee --- /dev/null +++ b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1_master.txt" +touch 2.txt && git add . && git commit -m "2_master.txt" +git tag 1.1.1 + +git checkout -b my-feature-branch +touch 3_feautre.txt && git add . && git commit -m "#minor 3_feature.txt" +touch 4_feautre.txt && git add . && git commit -m "4_feature.txt" +touch 5_feautre.txt && git add . && git commit -m "#minor 5_feature.txt" +echo "LATEST_FEATURE_BRANCH_COMMIT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + +git checkout master +touch 6.txt && git add . && git commit -m "#minor 6_master.txt" +touch 7.txt && git add . && git commit -m "#minor 7_master.txt" +git merge my-feature-branch --no-edit + +git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit From 1a092e8b9f8fc1880d8c592a3e21d628f5df12de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:05:46 +0100 Subject: [PATCH 47/63] Add merge-branch-new-tag-on-master-since-branching-off-merge-commit test --- .github/workflows/test.yml | 19 +++++++++++++ ...t_commit_new_tag_on_master_merge_commit.sh | 27 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 .github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76584c75..8e22c571 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -409,3 +409,22 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-merge-branch-no-new-tags-on-master-since-branching-off-merge-commit.outputs.new_tag }} "1.3.0" + # merge-branch-new-tag-on-master-since-branching-off-merge-commit: + - name: "Create test repo: merge-branch-new-tag-on-master-since-branching-off-merge-commit" + id: create-test-repo-merge-branch-new-tag-on-master-since-branching-off-merge-commit + shell: bash + run: | + .github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh + - name: "Create a tag: merge-branch-new-tag-on-master-since-branching-off-merge-commit" + id: create-tag-merge-branch-new-tag-on-master-since-branching-off-merge-commit + uses: ./ + env: + DRY_RUN: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + BRANCH_LATEST_COMMIT: ${{ steps.create-test-repo-merge-branch-new-tag-on-master-since-branching-off-merge-commit.outputs.LATEST_FEATURE_BRANCH_COMMIT_SHA }} + - name: "Assert the created tag: merge-branch-new-tag-on-master-since-branching-off-merge-commit" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-merge-branch-new-tag-on-master-since-branching-off-merge-commit.outputs.new_tag }} "2.5.0" diff --git a/.github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh new file mode 100755 index 00000000..6d6c0d0a --- /dev/null +++ b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1_master.txt" +touch 2.txt && git add . && git commit -m "2_master.txt" +git tag 1.1.1 + +git checkout -b my-feature-branch +touch 3_feautre.txt && git add . && git commit -m "#minor 3_feature.txt" +touch 4_feautre.txt && git add . && git commit -m "4_feature.txt" +touch 5_feautre.txt && git add . && git commit -m "#minor 5_feature.txt" +echo "LATEST_FEATURE_BRANCH_COMMIT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + +git checkout master +touch 6.txt && git add . && git commit -m "#minor 6_master.txt" +touch 7.txt && git add . && git commit -m "#minor 7_master.txt" +git tag 2.3.4 +git merge my-feature-branch --no-edit + +git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit From e9be94773697295e66108bf950977b7351cd4447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:17:15 +0100 Subject: [PATCH 48/63] Add merge-branch-no-new-tags-on-master-since-branching-off-fast-forward test --- .github/workflows/test.yml | 19 ++++++++++++ ...mmit_no_new_tags_on_master_fast_forward.sh | 30 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 .github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e22c571..04762ce6 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -428,3 +428,22 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-merge-branch-new-tag-on-master-since-branching-off-merge-commit.outputs.new_tag }} "2.5.0" + # merge-branch-no-new-tags-on-master-since-branching-off-fast-forward: + - name: "Create test repo: merge-branch-no-new-tags-on-master-since-branching-off-fast-forward" + id: create-test-repo-merge-branch-no-new-tags-on-master-since-branching-off-fast-forward + shell: bash + run: | + .github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh + - name: "Create a tag: merge-branch-no-new-tags-on-master-since-branching-off-fast-forward" + id: create-tag-merge-branch-no-new-tags-on-master-since-branching-off-fast-forward + uses: ./ + env: + DRY_RUN: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + BRANCH_LATEST_COMMIT: ${{ steps.create-test-repo-merge-branch-no-new-tags-on-master-since-branching-off-fast-forward.outputs.LATEST_FEATURE_BRANCH_COMMIT_SHA }} + - name: "Assert the created tag: merge-branch-no-new-tags-on-master-since-branching-off-fast-forward" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-merge-branch-no-new-tags-on-master-since-branching-off-fast-forward.outputs.new_tag }} "1.3.0" diff --git a/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh new file mode 100755 index 00000000..cba9fc17 --- /dev/null +++ b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1_master.txt" +touch 2.txt && git add . && git commit -m "2_master.txt" +git tag 1.1.1 + +git checkout -b my-feature-branch +touch 3_feautre.txt && git add . && git commit -m "#minor 3_feature.txt" +touch 4_feautre.txt && git add . && git commit -m "4_feature.txt" +touch 5_feautre.txt && git add . && git commit -m "#minor 5_feature.txt" +echo "LATEST_FEATURE_BRANCH_COMMIT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + +git checkout master +touch 6.txt && git add . && git commit -m "#minor 6_master.txt" +touch 7.txt && git add . && git commit -m "#minor 7_master.txt" + +git checkout my-feature-branch +git rebase master + +git merge my-feature-branch --no-edit --ff-only + +git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit From 8048bb9afdf721926b4f03c86ced28ed0ee4cb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:22:21 +0100 Subject: [PATCH 49/63] Add merge-branch-new-tag-on-master-since-branching-off-fast-forward test --- .github/workflows/test.yml | 19 ++++++++++++ ...t_commit_new_tag_on_master_fast_forward.sh | 31 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 .github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 04762ce6..1c5a8d22 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -447,3 +447,22 @@ jobs: shell: bash run: | .github/workflows/tests/_assert.sh ${{ steps.create-tag-merge-branch-no-new-tags-on-master-since-branching-off-fast-forward.outputs.new_tag }} "1.3.0" + # merge-branch-new-tag-on-master-since-branching-off-fast-forward: + - name: "Create test repo: merge-branch-new-tag-on-master-since-branching-off-fast-forward" + id: create-test-repo-merge-branch-new-tag-on-master-since-branching-off-fast-forward + shell: bash + run: | + .github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh + - name: "Create a tag: merge-branch-new-tag-on-master-since-branching-off-fast-forward" + id: create-tag-merge-branch-new-tag-on-master-since-branching-off-fast-forward + uses: ./ + env: + DRY_RUN: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE: test-repo + USE_LAST_COMMIT_ONLY: false + BRANCH_LATEST_COMMIT: ${{ steps.create-test-repo-merge-branch-new-tag-on-master-since-branching-off-fast-forward.outputs.LATEST_FEATURE_BRANCH_COMMIT_SHA }} + - name: "Assert the created tag: merge-branch-new-tag-on-master-since-branching-off-fast-forward" + shell: bash + run: | + .github/workflows/tests/_assert.sh ${{ steps.create-tag-merge-branch-new-tag-on-master-since-branching-off-fast-forward.outputs.new_tag }} "2.5.0" diff --git a/.github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh new file mode 100755 index 00000000..3c965950 --- /dev/null +++ b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +mkdir test-repo +cd test-repo || exit 1 + +git config --global init.defaultBranch master +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + +git init +touch 1.txt && git add . && git commit -m "1_master.txt" +touch 2.txt && git add . && git commit -m "2_master.txt" +git tag 1.1.1 + +git checkout -b my-feature-branch +touch 3_feautre.txt && git add . && git commit -m "#minor 3_feature.txt" +touch 4_feautre.txt && git add . && git commit -m "4_feature.txt" +touch 5_feautre.txt && git add . && git commit -m "#minor 5_feature.txt" +echo "LATEST_FEATURE_BRANCH_COMMIT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + +git checkout master +touch 6.txt && git add . && git commit -m "#minor 6_master.txt" +touch 7.txt && git add . && git commit -m "#minor 7_master.txt" +git tag 2.3.4 + +git checkout my-feature-branch +git rebase master + +git merge my-feature-branch --no-edit --ff-only + +git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit From ad6f1896271d9d7313474c825bbfed5c0bfa2ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:24:09 +0100 Subject: [PATCH 50/63] Remove git logs from bash scripts --- .../branch_latest_commit_new_tag_on_master_fast_forward.sh | 4 +--- .../branch_latest_commit_new_tag_on_master_merge_commit.sh | 4 +--- ...branch_latest_commit_no_new_tags_on_master_fast_forward.sh | 4 +--- ...branch_latest_commit_no_new_tags_on_master_merge_commit.sh | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh index 3c965950..b1a8e49a 100755 --- a/.github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh +++ b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_fast_forward.sh @@ -26,6 +26,4 @@ git tag 2.3.4 git checkout my-feature-branch git rebase master -git merge my-feature-branch --no-edit --ff-only - -git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit +git merge my-feature-branch --no-edit --ff-only \ No newline at end of file diff --git a/.github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh index 6d6c0d0a..8cdf3291 100755 --- a/.github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh +++ b/.github/workflows/tests/branch_latest_commit_new_tag_on_master_merge_commit.sh @@ -22,6 +22,4 @@ git checkout master touch 6.txt && git add . && git commit -m "#minor 6_master.txt" touch 7.txt && git add . && git commit -m "#minor 7_master.txt" git tag 2.3.4 -git merge my-feature-branch --no-edit - -git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit +git merge my-feature-branch --no-edit \ No newline at end of file diff --git a/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh index cba9fc17..565d5e31 100755 --- a/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh +++ b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_fast_forward.sh @@ -25,6 +25,4 @@ touch 7.txt && git add . && git commit -m "#minor 7_master.txt" git checkout my-feature-branch git rebase master -git merge my-feature-branch --no-edit --ff-only - -git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit +git merge my-feature-branch --no-edit --ff-only \ No newline at end of file diff --git a/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh index f60f60ee..3cf663a8 100755 --- a/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh +++ b/.github/workflows/tests/branch_latest_commit_no_new_tags_on_master_merge_commit.sh @@ -21,6 +21,4 @@ echo "LATEST_FEATURE_BRANCH_COMMIT_SHA=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT git checkout master touch 6.txt && git add . && git commit -m "#minor 6_master.txt" touch 7.txt && git add . && git commit -m "#minor 7_master.txt" -git merge my-feature-branch --no-edit - -git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit +git merge my-feature-branch --no-edit \ No newline at end of file From 29b81f0cb8482a87d6c01c3351a503d73016c578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:33:54 +0100 Subject: [PATCH 51/63] Pipeline debug --- .github/workflows/tests/_assert.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests/_assert.sh b/.github/workflows/tests/_assert.sh index bbb9a078..74631c9f 100755 --- a/.github/workflows/tests/_assert.sh +++ b/.github/workflows/tests/_assert.sh @@ -9,5 +9,5 @@ if [[ $OUTPUT_NEWTAG == "${CORRECT_TAG}" ]]; then else echo "The tag was not created correctly, expected $CORRECT_TAG got $OUTPUT_NEWTAG" >>"$GITHUB_STEP_SUMMARY" rm -rf test-repo - exit 1 + exit 123 fi From eabf0cb8a0a17e3f24020433ea6b6b21ea89f87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:37:30 +0100 Subject: [PATCH 52/63] Remove quotes from assert script param to test if pipeline succeeds --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c5a8d22..f533b541 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: - name: "Assert the created tag: default-bump-undefined" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-undefined.outputs.new_tag }} "1.2.0" + .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-undefined.outputs.new_tag }} 1.2.0 # default-bump-set-to-patch - name: "Create test repo: default-bump-set-to-patch" shell: bash From 7995bc250268dbc8a93d6d1b65ef0f0530126dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:39:11 +0100 Subject: [PATCH 53/63] Unify style in 'if' condition --- .github/workflows/tests/_assert.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests/_assert.sh b/.github/workflows/tests/_assert.sh index 74631c9f..45069d65 100755 --- a/.github/workflows/tests/_assert.sh +++ b/.github/workflows/tests/_assert.sh @@ -3,11 +3,11 @@ OUTPUT_NEWTAG=$1 CORRECT_TAG=$2 -if [[ $OUTPUT_NEWTAG == "${CORRECT_TAG}" ]]; then +if [[ "${OUTPUT_NEWTAG}" == "${CORRECT_TAG}" ]]; then echo "The tag was created correctly" >>"$GITHUB_STEP_SUMMARY" rm -rf test-repo else echo "The tag was not created correctly, expected $CORRECT_TAG got $OUTPUT_NEWTAG" >>"$GITHUB_STEP_SUMMARY" rm -rf test-repo - exit 123 + exit 1 fi From a734b874c7243e9ee1c7f844c427e74bb8c4166f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 00:41:09 +0100 Subject: [PATCH 54/63] Add quotes --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f533b541..821d5750 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: - name: "Assert the created tag: default-bump-undefined" shell: bash run: | - .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-undefined.outputs.new_tag }} 1.2.0 + .github/workflows/tests/_assert.sh "${{ steps.create-tag-default-bump-undefined.outputs.new_tag }}" 1.2.0 # default-bump-set-to-patch - name: "Create test repo: default-bump-set-to-patch" shell: bash From 27a50533d1df39b1996227aec50dc2c73bb60a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 01:06:07 +0100 Subject: [PATCH 55/63] Get rid of deprecated set-output and use $GITHUB_OUTPUT --- entrypoint.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b7a34747..1a922cc6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -207,11 +207,11 @@ if [ -n "$custom_tag" ]; then echo -e "\tPrefix: $prefix" echo -e "\tPart incremented: [none - custom tag was created]\n\n" - echo ::set-output name=new_tag_without_prefix::"$newCustomTagWithoutPrefix" - echo ::set-output name=new_tag::"$newCustomTag" + echo "new_tag_without_prefix=$newCustomTagWithoutPrefix" >> "$GITHUB_OUTPUT" + echo "new_tag=$newCustomTag" >> "$GITHUB_OUTPUT" # set the old tag value as an output - echo ::set-output name=tag::"$tag" + echo "tag=$tag" >> "$GITHUB_OUTPUT" push_new_tag_if_not_dry_run "$newCustomTag" fi @@ -269,8 +269,8 @@ commit=$(git rev-parse HEAD) if [ "$tag_commit" == "$commit" ]; then echo "No new commits since previous tag. Skipping..." - echo "::set-output name=new_tag::$tag" - echo "::set-output name=tag::$tag" + echo "new_tag=$tag" >> "$GITHUB_OUTPUT" + echo "tag=$tag" >> "$GITHUB_OUTPUT" exit 0 fi @@ -391,15 +391,15 @@ echo -e "\tNew tag: $new" echo -e "\tPrefix: $prefix" echo -e "\tPart incremented: $part\n\n" -echo "::set-output name=new_tag::$new" -echo "::set-output name=new_tag_without_prefix::$new_tag_without_prefix" -echo "::set-output name=part::$part" -echo "::set-output name=tag::$new" # this needs to go in v2 is breaking change -echo "::set-output name=old_tag::$tag" +echo "new_tag=$new" >> "$GITHUB_OUTPUT" +echo "new_tag_without_prefix=$new_tag_without_prefix" >> "$GITHUB_OUTPUT" +echo "part=$part" >> "$GITHUB_OUTPUT" +echo "tag=$new" >> "$GITHUB_OUTPUT" # this needs to go in v2 is breaking change +echo "old_tag=$tag" >> "$GITHUB_OUTPUT" # use dry run to determine the next tag if $dryrun; then - echo "::set-output name=tag::$tag" + echo "tag=$tag" >> "$GITHUB_OUTPUT" exit 0 fi From ca8e54d250a9b0289dbb0f908aa27fb521a10f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 02:08:31 +0100 Subject: [PATCH 56/63] Change docker base image to fix 'detected dubious ownership in repository' git error --- .github/workflows/test.yml | 2 +- Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 821d5750..1c5a8d22 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: - name: "Assert the created tag: default-bump-undefined" shell: bash run: | - .github/workflows/tests/_assert.sh "${{ steps.create-tag-default-bump-undefined.outputs.new_tag }}" 1.2.0 + .github/workflows/tests/_assert.sh ${{ steps.create-tag-default-bump-undefined.outputs.new_tag }} "1.2.0" # default-bump-set-to-patch - name: "Create test repo: default-bump-set-to-patch" shell: bash diff --git a/Dockerfile b/Dockerfile index b64fc5be..3f45af04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -FROM node:16-alpine +FROM node:16-bullseye-slim LABEL "repository"="https://github.com/anothrNick/github-tag-action" LABEL "homepage"="https://github.com/anothrNick/github-tag-action" LABEL "maintainer"="Nick Sjostrom" -RUN apk --no-cache add bash git curl jq && npm install -g semver +RUN apt-get update -y && apt-get install bash git curl jq -y && apt-get clean && npm install -g semver COPY entrypoint.sh /entrypoint.sh From 19ea1fe5869e70370c3fcd0f15a08e33155b200b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 10:17:55 +0100 Subject: [PATCH 57/63] Restore commented out code --- entrypoint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1a922cc6..229efeb8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -50,10 +50,10 @@ echo -e "\tNONE_STRING_TOKEN: ${none_string_token}" echo -e "******************************************\n" # verbose, show everything -# if $verbose TODO: restore -# then -# set -x -# fi +if $verbose +then + set -x +fi push_new_tag_if_not_dry_run() { From 62cbc92cd8f8e32fe01d0d6c9b87a77fbd4da450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 10:23:52 +0100 Subject: [PATCH 58/63] Disable schellcheck 2129 as it would break the logic --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 229efeb8..80d38f01 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/bash -# shellcheck disable=SC2153,2164 +# shellcheck disable=SC2153,2164,2129 set -o pipefail From 22353ab2b4dd96d9087154e7525b321deff1861e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 10:40:05 +0100 Subject: [PATCH 59/63] Remove dokcerfile warnings --- Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3f45af04..53d196c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,11 @@ LABEL "repository"="https://github.com/anothrNick/github-tag-action" LABEL "homepage"="https://github.com/anothrNick/github-tag-action" LABEL "maintainer"="Nick Sjostrom" -RUN apt-get update -y && apt-get install bash git curl jq -y && apt-get clean && npm install -g semver +RUN apt-get update -y \ + && apt-get install bash=5.1-2+deb11u1 git=1:2.30.2-1 curl=7.74.0-1.3+deb11u3 jq=1.6-2.1 --no-install-recommends -y \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && npm install -g semver COPY entrypoint.sh /entrypoint.sh From 8cdc515abe92a44289e4f28d4ebea3b5fa2a1e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 12:14:04 +0100 Subject: [PATCH 60/63] Use setOutput function --- entrypoint.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index dc91de51..d9d3e04f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -214,11 +214,11 @@ if [ -n "$custom_tag" ]; then echo -e "\tPrefix: $prefix" echo -e "\tPart incremented: [none - custom tag was created]\n\n" - echo "new_tag_without_prefix=$newCustomTagWithoutPrefix" >> "$GITHUB_OUTPUT" - echo "new_tag=$newCustomTag" >> "$GITHUB_OUTPUT" + setOutput new_tag_without_prefix "$newCustomTagWithoutPrefix" + setOutput new_tag "$newCustomTag" # set the old tag value as an output - echo "tag=$tag" >> "$GITHUB_OUTPUT" + setOutput tag "$tag" push_new_tag_if_not_dry_run "$newCustomTag" fi @@ -437,15 +437,15 @@ echo -e "\tNew tag: $new" echo -e "\tPrefix: $prefix" echo -e "\tPart incremented: $part\n\n" -echo "new_tag=$new" >> "$GITHUB_OUTPUT" -echo "new_tag_without_prefix=$new_tag_without_prefix" >> "$GITHUB_OUTPUT" -echo "part=$part" >> "$GITHUB_OUTPUT" -echo "tag=$new" >> "$GITHUB_OUTPUT" # this needs to go in v2 is breaking change -echo "old_tag=$tag" >> "$GITHUB_OUTPUT" +setOutput new_tag "$new" +setOutput new_tag_without_prefix "$new_tag_without_prefix" +setOutput part "$part" +setOutput tag "$new" # this needs to go in v2 is breaking change +setOutput old_tag "$tag" # use dry run to determine the next tag if $dryrun; then - echo "tag=$tag" >> "$GITHUB_OUTPUT" + setOutput tag "$tag" exit 0 fi From 7313ae63625cf7e76d351076b3435c0757a18fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 12:16:34 +0100 Subject: [PATCH 61/63] Removed redundant line --- entrypoint.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index d9d3e04f..110fabca 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -153,7 +153,6 @@ bump_version() { for ((c = 1; c <= count; c++)); do new=$(semver -i "$1" "$new") - part=$1 # TODO: Is this line needed? done } From a3563cb27f108a7997dac3581fb0fb8105630c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 12:38:40 +0100 Subject: [PATCH 62/63] Remove commented out parameter from test --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c5a8d22..b44e7452 100755 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -365,7 +365,6 @@ jobs: INITIAL_VERSION: 1.0.0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SOURCE: test-repo - # PREFIX: prefix- WITH_V: true - name: "Assert the created tag: tag-with-v-correct-prefix-is-added" shell: bash From 9c268789116797bec8d171907107ea886422c62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Sypniewski?= Date: Wed, 11 Jan 2023 14:59:43 +0100 Subject: [PATCH 63/63] Revert change from 7313ae6 as it is needed to output 'part' in some cases --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 110fabca..d5e545b8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -153,6 +153,7 @@ bump_version() { for ((c = 1; c <= count; c++)); do new=$(semver -i "$1" "$new") + part=$1 done }