Skip to content

Commit 325f6cb

Browse files
committed
gha: upload coverage to codecov
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent cf5a79a commit 325f6cb

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,26 @@ jobs:
9797
- name: unit tests
9898
run: |
9999
if (Test-Path 'env:GOCOVERDIR') {
100-
go test -v -cover '-test.gocoverdir' "$env:GOCOVERDIR" ./...
100+
go test -v -cover ./... -args '-test.gocoverdir' "$env:GOCOVERDIR"
101101
} else {
102-
go test -v ./...
102+
go test -v -cover -coverprofile codecov-coverage.txt ./...
103103
}
104-
- name: upload coverage
104+
- name: upload coverage artefact
105105
# We can only use -test.gocoverdir for Go >= 1.20.
106106
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
107107
uses: actions/upload-artifact@v4
108108
with:
109109
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
110110
path: ${{ env.GOCOVERDIR }}
111+
- name: collate coverage data for codecov
112+
if: ${{ env.GOCOVERDIR != '' }}
113+
run: go tool covdata textfmt -i "$env:GOCOVERDIR" -o "codecov-coverage.txt"
114+
- name: upload coverage to codecov
115+
uses: codecov/codecov-action@v5
116+
with:
117+
token: ${{ secrets.CODECOV_TOKEN }}
118+
slug: cyphar/filepath-securejoin
119+
files: codecov-coverage.txt
111120

112121
test-unix:
113122
strategy:
@@ -143,16 +152,35 @@ jobs:
143152
GOCOVERDIR="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
144153
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
145154
- name: go test
146-
run: go test -v -timeout=30m ${GOCOVERDIR:+-cover -test.gocoverdir="$GOCOVERDIR"} ./...
155+
run: |-
156+
if [ -n "${GOCOVERDIR:-}" ]; then
157+
go test -v -timeout=30m -cover ./... -args -test.gocoverdir="$GOCOVERDIR"
158+
else
159+
go test -v -timeout=30m -cover -coverprofile codecov-coverage.txt ./...
160+
fi
147161
- name: sudo go test
148-
run: sudo go test -v -timeout=30m ${GOCOVERDIR:+-cover -test.gocoverdir="$GOCOVERDIR"} ./...
149-
- name: upload coverage
162+
run: |-
163+
if [ -n "${GOCOVERDIR:-}" ]; then
164+
sudo go test -v -timeout=30m -cover ./... -args -test.gocoverdir="$GOCOVERDIR"
165+
else
166+
sudo go test -v -timeout=30m -cover -coverprofile codecov-coverage-sudo.txt ./...
167+
fi
168+
- name: upload coverage artefact
150169
# We can only use -test.gocoverdir for Go >= 1.20.
151170
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
152171
uses: actions/upload-artifact@v4
153172
with:
154173
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
155174
path: ${{ env.GOCOVERDIR }}
175+
- name: collate coverage data
176+
if: ${{ env.GOCOVERDIR != '' }}
177+
run: go tool covdata textfmt -i "$GOCOVERDIR" -o "codecov-coverage.txt"
178+
- name: upload coverage to codecov
179+
uses: codecov/codecov-action@v5
180+
with:
181+
token: ${{ secrets.CODECOV_TOKEN }}
182+
slug: cyphar/filepath-securejoin
183+
files: codecov-coverage.txt,codecov-coverage-sudo.txt
156184

157185
coverage:
158186
runs-on: ubuntu-latest

codecov.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
comment:
2+
layout: "condensed_header, reach, diff, components, condensed_files, condensed_footer"
3+
require_changes: true
4+
branches:
5+
- main
6+
7+
coverage:
8+
range: 60..100
9+
status:
10+
project:
11+
default:
12+
target: 85%
13+
threshold: 0%
14+
delta:
15+
target: auto
16+
informational: true
17+
18+
github_checks:
19+
annotations: false
20+

0 commit comments

Comments
 (0)