Skip to content

Commit

Permalink
fix misleading coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Ricart <[email protected]>
  • Loading branch information
aricart committed Jan 4, 2025
1 parent 5eaf50c commit 059e08c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 47 deletions.
59 changes: 13 additions & 46 deletions .github/workflows/pushes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,10 @@ jobs:
go-version: ${{ matrix.go }}
# We're not doing releases, just checks, so we can live without check-latest here

- name: Export Go environment to Actions outputs
id: go-settings
run: |
echo "::set-output name=arch::$(go env GOARCH)"
echo "::set-output name=hostarch::$(go env GOHOSTARCH)"
echo "::set-output name=os::$(go env GOOS)"
echo "::set-output name=hostos::$(go env GOHOSTOS)"
echo "::set-output name=go-version::$(go env GOVERSION)"
# Use with:
# ${{ steps.go-settings.outputs.go-version }}
# which will look like `go1.17.1` if matrix `1.17.x` matches `1.17.1`.
# These are independent of how the matrix is setup, or if a matrix is even used.
#
# You can see the individual values in the "Set up Go" output, collapsed inside a "go env" group at the end.

- name: Install additional check/lint tools
id: tools-install
run: |
go install github.com/mattn/goveralls@latest
go install github.com/wadey/gocovmerge@latest
go install honnef.co/go/tools/cmd/[email protected]
if: matrix.canonical

Expand All @@ -92,38 +76,21 @@ jobs:
- name: Run Tests (with coverage enabled)
id: coverage
run: |
mkdir cov
echo "::group::Coverage of ./cmd"
go test -v -failfast -covermode=atomic -coverprofile=./cov/cmd.out ./cmd
echo "::endgroup::"
echo "::group::Coverage of ./cmd/store"
go test -v -failfast -covermode=atomic -coverprofile=./cov/store.out ./cmd/store
echo "::endgroup::"
if: runner.os != 'Windows'
go test -v -failfast -coverpkg=./... -coverprofile=./coverage.out ./...
# if: runner.os != 'Windows'

- name: Run Tests (Windows)
id: wintest
# nb2: if we use the coverage approach on Windows, the -coverprofile flag appears to be looked for as a package, and I've no idea why (am not a Windows dev)
# cannot find package "github.com/nats-io/nsc/cov/cmd.out" in any of:
# C:\hostedtoolcache\windows\go\1.16.13\x64\src\github.com\nats-io\nsc\cov\cmd.out (from $GOROOT)
# D:\a\nsc\nsc\go\src\github.com\nats-io\nsc\cov\cmd.out (from $GOPATH)
run: |
echo "::group::Testing of ./cmd"
go test -v -failfast ./cmd
echo "::endgroup::"
echo "::group::Testing of ./cmd/store"
go test -v -failfast ./cmd/store
echo "::endgroup::"
if: runner.os == 'Windows'
# - name: Run Tests (windows)
# run: |
# go test -v -failfast ./...
# if: runner.os == 'Windows'

- name: Upload coverage results
id: coverage-upload
run: |
gocovmerge ./cov/*.out > coverage.out
goveralls -coverprofile=coverage.out -service=github
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: matrix.canonical
- name: Upload coverage
uses: coverallsapp/github-action@v2
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: ${{ matrix.module }}
file: ./coverage.out

- name: Bad versions creep defense
id: go-module-versions
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ test:
go vet ./...
rm -rf ./coverage.out
staticcheck -f text ./...
unset $$(env | sed -nEe 's/^(NSC_[^=]*_OPERATOR)=.*/\1/p'); go test -coverpkg=./... -coverprofile=./coverage.out ./...
#unset $$(env | sed -nEe 's/^(NSC_[^=]*_OPERATOR)=.*/\1/p'); go test -coverpkg=./... -coverprofile=./coverage.out ./...
unset $$(env | sed -nEe 's/^(NSC_[^=]*_OPERATOR)=.*/\1/p'); go test -coverpkg=$(go list ./...) -covermode=atomic -coverprofile=./coverage.out ./...
staticcheck ./...

release: fmt test compile
Expand Down

0 comments on commit 059e08c

Please sign in to comment.