diff --git a/.github/workflows/release_version_poc.yaml b/.github/workflows/release_version_poc.yaml index 2e1b245..21cb6a9 100644 --- a/.github/workflows/release_version_poc.yaml +++ b/.github/workflows/release_version_poc.yaml @@ -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: @@ -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 diff --git a/.github/workflows/reusable_release_poc.yaml b/.github/workflows/reusable_release_poc.yaml index 0452bcf..f5c6f61 100644 --- a/.github/workflows/reusable_release_poc.yaml +++ b/.github/workflows/reusable_release_poc.yaml @@ -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 oomofonmwan93@gmail.com - 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 \ No newline at end of file + #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/setup-maven-action@v1.14.0 + 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}' \ No newline at end of file