Skip to content

Commit

Permalink
Testing GitHub Actions POC
Browse files Browse the repository at this point in the history
  • Loading branch information
OmOmofonmwan committed Jul 8, 2024
1 parent ce5642a commit d7aa836
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 91 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/release_version_poc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
call_release_workflow_with_custom_inputs:
needs: get_custom_inputs
name: Call Release Workflow With Custom Inputs
uses: ikmdev/build-parent/.github/workflows/reusable_release_workflow.yaml@main
uses: OmOmofonmwan/GitHub-Actions-POC/.github/workflows/reusable_release_poc.yaml@main
permissions: write-all
secrets: inherit
with:
Expand Down Expand Up @@ -156,9 +156,8 @@ jobs:
echo "Release Version: ${{needs.get_major_minor_patch_inputs.outputs.RELEASE_VERSION}}"
call_release_workflow_incremented_version:
needs:
- increment_version
uses: ikmdev/build-parent/.github/workflows/reusable_release_workflow.yaml@main
needs: increment_version
uses: OmOmofonmwan/GitHub-Actions-POC/.github/workflows/reusable_release_poc.yaml@main
name: Call Release Workflow With Incremented Version
permissions: write-all
secrets: inherit
Expand Down
184 changes: 97 additions & 87 deletions .github/workflows/reusable_release_poc.yaml
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}'

0 comments on commit d7aa836

Please sign in to comment.