Skip to content

Commit 0f36cea

Browse files
authored
#157 fix: add CodeScene PR coverage gates (#158)
- add a reusable check-coverage action for cs-coverage check - run CodeScene coverage gates on pull requests in Tests.yml - keep the existing develop/manual CodeScene analysis flow - document the new PR gate behavior in the contributor docs and changelog
1 parent 29cd5fb commit 0f36cea

4 files changed

Lines changed: 69 additions & 5 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Check Coverage
2+
description: Run CodeScene coverage gates against uploaded coverage artifacts.
3+
4+
inputs:
5+
access-token:
6+
description: CodeScene REST API access token.
7+
required: true
8+
project-url:
9+
description: Full CodeScene project API URL, for example https://codescene.io/v2/projects/12345.
10+
required: true
11+
coverage-files:
12+
description: Glob pattern matching coverage reports to check.
13+
required: true
14+
15+
runs:
16+
using: composite
17+
steps:
18+
- name: Download cs-coverage binary
19+
shell: bash
20+
run: |
21+
set -euo pipefail
22+
curl -fsSL -o "$(pwd)/cs-coverage.zip" https://downloads.codescene.io/enterprise/cli/cs-coverage-linux-amd64-latest.zip
23+
unzip -oq "$(pwd)/cs-coverage.zip"
24+
chmod +x "$(pwd)/cs-coverage"
25+
26+
- name: Run CodeScene coverage gate check
27+
shell: bash
28+
env:
29+
CS_PROJECT_URL: ${{ inputs.project-url }}
30+
CS_ACCESS_TOKEN: ${{ inputs.access-token }}
31+
run: |
32+
set -euo pipefail
33+
find "$(pwd)" -name '*.cobertura.xml' -print
34+
"$(pwd)/cs-coverage" check --verbose --coverage-files "${{ inputs.coverage-files }}"

.github/workflows/Tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ jobs:
9292
with:
9393
token: ${{ secrets.CODECOV_TOKEN }}
9494

95+
codescene-coverage-gates:
96+
runs-on: ubuntu-latest
97+
needs:
98+
- test-and-coverage
99+
if: ${{ needs.test-and-coverage.result == 'success' && github.event_name == 'pull_request' }}
100+
steps:
101+
- name: Checkout
102+
uses: actions/checkout@v4
103+
with:
104+
fetch-depth: 0
105+
106+
- name: Download CI artifacts
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: nova-ci-artifacts
110+
path: coverage/
111+
112+
- name: Check coverage gates in CodeScene
113+
uses: ./.github/actions/check-coverage
114+
with:
115+
access-token: ${{ secrets.CS_ACCESS_TOKEN }}
116+
project-url: ${{ format('{0}/v2/projects/{1}', vars.CS_URL, vars.CS_PROJECT_ID) }}
117+
coverage-files: '**/pester-coverage.cobertura.xml'
118+
95119
codescene-analysis:
96120
runs-on: ubuntu-latest
97121
needs:

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Before making larger changes, read the contributor docs in:
3434
GitHub now prefills pull requests with `.github/pull_request_template.md`.
3535
Use it to explain intent clearly, record what you validated, and call out any required documentation or changelog work.
3636

37+
Pull requests against `main` and `develop` also run a CodeScene coverage-gate check when CI has produced the Cobertura coverage artifact, so PRs can be blocked when changed code falls below the configured coverage threshold.
38+
3739
**Before opening a pull request, please run the local quality flow from the repository root:**
3840

3941
```powershell title="run.ps1"
@@ -55,6 +57,7 @@ If you are working on the CodeScene integration, the CI coverage helper writes t
5557
CodeScene upload step consumes:
5658

5759
- generate coverage with `./scripts/build/ci/Invoke-NovaModuleToolsCI.ps1`
60+
- pull requests then download that uploaded artifact and run the CodeScene coverage-gate check through `.github/actions/check-coverage`
5861
- then upload/trigger with `./scripts/build/ci/Invoke-CodeSceneAnalysis.ps1 -UploadCoverage -TriggerAnalysis`
5962
- the upload helper auto-discovers a single `artifacts/*.cobertura.xml` file unless you pass `-CoveragePath`
6063
- if upload succeeds but `-TriggerAnalysis` fails with a project-owner OAuth error, re-authorize the repository in

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,11 @@ workflow configuration, and emits CI-friendly reports such as:
423423
- `artifacts/pester-coverage.cobertura.xml`
424424
- `artifacts/coverage-low.txt`
425425

426-
The `Tests.yml` workflow reuses that Cobertura artifact for both Codecov and CodeScene.
427-
The CodeScene step uploads coverage through `scripts/build/ci/Invoke-CodeSceneAnalysis.ps1` before it triggers a
428-
follow-up analysis run.
426+
The `Tests.yml` workflow reuses that Cobertura artifact for Codecov, for the pull-request CodeScene coverage-gate check,
427+
and for the develop/manual CodeScene upload-and-analysis flow.
428+
The CodeScene pull-request gate downloads the uploaded artifact and runs `cs-coverage check`, while the develop/manual
429+
CodeScene step uploads coverage through `scripts/build/ci/Invoke-CodeSceneAnalysis.ps1` before it triggers a follow-up
430+
analysis run.
429431
If coverage upload succeeds but the trigger fails with an OAuth/project-owner error, fix the repository authorization in
430432
CodeScene for the project owner. That trigger-side repository authorization is separate from `CS_ACCESS_TOKEN`.
431433

@@ -572,6 +574,8 @@ When CodeScene coverage upload is needed, run
572574
`scripts/build/ci/Invoke-CodeSceneAnalysis.ps1 -UploadCoverage -TriggerAnalysis`.
573575
That script auto-discovers a single `*.cobertura.xml` file under `artifacts/` unless you pass `-CoveragePath`
574576
explicitly.
577+
The repository `Tests.yml` workflow now also downloads that same Cobertura artifact during pull requests and runs the
578+
CodeScene coverage-gate check before merge.
575579
If `-TriggerAnalysis` fails after a successful upload, review the CodeScene response body: repository OAuth problems for
576580
the project owner must be fixed in CodeScene itself and are not solved by rotating `CS_ACCESS_TOKEN` alone.
577581

@@ -589,8 +593,7 @@ published module from the local install directory into the current PowerShell se
589593
step depends on the built-but-unpublished output instead.
590594

591595
The CI helper flow also produces JUnit and Cobertura artifacts for external systems, including the coverage file that
592-
the
593-
CodeScene workflow upload step consumes.
596+
the CodeScene workflow gate and upload steps consume.
594597

595598
### Release automation
596599

0 commit comments

Comments
 (0)