|
| 1 | +name: PR Title Check |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +jobs: |
| 7 | + pr_title_format_check: |
| 8 | + runs-on: ubuntu-22.04 |
| 9 | + permissions: |
| 10 | + pull-requests: write |
| 11 | + steps: |
| 12 | + - name: Check PR Title is Prefixed with Change Type |
| 13 | + id: check_prefix |
| 14 | + continue-on-error: true |
| 15 | + env: |
| 16 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 17 | + run: | |
| 18 | + if [[ "$PR_TITLE" =~ ^(Fix|Update|New|Breaking|Docs|Build|Upgrade|Chore):.*$ ]]; then |
| 19 | + echo "PR title is prefixed with change type." |
| 20 | + else |
| 21 | + echo "PR title is not prefixed with change type." |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | +
|
| 25 | + - name: Check PR Title contains Ticket/Dependabot Reference |
| 26 | + id: check_ticket_reference |
| 27 | + continue-on-error: true |
| 28 | + env: |
| 29 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 30 | + run: | |
| 31 | + if [[ "$PR_TITLE" =~ ^.*:.*\[([A-Z]+-[0-9]+|dependabot)\].*-.*$ ]]; then |
| 32 | + echo "PR title contains ticket or dependabot reference." |
| 33 | + else |
| 34 | + echo "PR title does not contain ticket or dependabot reference." |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Extract Ticket Reference |
| 39 | + id: extract_ticket_reference |
| 40 | + if: steps.check_ticket_reference.outcome == 'success' |
| 41 | + env: |
| 42 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 43 | + run: | |
| 44 | + if [[ "$PR_TITLE" =~ ^.*:.*\[([A-Z]+-[0-9]+|dependabot)\].*-.*$ ]]; then |
| 45 | + TICKET_REF="${BASH_REMATCH[1]}" |
| 46 | + echo "Extracted ticket reference: $TICKET_REF" |
| 47 | + echo "TICKET_REF=$TICKET_REF" > "$GITHUB_OUTPUT" |
| 48 | + else |
| 49 | + echo "No ticket reference found." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Comment on PR with Jira Link |
| 54 | + if: steps.extract_ticket_reference.outcome == 'success' && steps.extract_ticket_reference.outputs.TICKET_REF != 'dependabot' |
| 55 | + uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + TICKET_REF: ${{ steps.extract_ticket_reference.outputs.TICKET_REF }} |
| 59 | + with: |
| 60 | + message: | |
| 61 | + This PR is linked to a ticket in an NHS Digital JIRA Project. Here's a handy link to the ticket: |
| 62 | + # [${{ env.TICKET_REF }}](https://nhsd-jira.digital.nhs.uk/browse/${{ env.TICKET_REF }}) |
| 63 | + comment-tag: pr-link |
| 64 | + |
| 65 | + - name: Comment on PR for dependabot |
| 66 | + if: steps.extract_ticket_reference.outcome == 'success' && steps.extract_ticket_reference.outputs.TICKET_REF == 'dependabot' |
| 67 | + uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + with: |
| 71 | + message: | |
| 72 | + This PR is raised by Dependabot to update a dependency. |
| 73 | + comment-tag: pr-link |
| 74 | + |
| 75 | + - name: Comment on PR for bad format |
| 76 | + if: steps.check_prefix.outcome != 'success' || steps.check_ticket_reference.outcome != 'success' |
| 77 | + uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b |
| 78 | + env: |
| 79 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + with: |
| 81 | + message: | |
| 82 | + The PR title does not conform to the required format. |
| 83 | + Please ensure your PR title is prefixed with a change type (Fix, Update, New, Breaking, Docs, Build, Upgrade, Chore) |
| 84 | + and contains a ticket reference (eg. 'Fix: [AEA-####] - ...', or 'Chore: [dependabot] - ...'), |
| 85 | + then push an empty commit or recreate your PR. |
| 86 | + See the contributing guide for more details: |
| 87 | + https://github.com/NHSDigital/eps-common-workflows/blob/main/CONTRIBUTING.md |
| 88 | + comment-tag: pr-link |
0 commit comments