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