|
| 1 | +# Runs when a PR is opened. Performs the following tasks: |
| 2 | +# - Adds a review checklist comment |
| 3 | +# - Adds initial labels (NeedsWebsiteDocsUpdate, NeedsDescriptionUpdate, NeedsIssue, NeedsBackportReason) |
| 4 | +name: PR opened tasks |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request_target: # zizmor: ignore[dangerous-triggers] only checks out the base ref, never PR code |
| 11 | + types: [opened] |
| 12 | + |
| 13 | +jobs: |
| 14 | + # Skip PRs with "Backport" or "Forwardport" labels since those are automated. |
| 15 | + check_labels: |
| 16 | + name: Check for Backport or Forwardport labels |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + skip: ${{ steps.check_labels.outputs.skip }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Harden the runner (Audit all outbound calls) |
| 23 | + uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0 |
| 24 | + with: |
| 25 | + egress-policy: audit |
| 26 | + |
| 27 | + - name: Generate GitHub App token |
| 28 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 29 | + id: app-token |
| 30 | + with: |
| 31 | + app-id: ${{ vars.APP_ID }} |
| 32 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 33 | + permission-pull-requests: read |
| 34 | + |
| 35 | + - name: Check for Backport or Forwardport labels |
| 36 | + id: check_labels |
| 37 | + env: |
| 38 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 39 | + run: | |
| 40 | + # Get labels for this pull request |
| 41 | + LABELS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name') |
| 42 | +
|
| 43 | + # Check if PR has Backport or Forwardport label (case-insensitive) |
| 44 | + if echo "$LABELS" | grep -qi "^backport$\|^forwardport$"; then |
| 45 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 46 | + echo "PR has Backport or Forwardport label, skipping opened PR tasks" |
| 47 | + else |
| 48 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 49 | + fi |
| 50 | +
|
| 51 | + add_review_checklist: |
| 52 | + name: Add Review Checklist |
| 53 | + permissions: |
| 54 | + pull-requests: write |
| 55 | + runs-on: ubuntu-latest |
| 56 | + needs: check_labels |
| 57 | + if: needs.check_labels.outputs.skip != 'true' |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Generate GitHub App token |
| 61 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 62 | + id: app-token |
| 63 | + with: |
| 64 | + app-id: ${{ vars.APP_ID }} |
| 65 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 66 | + permission-pull-requests: write |
| 67 | + |
| 68 | + - name: Checkout code |
| 69 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 70 | + with: |
| 71 | + ref: ${{ github.base_ref }} |
| 72 | + persist-credentials: 'false' |
| 73 | + |
| 74 | + - name: Add Review Checklist Comment |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 77 | + run: | |
| 78 | + gh pr comment ${{ github.event.pull_request.number }} \ |
| 79 | + --repo ${{ github.repository }} \ |
| 80 | + --body-file .github/review_checklist.md |
| 81 | +
|
| 82 | + add_initial_labels: |
| 83 | + name: Add Initial Labels |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: check_labels |
| 86 | + if: needs.check_labels.outputs.skip != 'true' |
| 87 | + |
| 88 | + steps: |
| 89 | + - name: Generate GitHub App token |
| 90 | + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 91 | + id: app-token |
| 92 | + with: |
| 93 | + app-id: ${{ vars.APP_ID }} |
| 94 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 95 | + permission-pull-requests: write |
| 96 | + |
| 97 | + - name: Add Initial Labels |
| 98 | + env: |
| 99 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 100 | + run: | |
| 101 | + gh pr edit ${{ github.event.pull_request.number }} \ |
| 102 | + --repo ${{ github.repository }} \ |
| 103 | + --add-label "NeedsWebsiteDocsUpdate,NeedsDescriptionUpdate,NeedsIssue,NeedsBackportReason" |
| 104 | +
|
| 105 | + labeler: |
| 106 | + if: github.repository == 'vitessio/vitess' |
| 107 | + needs: add_initial_labels |
| 108 | + permissions: |
| 109 | + contents: read |
| 110 | + pull-requests: write |
| 111 | + runs-on: ubuntu-latest |
| 112 | + steps: |
| 113 | + - name: Run actions/labeler |
| 114 | + uses: actions/labeler@b8dd2d9be0f68b860e7dae5dae7d772984eacd6d # v6.2.0 |
0 commit comments