From 246363bf12e36cf5269017d15e926a86c7589536 Mon Sep 17 00:00:00 2001 From: Tigerpanzer_02 <37453987+Tigerpanzer02@users.noreply.github.com> Date: Wed, 16 Jun 2021 15:35:38 +0200 Subject: [PATCH] Added automatic maven version bump --- CHANGELOG.md | 7 +++++++ action.yml | 54 ++++++++++++++++++++++++++++++++++++++++++++++--- bumped.sh | 7 +++++++ version-bump.sh | 26 +++++++++++++++++++++--- 4 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 bumped.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea8979..9a40bbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/action.yml b/action.yml index 034c458..9c12ced 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 }})'" diff --git a/bumped.sh b/bumped.sh new file mode 100644 index 0000000..fb3af70 --- /dev/null +++ b/bumped.sh @@ -0,0 +1,7 @@ +CURRENT_VERSION=$($DIR/get-version.sh) + +if [ $BEFORE_VERSION = $CURRENT_VERSION ] + then + print 'false' + else + print 'true' \ No newline at end of file diff --git a/version-bump.sh b/version-bump.sh index c9a028d..a98cd12 100755 --- a/version-bump.sh +++ b/version-bump.sh @@ -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 } @@ -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" ]] @@ -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