From 3cc7cd8bf331634a570ac0fea6bfdea161382093 Mon Sep 17 00:00:00 2001 From: Jack Wainwright <79214177+nhsd-jack-wainwright@users.noreply.github.com> Date: Mon, 9 Mar 2026 15:17:41 +0000 Subject: [PATCH 1/7] [CDAPI-125]: Added new action to run SonarCloud analysis against main branch --- .../workflows/update-sonar-statistics.yaml | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 .github/workflows/update-sonar-statistics.yaml diff --git a/.github/workflows/update-sonar-statistics.yaml b/.github/workflows/update-sonar-statistics.yaml new file mode 100644 index 0000000..20e5fd4 --- /dev/null +++ b/.github/workflows/update-sonar-statistics.yaml @@ -0,0 +1,103 @@ +name: "Update Sonar Statistics" + +on: + push: + branches: + - "feature/CDAPI-125" # Temporary whilst testing changes + +env: + PYTHON_VERSION: 3.14 + +jobs: + run-tests: + name: "Run Tests" + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: "Checkout code" + uses: actions/checkout@v6 + + - name: Set up Python + uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 + with: + python-version: "${{ env.PYTHON_VERSION }}" + + - name: Setup Python project + uses: ./.github/actions/setup-python-project + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: "Create coverage artefact name" + id: create-name + uses: ./.github/actions/create-artefact-name + with: + prefix: coverage + + - name: "Run unit tests" + uses: ./.github/actions/run-test-suite + with: + test-type: unit + env: local + + merge-test-coverage: + name: "Merge test coverage" + needs: run-tests + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: "Checkout code" + uses: actions/checkout@v6 + + - name: Setup Python project + uses: ./.github/actions/setup-python-project + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: "Download all test coverage artefacts" + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 + with: + path: pathology-api/test-artefacts/ + merge-multiple: false + + - name: "Merge coverage data" + run: make test-coverage + + - name: "Rename coverage XML with unique name" + run: | + cd pathology-api/test-artefacts + mv coverage-merged.xml "${{ steps.create-name.outputs.artefact-name }}.xml" + + - name: "Upload combined coverage report" + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 + with: + name: ${{ steps.create-name.outputs.artefact-name }} + path: pathology-api/test-artefacts + retention-days: 30 + + sonarcloud-analysis: + name: "SonarCloud Analysis" + needs: [run-tests, merge-test-coverage] + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: "Checkout code" + uses: actions/checkout@v6 + with: + fetch-depth: 0 # Fetch all history for accurate SonarCloud analysis + + - name: "Download merged coverage report" + uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 + with: + name: ${{ steps.create-name.outputs.artefact-name }} + path: coverage-reports/ + + - name: "SonarCloud Scan" + uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 #7.0.0 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.organization=${{ vars.SONAR_ORGANISATION_KEY }} + -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} + -Dsonar.python.coverage.reportPaths=coverage-reports/${{ steps.create-name.outputs.artefact-name }}.xml + From 2f3c2707f62dc1727698f81448a0b4da7bef1e50 Mon Sep 17 00:00:00 2001 From: Jack Wainwright <79214177+nhsd-jack-wainwright@users.noreply.github.com> Date: Mon, 9 Mar 2026 15:35:35 +0000 Subject: [PATCH 2/7] [CDAPI-125]: Combined merge-test-coverage stage into run-tests --- .github/workflows/update-sonar-statistics.yaml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/.github/workflows/update-sonar-statistics.yaml b/.github/workflows/update-sonar-statistics.yaml index 20e5fd4..7e29302 100644 --- a/.github/workflows/update-sonar-statistics.yaml +++ b/.github/workflows/update-sonar-statistics.yaml @@ -12,7 +12,7 @@ jobs: run-tests: name: "Run Tests" runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 10 steps: - name: "Checkout code" uses: actions/checkout@v6 @@ -39,20 +39,6 @@ jobs: test-type: unit env: local - merge-test-coverage: - name: "Merge test coverage" - needs: run-tests - runs-on: ubuntu-latest - timeout-minutes: 2 - steps: - - name: "Checkout code" - uses: actions/checkout@v6 - - - name: Setup Python project - uses: ./.github/actions/setup-python-project - with: - python-version: ${{ env.PYTHON_VERSION }} - - name: "Download all test coverage artefacts" uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0 with: From c8379dd1233b5ad6bb3dce2e33c0c487fa922431 Mon Sep 17 00:00:00 2001 From: Jack Wainwright <79214177+nhsd-jack-wainwright@users.noreply.github.com> Date: Mon, 9 Mar 2026 15:39:24 +0000 Subject: [PATCH 3/7] [CDAPI-125]: Fixed stage dependency issue --- .github/workflows/update-sonar-statistics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-sonar-statistics.yaml b/.github/workflows/update-sonar-statistics.yaml index 7e29302..1bb9c83 100644 --- a/.github/workflows/update-sonar-statistics.yaml +++ b/.github/workflows/update-sonar-statistics.yaml @@ -62,7 +62,7 @@ jobs: sonarcloud-analysis: name: "SonarCloud Analysis" - needs: [run-tests, merge-test-coverage] + needs: run-tests runs-on: ubuntu-latest timeout-minutes: 5 steps: From 7054005357996a35321a20b3882dfdd3e109ef06 Mon Sep 17 00:00:00 2001 From: Jack Wainwright <79214177+nhsd-jack-wainwright@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:41:18 +0000 Subject: [PATCH 4/7] [CDAPI-125]: Removed dependency on test-coverage Make target --- .github/workflows/update-sonar-statistics.yaml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-sonar-statistics.yaml b/.github/workflows/update-sonar-statistics.yaml index 1bb9c83..5455921 100644 --- a/.github/workflows/update-sonar-statistics.yaml +++ b/.github/workflows/update-sonar-statistics.yaml @@ -45,12 +45,17 @@ jobs: path: pathology-api/test-artefacts/ merge-multiple: false - - name: "Merge coverage data" - run: make test-coverage - - - name: "Rename coverage XML with unique name" + - name: "Build coverage XML report" run: | cd pathology-api/test-artefacts + ls -lth + mv coverage.unit .coverage.unit + + cd .. + poetry run coverage combine test-artefacts + poetry run coverage report + poetry run coverage xml -o coverage-merged.xml + mv coverage-merged.xml "${{ steps.create-name.outputs.artefact-name }}.xml" - name: "Upload combined coverage report" From 7eabe749347c5b0c5e6e96f55b4c6729c45ace0e Mon Sep 17 00:00:00 2001 From: Jack Wainwright <79214177+nhsd-jack-wainwright@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:56:06 +0000 Subject: [PATCH 5/7] [CDAPI-125]: Updated workflow to target main branch. --- .github/workflows/update-sonar-statistics.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/update-sonar-statistics.yaml b/.github/workflows/update-sonar-statistics.yaml index 5455921..e30c0e0 100644 --- a/.github/workflows/update-sonar-statistics.yaml +++ b/.github/workflows/update-sonar-statistics.yaml @@ -3,7 +3,7 @@ name: "Update Sonar Statistics" on: push: branches: - - "feature/CDAPI-125" # Temporary whilst testing changes + - "main" env: PYTHON_VERSION: 3.14 @@ -48,7 +48,6 @@ jobs: - name: "Build coverage XML report" run: | cd pathology-api/test-artefacts - ls -lth mv coverage.unit .coverage.unit cd .. From b23bf2b0fab3698779bd4113b1cd1ad206eb15ec Mon Sep 17 00:00:00 2001 From: Jack Wainwright <79214177+nhsd-jack-wainwright@users.noreply.github.com> Date: Tue, 10 Mar 2026 09:24:54 +0000 Subject: [PATCH 6/7] [CDAPI-125]: Added condition to sonar steps to not run against commits created by dependabot --- .github/workflows/preview-env.yaml | 2 +- .github/workflows/update-sonar-statistics.yaml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-env.yaml b/.github/workflows/preview-env.yaml index 0e6238c..e96ab95 100644 --- a/.github/workflows/preview-env.yaml +++ b/.github/workflows/preview-env.yaml @@ -495,7 +495,7 @@ jobs: name: ${{ steps.create-name.outputs.artefact-name }} path: coverage-reports/ - name: "SonarCloud Scan" - if: always() && github.event.action != 'closed' + if: always() && github.event.action != 'closed' && github.actor != 'dependabot[bot]' uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 #7.0.0 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/update-sonar-statistics.yaml b/.github/workflows/update-sonar-statistics.yaml index e30c0e0..b2cbe0b 100644 --- a/.github/workflows/update-sonar-statistics.yaml +++ b/.github/workflows/update-sonar-statistics.yaml @@ -3,7 +3,7 @@ name: "Update Sonar Statistics" on: push: branches: - - "main" + - "feature/CDAPI-125" env: PYTHON_VERSION: 3.14 @@ -11,6 +11,7 @@ env: jobs: run-tests: name: "Run Tests" + if: github.actor != 'dependabot[bot]' runs-on: ubuntu-latest timeout-minutes: 10 steps: @@ -67,6 +68,7 @@ jobs: sonarcloud-analysis: name: "SonarCloud Analysis" needs: run-tests + if: github.actor != 'dependabot[bot]' runs-on: ubuntu-latest timeout-minutes: 5 steps: From bede86006bb5c468bce8ee477b5ffffbfa59c9cd Mon Sep 17 00:00:00 2001 From: Jack Wainwright <79214177+nhsd-jack-wainwright@users.noreply.github.com> Date: Tue, 10 Mar 2026 10:04:50 +0000 Subject: [PATCH 7/7] [CDAPI-125]: Updated branch back to main --- .github/workflows/update-sonar-statistics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-sonar-statistics.yaml b/.github/workflows/update-sonar-statistics.yaml index b2cbe0b..d726d7b 100644 --- a/.github/workflows/update-sonar-statistics.yaml +++ b/.github/workflows/update-sonar-statistics.yaml @@ -3,7 +3,7 @@ name: "Update Sonar Statistics" on: push: branches: - - "feature/CDAPI-125" + - "main" env: PYTHON_VERSION: 3.14