|
| 1 | +name: Companion PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, edited] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + check-companion-pr: |
| 13 | + name: Check |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Check for companion PR |
| 19 | + id: check |
| 20 | + env: |
| 21 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + run: | |
| 23 | + set +e |
| 24 | + output=$(./_assets/scripts/check-companion-pr.sh "${{ github.event.pull_request.number }}" "${{ github.event.pull_request.head.sha }}") |
| 25 | + exit_code=$? |
| 26 | + set -e |
| 27 | + echo "$output" |
| 28 | + while IFS='=' read -r key value; do |
| 29 | + echo "${key,,}=${value}" >> "$GITHUB_OUTPUT" |
| 30 | + done < <(echo "$output" | grep -E '^[A-Z_]+=') |
| 31 | + exit $exit_code |
| 32 | +
|
| 33 | + - name: Post comment |
| 34 | + if: always() |
| 35 | + uses: actions/github-script@v7 |
| 36 | + env: |
| 37 | + OUTPUTS_JSON: ${{ toJSON(steps.check.outputs) }} |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const outputs = JSON.parse(process.env.OUTPUTS_JSON); |
| 41 | + const prNumber = context.payload.pull_request.number; |
| 42 | + const headSha = context.payload.pull_request.head.sha; |
| 43 | +
|
| 44 | + let body; |
| 45 | + if (outputs.reason === 'no_link_in_description') { |
| 46 | + body = [ |
| 47 | + '<!-- companion-pr-check -->', |
| 48 | + '## ⚠️ Companion PR Required', |
| 49 | + '', |
| 50 | + 'Add a link to your status-app PR in this PR\'s description.', |
| 51 | + '', |
| 52 | + 'Example: `https://github.com/status-im/status-app/pull/123`' |
| 53 | + ].join('\n'); |
| 54 | + } else if (outputs.reason === 'sha_mismatch') { |
| 55 | + body = [ |
| 56 | + '<!-- companion-pr-check -->', |
| 57 | + '## ⚠️ Companion PR Needs Update', |
| 58 | + '', |
| 59 | + '[#' + outputs.companion_pr_number + '](' + outputs.companion_pr_url + ') is not using the latest status-go commit (`' + headSha + '`).', |
| 60 | + '', |
| 61 | + 'Update `vendor/status-go` in the companion PR.' |
| 62 | + ].join('\n'); |
| 63 | + } else if (outputs.verified === 'true') { |
| 64 | + body = [ |
| 65 | + '<!-- companion-pr-check -->', |
| 66 | + '## ✅ Companion PR Verified', |
| 67 | + '', |
| 68 | + '[#' + outputs.companion_pr_number + ' - ' + outputs.companion_pr_title + '](' + outputs.companion_pr_url + ')' |
| 69 | + ].join('\n'); |
| 70 | + } else { |
| 71 | + return; |
| 72 | + } |
| 73 | +
|
| 74 | + const { data: comments } = await github.rest.issues.listComments({ |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + issue_number: prNumber |
| 78 | + }); |
| 79 | +
|
| 80 | + const existing = comments.find(c => c.user.type === 'Bot' && c.body.includes('<!-- companion-pr-check -->')); |
| 81 | +
|
| 82 | + if (existing) { |
| 83 | + await github.rest.issues.updateComment({ |
| 84 | + owner: context.repo.owner, |
| 85 | + repo: context.repo.repo, |
| 86 | + comment_id: existing.id, |
| 87 | + body |
| 88 | + }); |
| 89 | + } else { |
| 90 | + await github.rest.issues.createComment({ |
| 91 | + owner: context.repo.owner, |
| 92 | + repo: context.repo.repo, |
| 93 | + issue_number: prNumber, |
| 94 | + body |
| 95 | + }); |
| 96 | + } |
0 commit comments