@@ -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
0 commit comments