|
| 1 | +name: PR Requirements |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled, unlabeled, opened, edited, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + changelog-label: |
| 9 | + name: Changelog label |
| 10 | + runs-on: ubuntu-22.04 |
| 11 | + steps: |
| 12 | + - name: Require changelog label |
| 13 | + if: >- |
| 14 | + !contains(github.event.pull_request.labels.*.name, 'include-changelog') && |
| 15 | + !contains(github.event.pull_request.labels.*.name, 'exclude-changelog') |
| 16 | + run: | |
| 17 | + echo "::error::PR must have one of: include-changelog, exclude-changelog" |
| 18 | + echo "## :x: Missing changelog label" >> "$GITHUB_STEP_SUMMARY" |
| 19 | + echo "PR must have one of: \`include-changelog\`, \`exclude-changelog\`" >> "$GITHUB_STEP_SUMMARY" |
| 20 | + exit 1 |
| 21 | +
|
| 22 | + ai-authorship-label: |
| 23 | + name: AI authorship label |
| 24 | + runs-on: ubuntu-22.04 |
| 25 | + steps: |
| 26 | + - name: Require AI authorship label |
| 27 | + if: >- |
| 28 | + !contains(github.event.pull_request.labels.*.name, 'mostly-ai') && |
| 29 | + !contains(github.event.pull_request.labels.*.name, 'mostly-human') |
| 30 | + run: | |
| 31 | + echo "::error::PR must have one of: mostly-ai, mostly-human" |
| 32 | + echo "## :x: Missing AI authorship label" >> "$GITHUB_STEP_SUMMARY" |
| 33 | + echo "PR must have one of: \`mostly-ai\`, \`mostly-human\`" >> "$GITHUB_STEP_SUMMARY" |
| 34 | + exit 1 |
| 35 | +
|
| 36 | + linked-issue: |
| 37 | + name: Linked issue |
| 38 | + runs-on: ubuntu-22.04 |
| 39 | + if: >- |
| 40 | + !startsWith(github.head_ref, 'dependabot/') && |
| 41 | + !contains(github.event.pull_request.labels.*.name, 'minor-change') |
| 42 | + permissions: |
| 43 | + issues: read |
| 44 | + pull-requests: read |
| 45 | + steps: |
| 46 | + - name: Require linked issue |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ github.token }} |
| 49 | + run: | |
| 50 | + ISSUES=$(gh pr view ${{ github.event.pull_request.number }} \ |
| 51 | + --repo ${{ github.repository }} \ |
| 52 | + --json closingIssuesReferences \ |
| 53 | + -q '.closingIssuesReferences[].url') |
| 54 | + if [ -z "$ISSUES" ]; then |
| 55 | + echo "::error::PR must have a linked issue (e.g. 'Fixes #123' in description or link via Development sidebar)" |
| 56 | + echo "## :x: Missing linked issue" >> "$GITHUB_STEP_SUMMARY" |
| 57 | + echo "PR must have a linked issue." >> "$GITHUB_STEP_SUMMARY" |
| 58 | + echo "Use \`Fixes #123\` in the description or link via the Development sidebar." >> "$GITHUB_STEP_SUMMARY" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + echo "## :white_check_mark: Linked issues" >> "$GITHUB_STEP_SUMMARY" |
| 62 | + echo "$ISSUES" | while read -r url; do echo "- $url" >> "$GITHUB_STEP_SUMMARY"; done |
| 63 | +
|
| 64 | + all-pr-requirements: |
| 65 | + name: All PR requirements |
| 66 | + runs-on: ubuntu-22.04 |
| 67 | + if: always() |
| 68 | + needs: [changelog-label, ai-authorship-label, linked-issue] |
| 69 | + steps: |
| 70 | + - name: Verify all PR requirements passed |
| 71 | + if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') |
| 72 | + run: | |
| 73 | + echo "::error::Some PR requirements failed - see ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 74 | + exit 1 |
0 commit comments