|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 OR ISC |
| 3 | +# |
| 4 | +# Backport bot. When a pull request labelled needs-backport merges, work out which |
| 5 | +# supported release branches still need the fix and open one pull request each. |
| 6 | +# |
| 7 | +# Split into two jobs on purpose. `analyze` is the only job that talks to the model, |
| 8 | +# and it has no write access. `publish` is the only job that can write, and it never |
| 9 | +# talks to the model. So repository content, which the model reads, is never handled |
| 10 | +# by a job holding a token that could change the repository. |
| 11 | +# |
| 12 | +# The OIDC role is pinned to this file by job_workflow_ref in |
| 13 | +# tests/ci/cdk/cdk/aws_lc_github_oidc_stack.py, so renaming this file breaks the |
| 14 | +# trust policy until the CDK stack is redeployed. |
| 15 | +name: backport-bot |
| 16 | + |
| 17 | +on: |
| 18 | + pull_request_target: |
| 19 | + types: [closed] |
| 20 | + |
| 21 | +permissions: {} |
| 22 | + |
| 23 | +jobs: |
| 24 | + analyze: |
| 25 | + name: analyze |
| 26 | + # Only merged pull requests, and only when somebody asked for a backport. Reading |
| 27 | + # the label here rather than in the tool keeps the decision with the reviewers |
| 28 | + if: >- |
| 29 | + github.event.pull_request.merged == true && |
| 30 | + contains(github.event.pull_request.labels.*.name, 'needs-backport') |
| 31 | + permissions: |
| 32 | + id-token: write # to assume the Bedrock role |
| 33 | + contents: read |
| 34 | + runs-on: |
| 35 | + - codebuild-aws-lc-ci-github-actions-${{ github.run_id }}-${{ github.run_attempt }} |
| 36 | + image:linux-5.0 |
| 37 | + instance-size:small |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v6 |
| 40 | + with: |
| 41 | + # The merge commit, not the pull request head, so no untrusted code runs |
| 42 | + ref: ${{ github.event.pull_request.merge_commit_sha }} |
| 43 | + # Brings every branch, which is how the tool sees the release branches, and |
| 44 | + # the whole history, which it needs to compare them |
| 45 | + fetch-depth: 0 |
| 46 | + persist-credentials: false |
| 47 | + - name: Load shared Bedrock settings |
| 48 | + # For configure-aws-credentials, which takes no region input and reads |
| 49 | + # AWS_REGION from the environment. No model id is set here: the tool reads |
| 50 | + # the same shared file itself |
| 51 | + run: | |
| 52 | + jq -r '"AWS_REGION=\(.aws_region)"' \ |
| 53 | + .github/workflows/ai-config.json >> "$GITHUB_ENV" |
| 54 | + - uses: ./.github/actions/configure-aws-credentials |
| 55 | + with: |
| 56 | + oidcRole: AwsLcGitHubActionsBackportOidcRole |
| 57 | + roleName: AwsLcGitHubActionsBedrockRole |
| 58 | + - name: Install the AI client |
| 59 | + run: pip3 install --user anthropic boto3 |
| 60 | + - name: Work out which branches need the fix |
| 61 | + run: | |
| 62 | + util/backport/backport analyze \ |
| 63 | + --commit "${{ github.event.pull_request.merge_commit_sha }}" --skip |
| 64 | + - name: Keep the verdict for the publish job |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: backport-run |
| 68 | + path: util/backport/.backport-runs/last-run.json |
| 69 | + if-no-files-found: error |
| 70 | + |
| 71 | + publish: |
| 72 | + name: publish |
| 73 | + needs: analyze |
| 74 | + permissions: |
| 75 | + contents: write # to push the backport branches |
| 76 | + pull-requests: write # to open and comment on the backport pull requests |
| 77 | + runs-on: |
| 78 | + - codebuild-aws-lc-ci-github-actions-${{ github.run_id }}-${{ github.run_attempt }} |
| 79 | + image:linux-5.0 |
| 80 | + instance-size:small |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v6 |
| 83 | + with: |
| 84 | + ref: ${{ github.event.pull_request.merge_commit_sha }} |
| 85 | + fetch-depth: 0 |
| 86 | + # persist-credentials is left alone here, unlike in analyze: this job pushes |
| 87 | + # the backport branches, and it is the checkout's credentials that do it |
| 88 | + - name: Take the verdict from the analyze job |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: |
| 91 | + name: backport-run |
| 92 | + path: util/backport/.backport-runs |
| 93 | + - name: Cherry-pick and open the pull requests |
| 94 | + env: |
| 95 | + GH_TOKEN: ${{ github.token }} |
| 96 | + run: | |
| 97 | + # cherry-pick needs an author, and a runner has no git identity |
| 98 | + git config user.name "aws-lc-backport-bot" |
| 99 | + git config user.email "backport-bot@users.noreply.github.com" |
| 100 | + # --push-to-aws-lc because in CI the checkout is aws/aws-lc itself, |
| 101 | + # so the backport branches have nowhere else to go |
| 102 | + util/backport/backport apply --yes |
| 103 | + util/backport/backport publish \ |
| 104 | + --pr "${{ github.event.pull_request.number }}" \ |
| 105 | + --push-to-aws-lc --yes |
0 commit comments