Skip to content

Releasing GitHub_Actions_POC #38 #38

Releasing GitHub_Actions_POC #38

Releasing GitHub_Actions_POC #38 #38

Workflow file for this run

name: Release Pipeline
run-name: "Releasing ${{ github.event.repository.name }} #${{github.run_number}}"
on:
workflow_dispatch
jobs:
initialization:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref_name == 'refs/heads/master'
outputs:
SNAPSHOT_VERSION: ${{steps.newSnapshotVersion.outputs.SnapshotVersion}}
RELEASE_VERSION: ${{steps.splitVersion.outputs._0}}
env:
SNAPSHOTVERSION: ""
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: Verify Is SNAPSHOT Version
if: ${{ !contains(env.POM_VERSION, '-SNAPSHOT')}}
run: |
echo "ERROR: Version is set to incompatible version ${{env.POM_VERSION}}. Only SNAPSHOT development versions can be converted to a release version."
exit 1
- 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
- name: Increment Snapshot Version
id: newSnapshotVersion
run: |
echo "SnapshotVersion=${{steps.splitVersionMinor.outputs._0}}.$((${{steps.splitVersionMinor.outputs._1}} + 1)).${{steps.splitVersionMinor.outputs._2}}-SNAPSHOT" >> $GITHUB_OUTPUT
- name: Print Versions
run: |
echo " Snapshot Version -- ${{steps.newSnapshotVersion.outputs.SnapshotVersion}}"
echo " Release Version -- ${{steps.splitVersion.outputs._0}}"
set_build_and_tag_release:
runs-on: ubuntu-latest
needs: initialization
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.initialization.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.initialization.outputs.RELEASE_VERSION}}',
sha: context.sha
})
set_dev_release:
runs-on: ubuntu-latest
needs:
- initialization
- 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 Release Version
run: mvn -B versions:set -DnewVersion=${{needs.initialization.outputs.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.initialization.outputs.SNAPSHOT_VERSION}}'
git push origin HEAD:main
git push --tags origin