Skip to content

Commit 176b18c

Browse files
committed
sync workflow
1 parent e9806f2 commit 176b18c

2 files changed

Lines changed: 99 additions & 41 deletions

File tree

.github/workflows/pr_title_check.yml

Lines changed: 88 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,91 @@ on:
44
workflow_call:
55

66
jobs:
7-
sync:
8-
runs-on: ubuntu-latest
9-
permissions:
10-
contents: write
11-
pull-requests: write
12-
13-
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
16-
with:
17-
ref: ${{ env.BRANCH_NAME }}
18-
fetch-depth: 0
19-
20-
- name: Fetch central instructions
21-
run: |
22-
rm -rf .github/copilot
23-
git clone \
24-
--depth 1 \
25-
--branch "copilot" \
26-
https://github.com/NHSDigital/eps-common-workflows.git tmp
27-
mv tmp/.github/chatmodes .github/chatmodes
28-
mv tmp/.github/instructions .github/instructions
29-
mv tmp/.github/copilot-instructions.md .github/copilot-instructions.md
30-
rm -rf tmp
31-
32-
- name: Create PR
33-
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0
34-
with:
35-
commit-message: "Upgrade [dependabot] - sync Copilot instructions"
36-
title: "Upgrade [dependabot] - sync Copilot instructions"
37-
body: |
38-
Syncing Copilot instructions from central repo.
39-
Ref: `${{ inputs.ref }}`
40-
branch: copilot-instructions-sync
41-
branch-suffix: random
42-
sign-commits: true
43-
delete-branch: true
44-
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
89+
90+
- name: Fail job due to invalid PR title format
91+
if: steps.check_prefix.outcome != 'success' || steps.check_ticket_reference.outcome != 'success'
92+
run: |
93+
echo "Job failed due to invalid PR title format."
94+
exit 1

.github/workflows/sync_copilot.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Sync copilot instructions
22

33
on:
44
workflow_call:
5+
inputs:
6+
ref:
7+
description: 'The branch to sync from the central repository'
8+
required: false
9+
default: 'main'
10+
type: string
511

612
jobs:
713
sync:
@@ -22,18 +28,20 @@ jobs:
2228
rm -rf .github/copilot
2329
git clone \
2430
--depth 1 \
25-
--branch "copilot" \
31+
--branch $[BRANCH_NAME}" \
2632
https://github.com/NHSDigital/eps-common-workflows.git tmp
2733
mv tmp/.github/chatmodes .github/chatmodes
2834
mv tmp/.github/instructions .github/instructions
2935
mv tmp/.github/copilot-instructions.md .github/copilot-instructions.md
3036
rm -rf tmp
37+
env:
38+
BRANCH_NAME: ${{ inputs.ref }}
3139

3240
- name: Create PR
3341
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0
3442
with:
35-
commit-message: "Upgrade [dependabot] - sync Copilot instructions"
36-
title: "Upgrade [dependabot] - sync Copilot instructions"
43+
commit-message: "Upgrade: [dependabot] - sync Copilot instructions"
44+
title: "Upgrade: [dependabot] - sync Copilot instructions"
3745
body: |
3846
Syncing Copilot instructions from central repo.
3947
Ref: `${{ inputs.ref }}`

0 commit comments

Comments
 (0)