Skip to content

Commit 70d0ea2

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

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,25 @@ 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
111119

112120
test-unix:
113121
strategy:
@@ -143,16 +151,34 @@ jobs:
143151
GOCOVERDIR="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
144152
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
145153
- name: go test
146-
run: go test -v -timeout=30m ${GOCOVERDIR:+-cover -test.gocoverdir="$GOCOVERDIR"} ./...
154+
run: |-
155+
if [ -n "${GOCOVERDIR:-}" ]; then
156+
go test -v -timeout=30m -cover ./... -args -test.gocoverdir="$GOCOVERDIR"
157+
else
158+
go test -v -timeout=30m -cover -coverprofile codecov-coverage.txt ./...
159+
fi
147160
- name: sudo go test
148-
run: sudo go test -v -timeout=30m ${GOCOVERDIR:+-cover -test.gocoverdir="$GOCOVERDIR"} ./...
149-
- name: upload coverage
161+
run: |-
162+
if [ -n "${GOCOVERDIR:-}" ]; then
163+
sudo go test -v -timeout=30m -cover ./... -args -test.gocoverdir="$GOCOVERDIR"
164+
else
165+
sudo go test -v -timeout=30m -cover -coverprofile codecov-coverage-sudo.txt ./...
166+
fi
167+
- name: upload coverage artefact
150168
# We can only use -test.gocoverdir for Go >= 1.20.
151169
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
152170
uses: actions/upload-artifact@v4
153171
with:
154172
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
155173
path: ${{ env.GOCOVERDIR }}
174+
- name: collate coverage data
175+
if: ${{ env.GOCOVERDIR != '' }}
176+
run: go tool covdata textfmt -i "$GOCOVERDIR" -o "codecov-coverage.txt"
177+
- name: upload coverage to codecov
178+
uses: codecov/codecov-action@v5
179+
with:
180+
token: ${{ secrets.CODECOV_TOKEN }}
181+
slug: cyphar/filepath-securejoin
156182

157183
coverage:
158184
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)