88 BRANCH_NAME : ${{ github.event.pull_request.head.ref }}
99
1010jobs :
11- dependabot-auto-approve-and-merge :
12- needs : quality_checks
13- uses : NHSDigital/eps-common-workflows/.github/workflows/dependabot-auto-approve-and-merge.yml@b933ef1bb3527fd7e7d5a7629fbd4e4dd94bf1b4
14- secrets :
15- AUTOMERGE_APP_ID : ${{ secrets.AUTOMERGE_APP_ID }}
16- AUTOMERGE_PEM : ${{ secrets.AUTOMERGE_PEM }}
1711 get_asdf_version :
1812 runs-on : ubuntu-22.04
1913 outputs :
@@ -32,20 +26,105 @@ jobs:
3226 TAG_FORMAT=$(yq '.TAG_FORMAT' .github/config/settings.yml)
3327 echo "TAG_FORMAT=$TAG_FORMAT" >> "$GITHUB_OUTPUT"
3428
29+ get_commit_message :
30+ runs-on : ubuntu-22.04
31+ outputs :
32+ commit_message : ${{ steps.commit_message.outputs.commit_message }}
33+ steps :
34+ - name : Checkout code
35+ uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
36+ with :
37+ ref : ${{ env.BRANCH_NAME }}
38+ fetch-depth : 0
39+ - name : Get Commit message
40+ id : commit_message
41+ run : |
42+ echo "commit_message=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT"
43+
3544 quality_checks :
3645 uses : NHSDigital/eps-common-workflows/.github/workflows/quality-checks.yml@b933ef1bb3527fd7e7d5a7629fbd4e4dd94bf1b4
37- needs : [get_asdf_version]
46+ needs : [get_asdf_version, get_commit_message]
47+ if : ${{ ! contains(needs.get_commit_message.outputs.commit_message, '#skip-qc') }}
3848 with :
3949 asdfVersion : ${{ needs.get_asdf_version.outputs.asdf_version }}
4050 secrets :
4151 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
4252
53+ quality_gate :
54+ needs : get_commit_message
55+ runs-on : ubuntu-22.04
56+ if : always()
57+ steps :
58+ - name : Wait for quality checks to succeed
59+ if : ${{ ! contains(needs.get_commit_message.outputs.commit_message, '#skip-qc') }}
60+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
61+ with :
62+ github-token : ${{ secrets.GITHUB_TOKEN }}
63+ result-encoding : json
64+ script : |
65+ const owner = context.repo.owner;
66+ const repo = context.repo.repo;
67+ const runId = context.runId;
68+
69+ // How many times to poll
70+ const pollTime = 10000; // 10 seconds
71+ const maxRetries = 120; // 20 minutes at 10 seconds each
72+ let attempts = 0;
73+
74+ async function fetchQCJob() {
75+ const { data } = await github.rest.actions.listJobsForWorkflowRun({
76+ owner, repo, run_id: runId
77+ });
78+ return data.jobs.find(job => job.name === 'quality_checks / quality_checks');
79+ }
80+
81+ let qc = await fetchQCJob();
82+ while ((!qc || qc.status !== 'completed') && attempts < maxRetries) {
83+ attempts++;
84+ console.log(`Attempt #${attempts}: ` +
85+ (qc
86+ ? `found job "${qc.name}" with status=${qc.status}`
87+ : 'no matching quality_checks job yet'));
88+ await new Promise(r => setTimeout(r, pollTime));
89+ qc = await fetchQCJob();
90+ }
91+
92+ if (!qc) {
93+ core.setFailed(
94+ `Timed out waiting for a "quality_checks" job (after ${attempts} polls).`
95+ );
96+ return;
97+ }
98+
99+ if (qc.status !== 'completed') {
100+ core.setFailed(
101+ `Quality checks job never completed (last status=${qc.status}).`
102+ );
103+ return;
104+ }
105+
106+ if (qc.conclusion !== 'success') {
107+ core.setFailed(
108+ `Quality checks failed (conclusion=${qc.conclusion}).`
109+ );
110+ }
111+
112+ - name : Bypass QC gate
113+ if : ${{ contains(needs.get_commit_message.outputs.commit_message, '#skip-qc') }}
114+ run : echo "Skipping QC gate per commit message."
115+
116+ dependabot-auto-approve-and-merge :
117+ needs : quality_gate
118+ uses : NHSDigital/eps-common-workflows/.github/workflows/dependabot-auto-approve-and-merge.yml@b933ef1bb3527fd7e7d5a7629fbd4e4dd94bf1b4
119+ secrets :
120+ AUTOMERGE_APP_ID : ${{ secrets.AUTOMERGE_APP_ID }}
121+ AUTOMERGE_PEM : ${{ secrets.AUTOMERGE_PEM }}
122+
43123 pr_title_format_check :
44124 uses : NHSDigital/eps-common-workflows/.github/workflows/pr_title_check.yml@b933ef1bb3527fd7e7d5a7629fbd4e4dd94bf1b4
45125
46126 get_issue_number :
47127 runs-on : ubuntu-22.04
48- needs : quality_checks
49128 outputs :
50129 issue_number : ${{steps.get_issue_number.outputs.result}}
51130
@@ -71,7 +150,11 @@ jobs:
71150 result-encoding : string
72151
73152 package_code :
74- needs : [get_issue_number]
153+ needs : [get_issue_number, quality_gate]
154+ if : |
155+ always() &&
156+ ! contains(needs.*.result, 'failure') &&
157+ ! contains(needs.*.result, 'cancelled')
75158 uses : ./.github/workflows/cdk_package_code.yml
76159 with :
77160 STACK_NAME : epsam-pr-${{needs.get_issue_number.outputs.issue_number}}
@@ -80,6 +163,10 @@ jobs:
80163
81164 release_code :
82165 needs : [get_issue_number, package_code]
166+ if : |
167+ always() &&
168+ ! contains(needs.*.result, 'failure') &&
169+ ! contains(needs.*.result, 'cancelled')
83170 uses : ./.github/workflows/release_all_stacks.yml
84171 with :
85172 STACK_NAME : epsam-pr-${{needs.get_issue_number.outputs.issue_number}}
0 commit comments