Skip to content

Commit b3e84ef

Browse files
DMCAW-12119: merge test suite and sonarqube jobs (#811)
1 parent 2a448eb commit b3e84ef

9 files changed

Lines changed: 79 additions & 234 deletions

.github/workflows/backend-api-post-merge.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,15 @@ jobs:
3838
with:
3939
PRIVATE_PACKAGES_REQUIRED: true
4040
RUN_PACT_TESTS: true
41+
SONARQUBE_CONTINUE_ON_ERROR: true
4142
WORKING_DIRECTORY: backend-api
4243
secrets: inherit
4344

44-
sonarqube-scan:
45-
name: Pre-deployment
46-
needs: run-test-suite
47-
with:
48-
CONTINUE_ON_ERROR: true
49-
WORKING_DIRECTORY: backend-api
50-
uses:
51-
./.github/workflows/job_sonarqube.yml
52-
secrets: inherit
53-
5445
push-docker-image-dev:
5546
name: Dev
5647
needs:
5748
- ci-checks
58-
- sonarqube-scan
49+
- run-test-suite
5950
uses:
6051
./.github/workflows/job_push-docker-image.yml
6152
with:
@@ -83,7 +74,7 @@ jobs:
8374
name: Build
8475
needs:
8576
- ci-checks
86-
- sonarqube-scan
77+
- run-test-suite
8778
uses:
8879
./.github/workflows/job_push-docker-image.yml
8980
with:

.github/workflows/backend-api-pull-request.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: backend-api pull request
1+
name: Backend API Pull Request
22
on:
33
pull_request:
44
branches:
@@ -14,7 +14,6 @@ on:
1414
- ".github/workflows/workflow_pull-request.yml"
1515
- ".github/workflows/job_ci-checks.yml"
1616
- ".github/workflows/job_test-suite.yml"
17-
- ".github/workflows/job_sonarqube.yml"
1817
- "!backend-api/**/*.md"
1918
- "!backend-api/**/*.png"
2019

@@ -24,13 +23,22 @@ permissions:
2423
packages: read
2524

2625
jobs:
27-
backend-api-pull-request:
28-
name: Backend-api pull request checks
26+
ci-checks:
27+
name: CI checks
2928
if: github.event.pull_request.draft == false
3029
uses:
31-
./.github/workflows/workflow_pull-request.yml
30+
./.github/workflows/job_ci-checks.yml
3231
with:
32+
PRIVATE_PACKAGES_REQUIRED: true
3333
WORKING_DIRECTORY: backend-api
34+
35+
run-test-suite:
36+
name: Run test suite
37+
needs: ci-checks
38+
uses:
39+
./.github/workflows/job_test-suite.yml
40+
with:
3441
PRIVATE_PACKAGES_REQUIRED: true
3542
RUN_PACT_TESTS: true
36-
secrets: inherit
43+
WORKING_DIRECTORY: backend-api
44+
secrets: inherit

.github/workflows/helper-scripts-pull-request.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: helper-scripts pull request
1+
name: Helper Scripts Pull Request
22
on:
33
pull_request:
44
branches:
@@ -18,8 +18,9 @@ on:
1818
workflow_dispatch:
1919

2020
jobs:
21-
helper-script-ci-checks:
22-
name: Helper script CI checks
21+
ci-checks:
22+
name: CI checks
23+
if: github.event.pull_request.draft == false
2324
uses:
2425
./.github/workflows/job_ci-checks.yml
2526
with:

.github/workflows/job_ci-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
- name: Validate SAM template
9595
if: inputs.RUN_SAM_VALIDATE == 'true'
9696
run: |
97-
TEMPLATES="$(find . -name template.yaml)"
97+
TEMPLATES="$(find . -name "template*.yaml")"
9898
for template in $TEMPLATES ; do
9999
sam validate --lint --template-file $template
100100
done

.github/workflows/job_sonarqube.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/job_test-suite.yml

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
description: Whether to run unit tests using `test:unit` npm script
1616
type: string
1717
default: true
18+
SONARQUBE_CONTINUE_ON_ERROR:
19+
description: Whether to continue running the workflow if SonarQube quality gate fails
20+
type: string
21+
default: false
1822
WORKING_DIRECTORY:
1923
description: Path to working directory in repo
2024
required: true
@@ -27,57 +31,56 @@ on:
2731
description: Whether to run pact tests using `test:pact:ci` npm script
2832
type: string
2933
default: false
34+
secrets:
35+
SONAR_TOKEN:
36+
description: The token used for secure access to the SonarQube platform
37+
required: false
3038

3139
jobs:
3240
run-test-suite:
33-
name: Run test suite and upload coverage artifact
41+
name: Run test suite and SonarQube
3442
runs-on: ubuntu-24.04
3543
defaults:
3644
run:
3745
shell: bash
3846
working-directory: ${{ inputs.WORKING_DIRECTORY }}
47+
env:
48+
CONTINUE_ON_ERROR: ${{ inputs.SONARQUBE_CONTINUE_ON_ERROR }}
3949
steps:
40-
- name: Check out repository code
50+
- name: Checkout Repository
4151
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4252
with:
53+
fetch-depth: 0
4354
submodules: true
4455

45-
- name: Setup nodeJS
56+
- name: Setup NodeJS
4657
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
4758
with:
4859
cache: npm
4960
cache-dependency-path: ${{ inputs.WORKING_DIRECTORY }}/package-lock.json
5061
node-version-file: ${{ inputs.WORKING_DIRECTORY }}/.nvmrc
5162

52-
- name: Configure authentication for private packages in .npmrc
53-
if: inputs.PRIVATE_PACKAGES_REQUIRED == 'true'
63+
- name: Configure Authentication for Private Packages in .npmrc
64+
if: inputs.GENERATE_OPEN_PROXY_API_SPEC == 'true'
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5467
run: |
5568
echo "engine-strict=true" > .npmrc
5669
echo "@govuk-one-login:registry=https://npm.pkg.github.com/" >> .npmrc
5770
echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" >> .npmrc
58-
env:
59-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6071
61-
- name: Install dependencies
72+
- name: Install Dependencies
6273
run: npm clean-install
6374

64-
- name: Run unit tests
75+
- name: Run Unit Tests
6576
if: inputs.RUN_UNIT_TESTS == 'true'
6677
run: npm run test:unit
6778

68-
- name: Upload unit test coverage artifact for SonarQube scan
69-
if: inputs.RUN_SONARQUBE == 'true'
70-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
71-
with:
72-
name: test-coverage
73-
path: ${{ inputs.WORKING_DIRECTORY }}/coverage/
74-
retention-days: 1
75-
76-
- name: Run infra tests
79+
- name: Run Infra Tests
7780
if: inputs.RUN_INFRA_TESTS == 'true'
7881
run: npm run test:infra
7982

80-
- name: Run pact tests
83+
- name: Run Pact Tests
8184
if: inputs.RUN_PACT_TESTS == 'true'
8285
continue-on-error: true # Pact tests are currently failing - remove step once fixed
8386
env:
@@ -87,3 +90,22 @@ jobs:
8790
PACT_BROKER_SOURCE_SECRET: ${{ secrets.PACT_BROKER_SOURCE_SECRET }}
8891
PUBLISH_PACT_VERIFICATION_RESULTS: "false"
8992
run: npm run test:pact:ci
93+
94+
- name: Run SonarQube Scan
95+
if: inputs.RUN_SONARQUBE == 'true'
96+
uses: sonarsource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 #v5.3.0
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
100+
with:
101+
projectBaseDir: ${{ inputs.WORKING_DIRECTORY }}
102+
103+
- name: Run SonarQube Quality Gate Check
104+
if: inputs.RUN_SONARQUBE == 'true'
105+
uses: Sonarsource/sonarqube-quality-gate-action@8406f4f1edaffef38e9fb9c53eb292fc1d7684fa #master
106+
continue-on-error: ${{ fromJSON(env.CONTINUE_ON_ERROR) }}
107+
timeout-minutes: 5
108+
env:
109+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
110+
with:
111+
scanMetadataReportFile: ${{ inputs.WORKING_DIRECTORY }}/.scannerwork/report-task.txt

.github/workflows/test-resources-post-merge.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,19 @@ jobs:
3131

3232
run-test-suite:
3333
name: Pre-deployment
34+
needs: ci-checks
3435
uses:
3536
./.github/workflows/job_test-suite.yml
3637
with:
38+
SONARQUBE_CONTINUE_ON_ERROR: true
3739
WORKING_DIRECTORY: test-resources
38-
39-
sonarqube-scan:
40-
name: Pre-deployment
41-
needs: run-test-suite
42-
with:
43-
CONTINUE_ON_ERROR: true
44-
WORKING_DIRECTORY: test-resources
45-
uses:
46-
./.github/workflows/job_sonarqube.yml
4740
secrets: inherit
4841

4942
push-docker-image-dev:
5043
name: Dev
5144
needs:
5245
- ci-checks
53-
- sonarqube-scan
46+
- run-test-suite
5447
uses:
5548
./.github/workflows/job_push-docker-image.yml
5649
with:
@@ -76,7 +69,7 @@ jobs:
7669
name: Build
7770
needs:
7871
- ci-checks
79-
- sonarqube-scan
72+
- run-test-suite
8073
uses:
8174
./.github/workflows/job_push-docker-image.yml
8275
with:

.github/workflows/test-resources-pull-request.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: test-resources pull request
1+
name: Test Resources Pull Request
22
on:
33
pull_request:
44
branches:
@@ -14,18 +14,25 @@ on:
1414
- ".github/workflows/workflow_pull-request.yml"
1515
- ".github/workflows/job_ci-checks.yml"
1616
- ".github/workflows/job_test-suite.yml"
17-
- ".github/workflows/job_sonarqube.yml"
1817
- "!test-resources/**/*.md"
1918
- "!test-resources/**/*.png"
2019

2120
workflow_dispatch:
2221

2322
jobs:
24-
test-resources-pull-request:
25-
name: Test resources pull request checks
23+
ci-checks:
24+
name: CI checks
2625
if: github.event.pull_request.draft == false
2726
uses:
28-
./.github/workflows/workflow_pull-request.yml
27+
./.github/workflows/job_ci-checks.yml
28+
with:
29+
WORKING_DIRECTORY: test-resources
30+
31+
run-test-suite:
32+
name: Run test suite
33+
needs: ci-checks
34+
uses:
35+
./.github/workflows/job_test-suite.yml
2936
with:
3037
WORKING_DIRECTORY: test-resources
3138
secrets: inherit

0 commit comments

Comments
 (0)