|
| 1 | +name: Backport Checker |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, labeled] |
| 6 | + branches: |
| 7 | + - next |
| 8 | + |
| 9 | +permissions: |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + check-backport-needed: |
| 14 | + name: Check if backport should be considered |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Check for backport labels |
| 18 | + id: check-labels |
| 19 | + env: |
| 20 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + run: | |
| 22 | + # Check if PR has any backport-to-* labels |
| 23 | + LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}' |
| 24 | + echo "Labels: $LABELS" |
| 25 | +
|
| 26 | + HAS_BACKPORT_LABEL=$(echo "$LABELS" | jq -r 'map(select(startswith("backport-to-"))) | length > 0') |
| 27 | + echo "has_backport_label=$HAS_BACKPORT_LABEL" >> $GITHUB_OUTPUT |
| 28 | +
|
| 29 | + - name: Remove existing backport comment if label added |
| 30 | + if: steps.check-labels.outputs.has_backport_label == 'true' |
| 31 | + env: |
| 32 | + GH_TOKEN: ${{ secrets.AZTEC_GITHUB_TOKEN }} |
| 33 | + run: | |
| 34 | + # Find and delete the backport reminder comment if it exists |
| 35 | + COMMENT_ID=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \ |
| 36 | + --jq '.[] | select(.body | contains("Consider backporting to")) | .id' | head -1) |
| 37 | +
|
| 38 | + if [ -n "$COMMENT_ID" ]; then |
| 39 | + echo "Removing backport reminder comment (ID: $COMMENT_ID)" |
| 40 | + gh api repos/${{ github.repository }}/issues/comments/$COMMENT_ID -X DELETE |
| 41 | + else |
| 42 | + echo "No backport reminder comment found to remove" |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Checkout repository |
| 46 | + if: steps.check-labels.outputs.has_backport_label == 'false' |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + - name: Get changed files |
| 52 | + if: steps.check-labels.outputs.has_backport_label == 'false' |
| 53 | + id: changed-files |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + run: | |
| 57 | + # Get the list of changed files in this PR |
| 58 | + CHANGED_FILES=$(gh pr diff ${{ github.event.pull_request.number }} --name-only || git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}) |
| 59 | + echo "Changed files:" |
| 60 | + echo "$CHANGED_FILES" |
| 61 | +
|
| 62 | + # Check for sequencer-related changes |
| 63 | + SEQUENCER_CHANGES=$(echo "$CHANGED_FILES" | grep -E '^yarn-project/sequencer-client/' || true) |
| 64 | +
|
| 65 | + # Check for release-image/bootstrap.sh changes |
| 66 | + RELEASE_IMAGE_CHANGES=$(echo "$CHANGED_FILES" | grep -E '^release-image/bootstrap\.sh$' || true) |
| 67 | +
|
| 68 | + # Check for prover coordination changes (prover-client and prover-node) |
| 69 | + PROVER_CHANGES=$(echo "$CHANGED_FILES" | grep -E '^yarn-project/(prover-client|prover-node)/' || true) |
| 70 | +
|
| 71 | + # Determine if backport should be considered |
| 72 | + NEEDS_BACKPORT="false" |
| 73 | +
|
| 74 | + if [ -n "$SEQUENCER_CHANGES" ] || [ -n "$RELEASE_IMAGE_CHANGES" ] || [ -n "$PROVER_CHANGES" ]; then |
| 75 | + NEEDS_BACKPORT="true" |
| 76 | + fi |
| 77 | +
|
| 78 | + echo "needs_backport=$NEEDS_BACKPORT" >> $GITHUB_OUTPUT |
| 79 | +
|
| 80 | + - name: Check for existing backport comment |
| 81 | + if: steps.check-labels.outputs.has_backport_label == 'false' && steps.changed-files.outputs.needs_backport == 'true' |
| 82 | + id: check-comment |
| 83 | + env: |
| 84 | + GH_TOKEN: ${{ secrets.AZTEC_GITHUB_TOKEN }} |
| 85 | + run: | |
| 86 | + # Check if we've already commented on this PR about backports |
| 87 | + EXISTING_COMMENT=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[].body' | grep -c "Consider backporting to" || true) |
| 88 | + if [ "$EXISTING_COMMENT" -gt 0 ]; then |
| 89 | + echo "already_commented=true" >> $GITHUB_OUTPUT |
| 90 | + else |
| 91 | + echo "already_commented=false" >> $GITHUB_OUTPUT |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Comment on PR about backport consideration |
| 95 | + if: steps.check-labels.outputs.has_backport_label == 'false' && steps.changed-files.outputs.needs_backport == 'true' && steps.check-comment.outputs.already_commented == 'false' |
| 96 | + env: |
| 97 | + GH_TOKEN: ${{ secrets.AZTEC_GITHUB_TOKEN }} |
| 98 | + run: | |
| 99 | + gh pr comment ${{ github.event.pull_request.number }} --body "This PR touches sequencer/prover code. Consider backporting to \`v2\` (Ignition) or \`v3\` (Testnet) if applicable." |
0 commit comments