|
| 1 | +name: Update ci-infra crcr Terrafile |
| 2 | + |
| 3 | +# When a test-infra lambda release is published, check whether it contains |
| 4 | +# changes to the CRCR lambda code (aws/lambda/cross_repo_ci_relay/**). If so, |
| 5 | +# open a PR in pytorch/ci-infra that bumps the `tag` in crcr/Terrafile so the |
| 6 | +# deploy pulls the newly built cross-repo-ci-webhook.zip / cross-repo-ci-callback.zip. |
| 7 | +# |
| 8 | +# Not every release needs a bump: only releases that actually changed the CRCR |
| 9 | +# lambda code vs the previous lambda release trigger a PR. |
| 10 | + |
| 11 | +on: |
| 12 | + release: |
| 13 | + types: [published] |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + tag: |
| 17 | + description: "test-infra release tag to promote to ci-infra crcr/Terrafile" |
| 18 | + required: true |
| 19 | + type: string |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +jobs: |
| 25 | + maybe-update-crcr-terrafile: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + environment: trigger-nightly |
| 28 | + steps: |
| 29 | + - name: Resolve release tag |
| 30 | + id: tag |
| 31 | + env: |
| 32 | + EVENT_TAG: ${{ github.event.release.tag_name }} |
| 33 | + INPUT_TAG: ${{ inputs.tag }} |
| 34 | + run: | |
| 35 | + TAG="${INPUT_TAG:-$EVENT_TAG}" |
| 36 | + # Only lambda release tags (vYYYYMMDD-HHMMSS) are eligible. Skips |
| 37 | + # -custom tags (test builds) and unrelated releases (e.g. blast-cli-*). |
| 38 | + if [[ ! "$TAG" =~ ^v[0-9]{8}-[0-9]{6}$ ]]; then |
| 39 | + echo "Skipping non-lambda release tag: $TAG" |
| 40 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 44 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + - name: Checkout test-infra at release tag |
| 47 | + if: steps.tag.outputs.skip == 'false' |
| 48 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 49 | + with: |
| 50 | + ref: ${{ steps.tag.outputs.tag }} |
| 51 | + fetch-depth: 0 |
| 52 | + path: test-infra |
| 53 | + |
| 54 | + # Detect whether this release's commit actually touched CRCR lambda |
| 55 | + # files. Only releases whose commit changed aws/lambda/cross_repo_ci_relay/** |
| 56 | + # need a Terrafile bump; everything else is skipped. |
| 57 | + - name: Detect CRCR lambda changes |
| 58 | + id: crcr |
| 59 | + if: steps.tag.outputs.skip == 'false' |
| 60 | + working-directory: test-infra |
| 61 | + env: |
| 62 | + NEW_TAG: ${{ steps.tag.outputs.tag }} |
| 63 | + run: | |
| 64 | + set -euo pipefail |
| 65 | + if ! git rev-parse --verify -q "${NEW_TAG}~1" >/dev/null 2>&1; then |
| 66 | + echo "Release tag has no parent commit; skipping" |
| 67 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | + if git diff --name-only "${NEW_TAG}~1" "${NEW_TAG}" -- aws/lambda/cross_repo_ci_relay/ | grep -q .; then |
| 71 | + echo "CRCR lambda code changed in this release; ci-infra Terrafile needs a bump" |
| 72 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 73 | + else |
| 74 | + echo "No CRCR lambda changes in this release; no Terrafile update needed" |
| 75 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Checkout ci-infra |
| 79 | + if: steps.crcr.outputs.changed == 'true' |
| 80 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 81 | + with: |
| 82 | + repository: pytorch/ci-infra |
| 83 | + token: ${{ secrets.GH_PYTORCHBOT_TOKEN }} |
| 84 | + ref: main |
| 85 | + path: ci-infra |
| 86 | + fetch-depth: 0 |
| 87 | + |
| 88 | + - name: Update crcr Terrafile tag |
| 89 | + if: steps.crcr.outputs.changed == 'true' |
| 90 | + working-directory: ci-infra |
| 91 | + run: | |
| 92 | + set -euo pipefail |
| 93 | + python3 ../test-infra/.github/scripts/update_crcr_terrafile.py crcr/Terrafile "${{ steps.tag.outputs.tag }}" |
| 94 | + echo "--- crcr/Terrafile diff ---" |
| 95 | + git diff -- crcr/Terrafile |
| 96 | +
|
| 97 | + - name: Create Pull Request |
| 98 | + if: steps.crcr.outputs.changed == 'true' |
| 99 | + uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7 |
| 100 | + with: |
| 101 | + token: ${{ secrets.GH_PYTORCHBOT_TOKEN }} |
| 102 | + path: ci-infra |
| 103 | + base: main |
| 104 | + branch: create-pull-request/update-crcr-terrafile-${{ steps.tag.outputs.tag }} |
| 105 | + add-paths: crcr/Terrafile |
| 106 | + commit-message: "Update crcr Terrafile to release ${{ steps.tag.outputs.tag }}" |
| 107 | + title: "[CRCR] Update crcr Terrafile to release ${{ steps.tag.outputs.tag }}" |
| 108 | + reviewers: fffrog, can-gaa-hou, atalman |
| 109 | + body: | |
| 110 | + This PR is auto-generated by the `update-crcr-terrafile` workflow in [pytorch/test-infra](https://github.com/pytorch/test-infra). |
| 111 | +
|
| 112 | + test-infra release `${{ steps.tag.outputs.tag }}` contains changes to the CRCR (`aws/lambda/cross_repo_ci_relay`) Lambda code, so `crcr/Terrafile` is updated to reference the new release tag and pick up the freshly built `cross-repo-ci-webhook.zip` / `cross-repo-ci-callback.zip` assets. |
0 commit comments