Skip to content

Commit 14e5da0

Browse files
authored
ci: upload Go test coverage to GitHub code coverage API (#35360)
1 parent 96df9a8 commit 14e5da0

1 file changed

Lines changed: 78 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
timeout-minutes: 25
3333
permissions:
3434
contents: read
35+
code-quality: write
36+
pull-requests: read
3537
strategy:
3638
fail-fast: false
3739
matrix:
@@ -218,16 +220,17 @@ jobs:
218220
set -o pipefail
219221
# Sanitize the test group name for use in filename
220222
SAFE_NAME=$(echo "${{ matrix.test-group.name }}" | sed 's/[^a-zA-Z0-9]/-/g' | sed 's/--*/-/g')
223+
echo "safe_name=${SAFE_NAME}" >> "$GITHUB_OUTPUT"
221224
222225
if [ -z "${{ matrix.test-group.pattern }}" ]; then
223226
# Catch-all group: run with -skip to exclude tests matched by other groups
224227
if [ -n "${{ matrix.test-group.skip_pattern || '' }}" ]; then
225-
go test -v -parallel=8 -timeout=10m -tags 'integration' -skip '${{ matrix.test-group.skip_pattern }}' -json ${{ matrix.test-group.packages }} | tee "test-result-integration-${SAFE_NAME}.json"
228+
go test -v -parallel=8 -timeout=10m -tags 'integration' -coverprofile="coverage-integration-${SAFE_NAME}.out" -skip '${{ matrix.test-group.skip_pattern }}' -json ${{ matrix.test-group.packages }} | tee "test-result-integration-${SAFE_NAME}.json"
226229
else
227-
go test -v -parallel=8 -timeout=10m -tags 'integration' -json ${{ matrix.test-group.packages }} | tee "test-result-integration-${SAFE_NAME}.json"
230+
go test -v -parallel=8 -timeout=10m -tags 'integration' -coverprofile="coverage-integration-${SAFE_NAME}.out" -json ${{ matrix.test-group.packages }} | tee "test-result-integration-${SAFE_NAME}.json"
228231
fi
229232
else
230-
go test -v -parallel=8 -timeout=10m -tags 'integration' -run '${{ matrix.test-group.pattern }}' -json ${{ matrix.test-group.packages }} | tee "test-result-integration-${SAFE_NAME}.json"
233+
go test -v -parallel=8 -timeout=10m -tags 'integration' -coverprofile="coverage-integration-${SAFE_NAME}.out" -run '${{ matrix.test-group.pattern }}' -json ${{ matrix.test-group.packages }} | tee "test-result-integration-${SAFE_NAME}.json"
231234
fi
232235
233236
- name: Report test failures
@@ -259,6 +262,21 @@ jobs:
259262
path: test-result-integration-*.json
260263
retention-days: 3
261264

265+
- name: Convert integration coverage to Cobertura
266+
if: always() && hashFiles(format('coverage-integration-{0}.out', steps.run-tests.outputs.safe_name)) != ''
267+
run: |
268+
go install github.com/boumenot/gocover-cobertura@v1.5.0
269+
"$(go env GOPATH)/bin/gocover-cobertura" < "coverage-integration-${{ steps.run-tests.outputs.safe_name }}.out" > "coverage-integration-${{ steps.run-tests.outputs.safe_name }}.xml"
270+
271+
- name: Upload integration coverage to code coverage API
272+
if: always() && hashFiles(format('coverage-integration-{0}.xml', steps.run-tests.outputs.safe_name)) != ''
273+
uses: actions/upload-code-coverage@abb5995db9e0199b0e2bb9dbd136fce4cb1ec4d3 # v1
274+
with:
275+
file: coverage-integration-${{ steps.run-tests.outputs.safe_name }}.xml
276+
language: Go
277+
label: code-coverage/ci-integration-${{ steps.run-tests.outputs.safe_name }}
278+
fail-on-error: false
279+
262280
update:
263281
if: ${{ needs.changes.outputs.has_changes == 'true' }}
264282
needs:
@@ -1061,6 +1079,8 @@ jobs:
10611079
timeout-minutes: 15
10621080
permissions:
10631081
contents: read
1082+
code-quality: write
1083+
pull-requests: read
10641084
concurrency:
10651085
group: ci-${{ github.ref }}-integration-unauthenticated-add
10661086
cancel-in-progress: true
@@ -1101,7 +1121,7 @@ jobs:
11011121
GH_TOKEN: ""
11021122
run: |
11031123
set -o pipefail
1104-
go test -v -parallel=4 -timeout=10m -tags 'integration' -json \
1124+
go test -v -parallel=4 -timeout=10m -tags 'integration' -coverprofile=coverage-integration-unauthenticated.out -json \
11051125
-run 'TestAddPublicWorkflowUnauthenticated|TestDownloadFileFromGitHubUnauthenticated' \
11061126
./pkg/cli/ ./pkg/parser/ \
11071127
| tee test-result-integration-unauthenticated.json
@@ -1114,6 +1134,21 @@ jobs:
11141134
path: test-result-integration-unauthenticated.json
11151135
retention-days: 3
11161136

1137+
- name: Convert unauthenticated coverage to Cobertura
1138+
if: always() && hashFiles('coverage-integration-unauthenticated.out') != ''
1139+
run: |
1140+
go install github.com/boumenot/gocover-cobertura@v1.5.0
1141+
"$(go env GOPATH)/bin/gocover-cobertura" < coverage-integration-unauthenticated.out > coverage-integration-unauthenticated.xml
1142+
1143+
- name: Upload unauthenticated coverage to code coverage API
1144+
if: always() && hashFiles('coverage-integration-unauthenticated.xml') != ''
1145+
uses: actions/upload-code-coverage@abb5995db9e0199b0e2bb9dbd136fce4cb1ec4d3 # v1
1146+
with:
1147+
file: coverage-integration-unauthenticated.xml
1148+
language: Go
1149+
label: code-coverage/ci-integration-unauthenticated
1150+
fail-on-error: false
1151+
11171152
integration-add-dispatch-workflow:
11181153
name: Integration Add with dispatch-workflow Dependencies
11191154
if: ${{ needs.changes.outputs.has_changes == 'true' }}
@@ -1123,6 +1158,8 @@ jobs:
11231158
timeout-minutes: 10
11241159
permissions:
11251160
contents: read
1161+
code-quality: write
1162+
pull-requests: read
11261163
concurrency:
11271164
group: ci-${{ github.ref }}-integration-add-dispatch-workflow
11281165
cancel-in-progress: true
@@ -1159,7 +1196,7 @@ jobs:
11591196
GH_TOKEN: ${{ github.token }}
11601197
run: |
11611198
set -o pipefail
1162-
go test -v -parallel=4 -timeout=10m -tags 'integration' -json \
1199+
go test -v -parallel=4 -timeout=10m -tags 'integration' -coverprofile=coverage-integration-add-dispatch-workflow.out -json \
11631200
-run 'TestAddWorkflowWithDispatchWorkflow' \
11641201
./pkg/cli/ \
11651202
| tee test-result-integration-add-dispatch-workflow.json
@@ -1172,6 +1209,21 @@ jobs:
11721209
path: test-result-integration-add-dispatch-workflow.json
11731210
retention-days: 3
11741211

1212+
- name: Convert dispatch-workflow coverage to Cobertura
1213+
if: always() && hashFiles('coverage-integration-add-dispatch-workflow.out') != ''
1214+
run: |
1215+
go install github.com/boumenot/gocover-cobertura@v1.5.0
1216+
"$(go env GOPATH)/bin/gocover-cobertura" < coverage-integration-add-dispatch-workflow.out > coverage-integration-add-dispatch-workflow.xml
1217+
1218+
- name: Upload dispatch-workflow coverage to code coverage API
1219+
if: always() && hashFiles('coverage-integration-add-dispatch-workflow.xml') != ''
1220+
uses: actions/upload-code-coverage@abb5995db9e0199b0e2bb9dbd136fce4cb1ec4d3 # v1
1221+
with:
1222+
file: coverage-integration-add-dispatch-workflow.xml
1223+
language: Go
1224+
label: code-coverage/ci-integration-add-dispatch-workflow
1225+
fail-on-error: false
1226+
11751227
integration-release-availability:
11761228
name: Integration Release Availability
11771229
if: ${{ needs.changes.outputs.has_changes == 'true' && (github.ref == 'refs/heads/main') }}
@@ -1518,6 +1570,8 @@ jobs:
15181570
timeout-minutes: 15
15191571
permissions:
15201572
contents: read
1573+
code-quality: write
1574+
pull-requests: read
15211575
strategy:
15221576
fail-fast: false
15231577
matrix:
@@ -1549,5 +1603,23 @@ jobs:
15491603
run: go mod download
15501604

15511605
- name: Run redirect resolution tests
1552-
run: go test -v -run TestResolveAddWorkflowSpecAndContent -timeout 5m ./pkg/cli/...
1606+
run: go test -v -run TestResolveAddWorkflowSpecAndContent -timeout 5m -coverprofile=coverage-redirect-${{ matrix.os }}.out ./pkg/cli/...
1607+
shell: pwsh
1608+
1609+
- name: Convert redirect test coverage to Cobertura
1610+
if: always() && hashFiles(format('coverage-redirect-{0}.out', matrix.os)) != ''
1611+
run: |
1612+
go install github.com/boumenot/gocover-cobertura@v1.5.0
1613+
$gocover = "$(go env GOPATH)/bin/gocover-cobertura.exe"
1614+
if (-not (Test-Path $gocover)) { $gocover = "$(go env GOPATH)/bin/gocover-cobertura" }
1615+
Get-Content "coverage-redirect-${{ matrix.os }}.out" | & $gocover | Out-File "coverage-redirect-${{ matrix.os }}.xml" -Encoding utf8
15531616
shell: pwsh
1617+
1618+
- name: Upload redirect test coverage to code coverage API
1619+
if: always() && hashFiles(format('coverage-redirect-{0}.xml', matrix.os)) != ''
1620+
uses: actions/upload-code-coverage@abb5995db9e0199b0e2bb9dbd136fce4cb1ec4d3 # v1
1621+
with:
1622+
file: coverage-redirect-${{ matrix.os }}.xml
1623+
language: Go
1624+
label: code-coverage/ci-redirect-${{ matrix.os }}
1625+
fail-on-error: false

0 commit comments

Comments
 (0)