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