Skip to content

Commit

Permalink
Added automatic maven version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigerpanzer02 committed Jun 16, 2021
1 parent 60dc7c6 commit 246363b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v4 - 06/16/2021
- Added skip to this action, insert [SKIP BUMP] on commit head (Changeable input commit-skip)
- Added value to check if version got bumped (output `bumped`)
- Added inputs auto-version-bump, auto-version-bump-suffix, auto-version-bump-higher, auto-version-bump-splitter, auto-version-bump-release
This will automatically bumps version on trigger, additionally with suffix for example 1.0.0-dev1, 1.0.0-dev2
- !Readme update outstanding!

## v3 - 04/10/2021

- Add `version` output
Expand Down
54 changes: 51 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Maven Version Bump Action
description: A simple GitHub Actions to bump the version of Maven projects

author: Nick Nichols
author: Plugily Projects and Nick Nichols

branding:
color: purple
Expand All @@ -24,30 +24,78 @@ inputs:
description: 'The name to use for the version bump commit. e.g. github.actor'
required: true
default: github-actions[bot]
commit-skip:
description: 'Skip this whole action when some phrase is on the commit'
required: true
default: '[SKIP BUMP]'
auto-version-bump:
description: 'Should we bump the version on every commit?'
required: true
default: true
auto-version-bump-splitter:
description: 'Version splitter for auto bump'
required: true
default: '-'
auto-version-bump-suffix:
description: 'Version suffix for auto bump'
required: true
default: 'dev'
auto-version-bump-higher:
description: 'Should after the suffix a number bumped?'
required: true
default: true
auto-version-bump-release:
description: 'Should on a automatic bump a tag and release created?'
required: true
default: false

outputs:
version:
description: 'The current version (whether updated or not)'
value: ${{ steps.get-outputs.outputs.version }}
before-version:
description: 'The version before running this github action'
value: ${{ steps.get-before-version.outputs.before-version }}
bumped:
description: 'If version got bumped (true/false)'
value: ${{ steps.get-outputs.outputs.bumped }}

runs:
using: "composite"
if: "!contains(github.event.head_commit.message, ${{ inputs.commit-skip }})"
steps:
- name: Output before version
id: get-before-version
shell: bash
env:
POMPATH: ${{ inputs.pom-path }}
run: echo "::set-output name=before-version::$(${{github.action_path}}/get-version.sh)"

- name: Bump Version
env:
TOKEN: ${{ inputs.github-token }}
EMAIL: ${{ inputs.git-email }}
NAME: ${{ inputs.git-username }}
POMPATH: ${{ inputs.pom-path }}
AUTO: ${{ inputs.auto-version-bump }}
AUTO_SPLITTER: ${{ inputs.auto-version-bump-splitter }}
AUTO_SUFFIX: ${{ inputs.auto-version-bump-suffix }}
AUTO_HIGHER: ${{ inputs.auto-version-bump-higher }}
AUTO_RELEASE: ${{ inputs.auto-version-bump-release }}
run: ${{github.action_path}}/version-bump.sh
shell: bash

- name: Set outputs
id: get-outputs
shell: bash
env:
POMPATH: ${{ inputs.pom-path }}
run: echo "::set-output name=version::$(${{github.action_path}}/get-version.sh)"
BEFORE_VERSION: ${{ steps.get-outputs.outputs.version }}
run: |
echo "::set-output name=version::$(${{github.action_path}}/get-version.sh)"
echo "::set-output name=bumped::$(${{github.action_path}}/bumped.sh)"
- name: Result
shell: bash
run: "echo 'Version is now ${{ steps.get-outputs.outputs.version }}'"
run: "echo 'Version is now ${{ steps.get-outputs.outputs.version }} (Bumped: ${{ steps.get-outputs.outputs.bumped }})'"

7 changes: 7 additions & 0 deletions bumped.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CURRENT_VERSION=$($DIR/get-version.sh)

if [ $BEFORE_VERSION = $CURRENT_VERSION ]
then
print 'false'
else
print 'true'
26 changes: 23 additions & 3 deletions version-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ function bump {
local bv=$((parts[2] + 1))
NEW_VERSION="${parts[0]}.${parts[1]}.${bv}"
;;
auto)
if [ "${AUTO_HIGHER}" == "true" ] && [[ "${parts[2]}" == *"${AUTO_SPLITTER}${AUTO_SUFFIX}"* ]]; then
local higher=( ${parts[2]//${AUTO_SPLITTER}${AUTO_SUFFIX}/ } )
local bv=$((higher[1] + 1))
NEW_VERSION="${parts[0]}.${parts[1]}.$((parts[2] + 0))${AUTO_SPLITTER}${AUTO_SUFFIX}${bv}"
elif [ "${AUTO_HIGHER}" == "false" ] && [[ "${parts[2]}" == *"${AUTO_SPLITTER}${AUTO_SUFFIX}"* ]]; then
local higher=( ${parts[2]//${AUTO_SPLITTER}${AUTO_SUFFIX}/ } )
local bv=$((higher[1] + 0))
NEW_VERSION="${parts[0]}.${parts[1]}.$((parts[2] + 0))${AUTO_SPLITTER}${AUTO_SUFFIX}${bv}"
else
NEW_VERSION="${parts[0]}.${parts[1]}.$((parts[2] + 0))${AUTO_SPLITTER}${AUTO_SUFFIX}"
fi
;;
esac
}

Expand All @@ -43,6 +56,8 @@ elif git log -1 | grep -q "#minor"; then
BUMP_MODE="minor"
elif git log -1 | grep -q "#patch"; then
BUMP_MODE="patch"
elif [[ "${AUTO}" == "true" ]]; then
BUMP_MODE="auto"
fi

if [[ "${BUMP_MODE}" == "none" ]]
Expand All @@ -57,7 +72,12 @@ else
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"
git tag $NEW_VERSION
git push $REPO --follow-tags
git push $REPO --tags
if [[ "${BUMP_MODE}" == "auto" ]] && [[ "${AUTO_RELEASE}" == "false" ]]; then
echo "Doing no new tag for this bump because its disabled for auto mode"
else
git tag $NEW_VERSION
git push $REPO --follow-tags
git push $REPO --tags
echo "Created a new tag for this bump"
fi
fi

0 comments on commit 246363b

Please sign in to comment.