|
| 1 | +name: Rollback Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + branch_from: |
| 7 | + description: 'The known good version to re-release (e.g. 2.9.1)' |
| 8 | + required: true |
| 9 | + deprecated_version: |
| 10 | + description: 'The version you are rolling back (e.g. 2.9.2)' |
| 11 | + required: true |
| 12 | + new_version: |
| 13 | + description: 'The new version number (e.g. 2.9.3)' |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +jobs: |
| 18 | + rollback-release: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + env: |
| 21 | + AWS_REGION: "us-east-1" |
| 22 | + BRANCH_FROM: ${{ inputs.branch_from }} |
| 23 | + DEPRECATED_VERSION: ${{ inputs.deprecated_version }} |
| 24 | + NEW_VERSION: ${{ inputs.new_version }} |
| 25 | + CI_COMMIT_MESSAGE: Re-release v${{ inputs.branch_from }} as v${{ inputs.new_version }} |
| 26 | + ROLLBACK_BRANCH: rollback_${{ inputs.deprecated_version }} |
| 27 | + NEW_TAG: release_v${{ inputs.new_version }} |
| 28 | + permissions: |
| 29 | + id-token: write |
| 30 | + contents: write |
| 31 | + actions: write |
| 32 | + steps: |
| 33 | + - name: Checkout Source Code |
| 34 | + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 |
| 35 | + with: |
| 36 | + ref: ${{ format('release_v{0}', env.BRANCH_FROM) }} |
| 37 | + token: ${{ secrets.GH_WORKFLOW_TOKEN }} |
| 38 | + - name: Create Rollback Branch |
| 39 | + run: git checkout -b ${{ env.ROLLBACK_BRANCH }} |
| 40 | + - name: Update Version |
| 41 | + run: | |
| 42 | + git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 43 | + git config --global user.name github-actions[bot] |
| 44 | + sed -i 's/POM_VERSION=${{ env.BRANCH_FROM }}/POM_VERSION=${{ env.NEW_VERSION }}/g' gradle.properties |
| 45 | + echo -e '## [Release ${{ env.NEW_VERSION }}](https://github.com/${{ github.repository }}/releases/tag/${{ env.NEW_TAG }})\n\nThis is a re-release of version ${{ env.BRANCH_FROM }}. Use this instead of version ${{ env.DEPRECATED_VERSION }}.\n' | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md |
| 46 | + git add gradle.properties |
| 47 | + git add CHANGELOG.md |
| 48 | + git commit -m "${{ env.CI_COMMIT_MESSAGE }}" |
| 49 | + - name: Tag Version |
| 50 | + run: git tag "${{ env.NEW_TAG }}" |
| 51 | + - name: Push Changes |
| 52 | + run: git push --atomic origin ${{ env.ROLLBACK_BRANCH }} ${{ env.NEW_TAG }} |
| 53 | + - name: Run Publish |
| 54 | + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 |
| 55 | + with: |
| 56 | + # The aws-codebuild-run-build action automatically passes the source version that the workflow |
| 57 | + # is run on to Codebuild, and there is no override option. In order to run the Codebuild |
| 58 | + # release with our newly-created tag version we dispatch another workflow on that tag. |
| 59 | + script: | |
| 60 | + github.rest.actions.createWorkflowDispatch({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + workflow_id: 'rollback_publish.yml', |
| 64 | + ref: "${{ env.NEW_TAG }}", |
| 65 | + }) |
0 commit comments