Skip to content

Commit

Permalink
Merge pull request #58 from endrjuskr/master
Browse files Browse the repository at this point in the history
Add initial version parameter and output part which was bumped
  • Loading branch information
anothrNick committed May 5, 2020
2 parents 48e7710 + 6ee44aa commit 9d0290c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -45,11 +45,13 @@ _NOTE: set the fetch-depth for `actions/checkout@master` to be sure you retrieve
* **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`.

#### 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.

> ***Note:*** This action creates a [lightweight tag](https://developer.github.com/v3/git/refs/#create-a-reference).
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Expand Up @@ -9,6 +9,8 @@ outputs:
description: 'Generated tag'
tag:
description: 'The latest tag after running this action'
part:
description: 'The part of version which was bumped'
branding:
icon: 'git-merge'
color: 'purple'
16 changes: 10 additions & 6 deletions entrypoint.sh
Expand Up @@ -7,6 +7,7 @@ release_branches=${RELEASE_BRANCHES:-master}
custom_tag=${CUSTOM_TAG}
source=${SOURCE:-.}
dryrun=${DRY_RUN:-false}
initial_version=${INITIAL_VERSION:-0.0.0}

cd ${GITHUB_WORKSPACE}/${source}

Expand Down Expand Up @@ -39,11 +40,11 @@ if [ "$tag_commit" == "$commit" ]; then
exit 0
fi

# if there are none, start tags at 0.0.0
# 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=0.0.0
tag="$initial_version"
else
log=$(git log $tag..HEAD --pretty='%B')
fi
Expand All @@ -53,12 +54,14 @@ echo $log
# get commit logs and determine home to bump the version
# supports #major, #minor, #patch (anything else will be 'minor')
case "$log" in
*#major* ) new=$(semver bump major $tag);;
*#minor* ) new=$(semver bump minor $tag);;
*#patch* ) new=$(semver bump patch $tag);;
* ) new=$(semver bump `echo $default_semvar_bump` $tag);;
*#major* ) new=$(semver bump major $tag); part="major";;
*#minor* ) new=$(semver bump minor $tag); part="minor";;
*#patch* ) new=$(semver bump patch $tag); part="patch";;
* ) new=$(semver bump `echo $default_semvar_bump` $tag); part=$default_semvar_bump;;
esac

echo $part

# did we get a new tag?
if [ ! -z "$new" ]
then
Expand All @@ -83,6 +86,7 @@ echo $new

# set outputs
echo ::set-output name=new_tag::$new
echo ::set-output name=part::$part

# use dry run to determine the next tag
if $dryrun
Expand Down

0 comments on commit 9d0290c

Please sign in to comment.