|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - release |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + extract-release-version: |
| 14 | + name: Extract release version |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + version: ${{ steps.extract-release-version.outputs.result }} |
| 18 | + steps: |
| 19 | + - name: Extract release version |
| 20 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 21 | + id: extract-release-version |
| 22 | + with: |
| 23 | + result-encoding: string |
| 24 | + script: | |
| 25 | + const matches = `${{ github.event.head_commit.message }}`.match(/[0-9]+\.[0-9]+\.[0-9]+/) ?? [] |
| 26 | + return matches.length > 0 ? matches[0] : "" |
| 27 | +
|
| 28 | + validate-version-format: |
| 29 | + name: Validate Version Format |
| 30 | + needs: |
| 31 | + - extract-release-version |
| 32 | + if: ${{ needs.extract-release-version.outputs.version != '' }} |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Validated |
| 36 | + run: echo "Releasing new version ${{ needs.extract-release-version.outputs.version }}" |
| 37 | + |
| 38 | + unit-test: |
| 39 | + name: Unit Tests |
| 40 | + needs: |
| 41 | + - validate-version-format |
| 42 | + uses: ./.github/workflows/unit-test.yaml |
| 43 | + with: |
| 44 | + identifier: workflow-call-unit-test |
| 45 | + |
| 46 | + build-on-minimum-supported-platforms: |
| 47 | + name: Build on minimum supported platforms |
| 48 | + needs: |
| 49 | + - validate-version-format |
| 50 | + uses: ./.github/workflows/build-on-minimum-supported-platform.yaml |
| 51 | + with: |
| 52 | + identifier: workflow-call-build-on-minimum-platforms |
| 53 | + |
| 54 | + release: |
| 55 | + name: Release new version |
| 56 | + environment: Release |
| 57 | + needs: |
| 58 | + - extract-release-version |
| 59 | + - unit-test |
| 60 | + - build-on-minimum-supported-platforms |
| 61 | + runs-on: ubuntu-latest |
| 62 | + env: |
| 63 | + RELEASE_VERSION: ${{ needs.extract-release-version.outputs.version }} |
| 64 | + steps: |
| 65 | + - name: Checkout Code |
| 66 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 67 | + with: |
| 68 | + ref: release |
| 69 | + fetch-depth: 0 |
| 70 | + persist-credentials: false |
| 71 | + |
| 72 | + - name: Configure AWS Credentials |
| 73 | + uses: aws-actions/configure-aws-credentials@v4 |
| 74 | + with: |
| 75 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 76 | + role-session-name: ${{ format('{0}.release', github.run_id) }} |
| 77 | + aws-region: ${{ secrets.AWS_REGION }} |
| 78 | + |
| 79 | + - name: Setup Github Token |
| 80 | + id: setup-pat |
| 81 | + env: |
| 82 | + DEPLOY_SECRET_ARN: ${{ secrets.DEPLOY_SECRET_ARN }} |
| 83 | + run: | |
| 84 | + PAT=$(aws secretsmanager get-secret-value \ |
| 85 | + --secret-id "${DEPLOY_SECRET_ARN}" \ |
| 86 | + | jq -r ".SecretString | fromjson | .Credential") |
| 87 | + echo "token=$PAT" >> $GITHUB_OUTPUT |
| 88 | +
|
| 89 | + - name: Create new version tag ${{ needs.extract-release-version.outputs.version }} |
| 90 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 91 | + with: |
| 92 | + script: | |
| 93 | + github.rest.git.createRef({ |
| 94 | + owner: context.repo.owner, |
| 95 | + repo: context.repo.repo, |
| 96 | + ref: `refs/tags/${process.env.RELEASE_VERSION}`, |
| 97 | + sha: context.sha, |
| 98 | + force: true |
| 99 | + }) |
| 100 | +
|
| 101 | + - name: Sync Back to Main |
| 102 | + env: |
| 103 | + PAT: ${{ steps.setup-pat.outputs.token }} |
| 104 | + GITHUB_USER: aws-amplify-ops |
| 105 | + GITHUB_EMAIL: aws-amplify-ops@amazon.com |
| 106 | + run: | |
| 107 | + git config user.name $GITHUB_USER |
| 108 | + git config user.email $GITHUB_EMAIL |
| 109 | + git push "https://${PAT}@github.com/${{ github.repository }}" HEAD:main |
0 commit comments