Skip to content

Commit

Permalink
needed ability to set the release type without using commit comments (#…
Browse files Browse the repository at this point in the history
…14)

* added release type option

* changed location of pompath for subdirectories

* Update README.md

added feature for type
  • Loading branch information
radicaldrew authored Jan 27, 2024
1 parent 0c2fc90 commit 1ecfed4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ A simple GitHub Actions to bump the version of Maven projects.
When triggered, this action will look at the commit message of HEAD~1 and determine if it contains one of `#major`, `#minor`, or `#patch` (in that order of precedence).
If true, it will use Maven to bump your pom's version.

You can override this default behavior by setting a release type, setting type will override the above commit message check.

For example, a `#minor` update to version `1.3.9` will result in the version changing to `1.4.0`.
The change will then be committed.

Expand Down Expand Up @@ -39,6 +41,7 @@ jobs:
* `github-token`: The only required argument. Can either be the default token, as seen above, or a personal access token with write access to the repository
* `git-email`: The email address each commit should be associated with. Defaults to a github provided noreply address
* `git-username`: The GitHub username each commit should be associated with. Defaults to `github-actions[bot]`
* `type`: This will overide the release type this can be minor, patch or major. if not set will use comments.
* `pom-path`: The path within your directory the pom.xml you intended to change is located.

## Outputs
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
description: 'The relative location of your pom.xml file'
required: true
default: '.'
type:
description: 'The type of release patch,major, or minor'
required: false
default: ''
git-email:
description: 'The email address used to create the version bump commit with.'
required: true
Expand All @@ -39,6 +43,7 @@ runs:
EMAIL: ${{ inputs.git-email }}
NAME: ${{ inputs.git-username }}
POMPATH: ${{ inputs.pom-path }}
TYPE: ${{ inputs.type }}
run: ${{github.action_path}}/version-bump.sh
shell: bash
- name: Set outputs
Expand Down
27 changes: 21 additions & 6 deletions version-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,40 @@ git config --global user.email $EMAIL
git config --global user.name $NAME

OLD_VERSION=$($DIR/get-version.sh)

BUMP_MODE="none"
if git log -1 | grep -q "#major"; then

if [[ "${TYPE}" == "" ]]
then
if git log -1 | grep -q "#major"; then
BUMP_MODE="major"
elif git log -1 | grep -q "#minor"; then
elif git log -1 | grep -q "#minor"; then
BUMP_MODE="minor"
elif git log -1 | grep -q "#patch"; then
elif git log -1 | grep -q "#patch"; then
BUMP_MODE="patch"
fi
else
case "$TYPE" in
major)
BUMP_MODE="major"
;;
minor)
BUMP_MODE="minor"
;;
patch)
BUMP_MODE="patch"
;;
esac
fi

if [[ "${BUMP_MODE}" == "none" ]]
then
echo "No matching commit tags found."
echo "No matching commit tags found or no release type set."
echo "pom.xml at" $POMPATH "will remain at" $OLD_VERSION
else
echo $BUMP_MODE "version bump detected"
bump $BUMP_MODE $OLD_VERSION
echo "pom.xml at" $POMPATH "will be bumped from" $OLD_VERSION "to" $NEW_VERSION
mvn -q versions:set -DnewVersion="${NEW_VERSION}"
mvn --file $POMPATH/pom.xml -q versions:set -DnewVersion="${NEW_VERSION}"
git add $POMPATH/pom.xml
REPO="https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git"
git commit -m "Bump pom.xml from $OLD_VERSION to $NEW_VERSION"
Expand Down

0 comments on commit 1ecfed4

Please sign in to comment.