-
Notifications
You must be signed in to change notification settings - Fork 1
63 lines (57 loc) · 2.56 KB
/
pr_title_check.yml
File metadata and controls
63 lines (57 loc) · 2.56 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
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]+-0000)\].*-.*$ ]]; then
echo "PR title uses AEA-0000 placeholder. Please use 'adhoc' instead of 'AEA-0000' for adhoc changes."
exit 1
fi
if [[ "$PR_TITLE" =~ ^.*:.*\[([A-Z]+-[0-9]+|dependabot|adhoc)\].*-.*$ ]]; then
echo "PR title contains ticket reference, was raised by dependabot or is an adhoc change."
else
echo "PR title does not contain ticket reference, was not raised by dependabot, and is not an adhoc change."
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|adhoc)\].*-.*$ ]]; 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: 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