Skip to content

Commit df578fd

Browse files
Merge pull request #1146 from NHSDigital/feature/made14-NRL-1922-sonarcloud-config-update
[NRL-1922] Get Sonarcloud reporting working as required
2 parents 051fdf3 + 7e81f3d commit df578fd

File tree

5 files changed

+129
-18
lines changed

5 files changed

+129
-18
lines changed

.github/workflows/daily-build.yml

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: Build NRL Project on Environment
22
run-name: Build NRL Project on ${{ inputs.environment || 'dev' }}
3-
permissions:
4-
id-token: write
5-
contents: read
6-
actions: write
73

84
on:
5+
push:
6+
branches:
7+
- develop
98
schedule:
109
- cron: "0 1 * * *"
1110
workflow_dispatch:
@@ -18,8 +17,12 @@ on:
1817

1918
jobs:
2019
build:
21-
name: Build - ${{ github.ref }}
20+
name: Build and test - ${{ github.ref }}
2221
runs-on: codebuild-nhsd-nrlf-ci-build-project-${{ github.run_id }}-${{ github.run_attempt }}
22+
permissions:
23+
contents: read
24+
actions: write
25+
id-token: write
2326

2427
steps:
2528
- name: Git clone - ${{ github.ref }}
@@ -35,12 +38,12 @@ jobs:
3538
- name: Run Linting
3639
run: make lint
3740

38-
- name: Run Unit Tests
39-
run: make test
40-
4141
- name: Build Project
4242
run: make build
4343

44+
- name: Run Unit Tests
45+
run: make test
46+
4447
- name: Configure Management Credentials
4548
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a #v4.3.1
4649
with:
@@ -60,10 +63,43 @@ jobs:
6063
name: build-artifacts
6164
path: |
6265
dist/*.zip
66+
dist/test-coverage.xml
6367
!dist/nrlf_permissions.zip
6468
6569
- name: Save NRLF Permissions cache
6670
uses: actions/cache/save@v4
6771
with:
6872
key: ${{ github.run_id }}-nrlf-permissions
6973
path: dist/nrlf_permissions.zip
74+
75+
sonar:
76+
name: SonarQube scan
77+
runs-on: ubuntu-latest
78+
needs: build
79+
environment: pull-request
80+
permissions:
81+
contents: read
82+
actions: write
83+
steps:
84+
- uses: actions/checkout@v4
85+
with:
86+
ref: ${{ github.ref }}
87+
88+
- name: Get build artifacts
89+
uses: actions/download-artifact@v4
90+
with:
91+
name: build-artifacts
92+
path: dist
93+
94+
- name: SonarQube scan
95+
uses: sonarsource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 #v7.0.0
96+
env:
97+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
98+
99+
- name: SonarQube quality gate check
100+
id: sonarqube-quality-gate-check
101+
uses: sonarsource/sonarqube-quality-gate-action@cf038b0e0cdecfa9e56c198bbb7d21d751d62c3b #v1.2.0
102+
with:
103+
pollingTimeoutSec: 600
104+
env:
105+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/pr-checks.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Run PR checks
2+
run-name: "Running checks for PR #${{ github.event.pull_request.number }} (${{ github.event.pull_request.title }})"
3+
4+
on:
5+
pull_request:
6+
types: [opened, reopened, synchronize]
7+
8+
jobs:
9+
build:
10+
name: Build and test
11+
runs-on: codebuild-nhsd-nrlf-ci-build-project-${{ github.run_id }}-${{ github.run_attempt }}
12+
environment: pull-request
13+
permissions:
14+
contents: read
15+
actions: write
16+
17+
steps:
18+
- name: Git clone - ${{ github.ref }}
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.ref }}
22+
23+
- name: Setup environment
24+
run: |
25+
echo "${HOME}/.asdf/bin" >> $GITHUB_PATH
26+
poetry install --no-root
27+
28+
- name: Lint
29+
run: make lint
30+
31+
- name: Build
32+
run: make build
33+
34+
- name: Test
35+
run: make test
36+
37+
- name: Upload build artifacts
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: build-artifacts
41+
path: dist
42+
43+
sonar:
44+
name: SonarQube scan
45+
runs-on: ubuntu-latest
46+
needs: build
47+
environment: pull-request
48+
permissions:
49+
contents: read
50+
actions: write
51+
steps:
52+
- uses: actions/checkout@v4
53+
with:
54+
ref: ${{ github.ref }}
55+
56+
- name: Get build artifacts
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: build-artifacts
60+
path: dist
61+
62+
- name: SonarQube scan
63+
uses: sonarsource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 #v7.0.0
64+
env:
65+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
66+
67+
- name: SonarQube quality gate check
68+
id: sonarqube-quality-gate-check
69+
uses: sonarsource/sonarqube-quality-gate-action@cf038b0e0cdecfa9e56c198bbb7d21d751d62c3b #v1.2.0
70+
with:
71+
pollingTimeoutSec: 600
72+
env:
73+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MAKEFLAGS := --no-print-directory
66
SHELL := /bin/bash
77

88
DIST_PATH ?= ./dist
9-
TEST_ARGS ?= --cov --cov-report=term-missing
9+
TEST_ARGS ?= --cov --cov-report=term-missing --cov-report=xml:$(DIST_PATH)/test-coverage.xml
1010
SMOKE_TEST_ARGS ?=
1111
FEATURE_TEST_ARGS ?= ./tests/features --format progress2
1212
TF_WORKSPACE_NAME ?= $(shell terraform -chdir=terraform/infrastructure workspace show)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ docstring-code-format = true
8686
docstring-code-line-length = 80
8787

8888
[tool.coverage.run]
89+
relative_files = true
8990
branch = true
9091
omit = [
9192
"*/tests/*",

sonar-project.properties

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
sonar.projectKey=NHSDigital_NRLF
22
sonar.organization=nhsdigital
33
sonar.projectName=NRLF
4-
sonar.python.version=3.9.5
5-
sonar.terraform.provider.aws.version=4.63.0
6-
# TODO: Some paths here are outdated and perhaps we don't want to exclude everything
7-
sonar.cpd.exclusions=api/tests/**, tests/**, api/**/tests/**, feature_tests/**, cron/seed_sandbox/tests/**, data_contracts/**/tests/**, firehose/**/tests/**, firehose/**/scripts/**, helpers/tests/**, mi/**/tests/**
8-
sonar.exclusions=scripts/**, **/scripts/**, api/tests/**, tests/**, api/**/tests/**, feature_tests/**, cron/seed_sandbox/tests/**, data_contracts/**/tests/**, firehose/**/tests/**, firehose/**/scripts/**, helpers/tests/**, mi/**/tests/**
94

10-
# Exclude snomed urls as being unsafe
11-
sonar.issue.ignore.multicriteria=exclude_snomed_urls
12-
sonar.issue.ignore.multicriteria.exclude_snomed_urls.ruleKey=python:S5332
13-
sonar.issue.ignore.multicriteria.exclude_snomed_urls.pattern=**http://snomed\.info(/sct)?**
5+
sonar.python.version=3.12
6+
7+
sonar.sources=.
8+
sonar.exclusions=scripts/**
9+
sonar.tests=.
10+
sonar.tests.inclusions=**/tests/**
11+
sonar.coverage.exclusions=scripts/**, tests/**, **/tests/**
12+
sonar.cpd.exclusions=tests/**, **/tests/**
13+
14+
sonar.python.coverage.reportPaths=dist/test-coverage.xml

0 commit comments

Comments
 (0)