Incrementing Release Version -- Major #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Increment Release Version Pipeline | |
run-name: "Incrementing Release Version -- ${{github.event.inputs.action}}" | |
on: | |
workflow_dispatch: | |
inputs: | |
action: | |
type: choice | |
description: Version To Increment | |
options: | |
- Major | |
- Minor | |
- Patch | |
required: true | |
env: | |
INCREMENTING_VERSION: ${{github.event.inputs.action}} | |
jobs: | |
get_version: | |
runs-on: ubuntu-latest | |
name: Get Version | |
outputs: | |
RELEASE_VERSION: ${{steps.splitVersion.outputs._0}} | |
_MAJOR: ${{steps.splitVersionMinor.outputs._0}} | |
_MINOR: ${{steps.splitVersionMinor.outputs._1}} | |
_PATCH: ${{steps.splitVersionMinor.outputs._2}} | |
steps: | |
- name: Checkout Code Repository | |
uses: actions/checkout@v4 | |
- name: Downloading Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Get Current Version | |
run: | | |
echo "POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | |
- name: Print Version | |
run: echo ${{env.POM_VERSION}} | |
- name: Split version code | |
uses: xom9ikk/split@v1 | |
id: splitVersion | |
with: | |
string: ${{env.POM_VERSION}} | |
separator: -SNAPSHOT | |
limit: -1 | |
- name: Split version code - Minor | |
uses: xom9ikk/split@v1 | |
id: splitVersionMinor | |
with: | |
string: ${{steps.splitVersion.outputs._0}} | |
separator: . | |
limit: -1 | |
increment_version: | |
runs-on: ubuntu-latest | |
needs: get_version | |
outputs: | |
NEXT_SNAPSHOT_VERSION: ${{steps.nextSnapshotVersion.outputs.NEXT_SNAPSHOT_VERSION}} | |
RELEASE_VERSION: ${{needs.get_version.outputs.RELEASE_VERSION}} | |
name: "Increment ${{github.event.inputs.action}} Version" | |
steps: | |
- name: Set Env - Major | |
shell: bash | |
run: | | |
VERSION_PICKED=${{env.INCREMENTING_VERSION}} | |
if [[ "$VERSION_PICKED" == "Major" ]]; then | |
echo "VERSION_NUMBER=${{needs.get_version.outputs._MAJOR}}" >> $GITHUB_ENV | |
elif [[ "$VERSION_PICKED" == "Minor" ]]; then | |
echo "VERSION_NUMBER=${{needs.get_version.outputs._MINOR}}" >> $GITHUB_ENV | |
else | |
echo "VERSION_NUMBER=${{needs.get_version.outputs._PATCH}}" >> $GITHUB_ENV | |
fi | |
- name: Print Version | |
run: echo ${{env.INCREMENTING_VERSION}} -- ${{env.VERSION_NUMBER}} | |
- name: Increment Version | |
run: echo "NEW_VERSION_NUMBER=$((${{env.VERSION_NUMBER}} + 1))" >> $GITHUB_ENV | |
- name: Generate New Snapshot Version Output | |
id: nextSnapshotVersion | |
shell: bash | |
run: | | |
VERSION_PICKED=${{env.INCREMENTING_VERSION}} | |
if [[ "$VERSION_PICKED" == "Major" ]]; then | |
echo "NEXT_SNAPSHOT_VERSION=${{env.NEW_VERSION_NUMBER}}.0.0" >> $GITHUB_OUTPUT | |
elif [[ "$VERSION_PICKED" == "Minor" ]]; then | |
echo "NEXT_SNAPSHOT_VERSION=${{needs.get_version.outputs._MAJOR}}.${{env.NEW_VERSION_NUMBER}}.0" >> $GITHUB_OUTPUT | |
else | |
echo "NEXT_SNAPSHOT_VERSION=${{needs.get_version.outputs._MAJOR}}.${{needs.get_version.outputs._MINOR}}.${{env.NEW_VERSION_NUMBER}}" >> $GITHUB_OUTPUT | |
fi | |
set_build_and_tag_release: | |
runs-on: ubuntu-latest | |
needs: increment_version | |
name: "Set, Build & Tag Release Version" | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Code Repository | |
uses: actions/checkout@v4 | |
- name: Downloading Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Set Release Version | |
run: mvn -B versions:set -DnewVersion=${{needs.increment_version.outputs.RELEASE_VERSION}} -DgenerateBackupPoms=false | |
- name: Build Release Version | |
run: mvn -version mvn clean install | |
- name: Create tag | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/${{needs.increment_version.outputs.RELEASE_VERSION}}', | |
sha: context.sha | |
}) | |
set_next_dev: | |
runs-on: ubuntu-latest | |
name: Set Next Snapshot Version | |
needs: | |
- increment_version | |
- set_build_and_tag_release | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Code Repository | |
uses: actions/checkout@v4 | |
- name: Downloading Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Set Dev Version | |
run: mvn -B versions:set -DnewVersion=${{needs.increment_version.outputs.NEXT_SNAPSHOT_VERSION}} -DgenerateBackupPoms=false | |
- name: Commit & Push | |
run: | | |
git add . | |
git config user.name fda_shield_omoruyi | |
git config user.email [email protected] | |
git commit -m 'Set next dev version to ${{needs.increment_version.outputs.NEXT_SNAPSHOT_VERSION}}' | |
git push origin HEAD:main | |
git push --tags origin | |
create_release: | |
name: Create Release | |
permissions: write-all | |
needs: | |
- increment_version | |
- set_build_and_tag_release | |
- set_next_dev | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@master | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag_name: ${{needs.increment_version.outputs.RELEASE_VERSION}} | |
release_name: Release ${{needs.increment_version.outputs.RELEASE_VERSION}} | |
body: | | |
New Release Version ${{needs.increment_version.outputs.RELEASE_VERSION}} | |
draft: false | |
prerelease: false | |