-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OmOmofonmwan
committed
Jul 8, 2024
1 parent
ce5642a
commit d7aa836
Showing
2 changed files
with
100 additions
and
91 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,103 @@ | ||
name: Reusable Release Pipeline | ||
name: Reusable Release Workflow | ||
|
||
run-name: "Releasing ${{ github.event.repository.name }} #${{github.run_number}}" | ||
|
||
# Trigger workflow manually | ||
on: | ||
workflow_call: | ||
inputs: | ||
release_version: | ||
type: string | ||
required: true | ||
development_version: | ||
type: string | ||
required: true | ||
workflow_call: | ||
inputs: | ||
snapshot_version: | ||
type: string | ||
required: true | ||
release_version: | ||
type: string | ||
required: true | ||
release_message: | ||
type: string | ||
required: false | ||
|
||
# Define environment parameters | ||
env: | ||
BRANCH_NAME: ${{github.ref_name}} | ||
TRUNK_BRANCH_NAME: main | ||
RELEASE_MESSAGE: ${{github.event.inputs.release_message}} | ||
|
||
|
||
# Define jobs within the workflow | ||
jobs: | ||
set_build_and_tag_release: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Print Versions | ||
run: | | ||
echo "Next Dev Version: ${{inputs.development_version}}" | ||
echo "Next Release Version: ${{inputs.release_version}}" | ||
- 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=${{github.event.inputs.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/${{github.event.inputs.release_version}}', | ||
sha: context.sha | ||
}) | ||
set_next_dev: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- 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=${{github.event.inputs.development_version}}-SNAPSHOT -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 ${{github.event.inputs.development_version}}-SNAPSHOT' | ||
git push origin HEAD:main | ||
git push --tags origin | ||
create_release: | ||
name: Create Release | ||
permissions: write-all | ||
needs: | ||
- 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: ${{github.event.inputs.release_version}} | ||
release_name: Release ${{github.event.inputs.release_version}} | ||
body: | | ||
Release ${{github.event.inputs.release_version}} | ||
draft: false | ||
prerelease: false | ||
#Setting versioning for build and tags | ||
set_build_and_tag_release_and_set_next_dev_version: | ||
name: Set, Build, Tag Release Version & Set Next Version | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Setup Maven Action | ||
uses: s4u/[email protected] | ||
with: | ||
checkout-fetch-depth: 0 | ||
java-version: 21 | ||
java-distribution: adopt | ||
maven-version: 3.9.0 | ||
|
||
- name: Set Release Version | ||
run: | | ||
mvn -B versions:set \ | ||
-DnewVersion=${{inputs.release_version}} \ | ||
-DgenerateBackupPoms=false | ||
- name: Build Release Version | ||
run: | | ||
mvn -version | ||
mvn clean install | ||
- name: Create tag | ||
run: | | ||
git remote set-url origin https://git:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git | ||
git config user.name "Cloud User" | ||
git add . | ||
git commit -m 'Release ${{inputs.release_version}}' | ||
git tag -a ${{inputs.release_version}} -m '${{inputs.release_version}}' --force | ||
- name: Set Dev Version | ||
run: | | ||
mvn -B versions:set \ | ||
-DnewVersion=${{inputs.snapshot_version}} \ | ||
-DgenerateBackupPoms=false | ||
- name: Commit & Push | ||
run: | | ||
git add . | ||
git commit -m 'Set next dev version to ${{inputs.snapshot_version}}' | ||
git push origin HEAD:main | ||
git push --tags origin | ||
# Creating a release | ||
create_release: | ||
name: Create Release | ||
permissions: write-all | ||
|
||
needs: | ||
- set_build_and_tag_release_and_set_next_dev_version | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Modify Release Message | ||
if: inputs.release_message == '' | ||
run: echo "RELEASE_MESSAGE=Release ${{inputs.release_version}}" >> $GITHUB_ENV | ||
|
||
- name: Create Release | ||
id: create_release | ||
run: | | ||
curl -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
https://api.github.com/repos/${{github.repository}}/releases \ | ||
-d '{"tag_name":"${{inputs.release_version}}","name":"${{inputs.release_version}}","body":"${{env.RELEASE_MESSAGE}}","draft":false,"prerelease":false,"generate_release_notes":false}' |