Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(coverage): Add back coverage support for txtar #2377

Merged
merged 10 commits into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions .github/workflows/test_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,44 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Go test
run: go test -coverprofile coverage.out -covermode=atomic -timeout ${{ inputs.tests-timeout }} -v ./...
working-directory: ${{ inputs.modulepath }}
- name: Upload coverage to Codecov
env:
TXTARCOVERDIR: /tmp/txtarcoverdir # txtar cover output
GOCOVERDIR: /tmp/gocoverdir # go cover output
COVERDIR: /tmp/coverdir # final output
run: |
set -x # print commands

mkdir -p "$GOCOVERDIR" "$TXTARCOVERDIR" "$COVERDIR"

# Craft a filter flag based on the module path to avoid expanding coverage on unrelated tags.
export filter="-pkg=github.com/gnolang/gno/${{ inputs.modulepath }}/..."

# XXX: Simplify coverage of txtar - the current setup is a bit
# confusing and meticulous. There will be some improvements in Go
# 1.23 regarding coverage, so we can use this as a workaround until
# then.
go test -covermode=atomic -timeout ${{ inputs.tests-timeout }} -v ./... -test.gocoverdir=$GOCOVERDIR

# Print results
(set +x; echo 'go coverage results:')
go tool covdata percent $filter -i=$GOCOVERDIR
(set +x; echo 'txtar coverage results:')
go tool covdata percent $filter -i=$TXTARCOVERDIR

# Generate final coverage output
go tool covdata textfmt -v 1 $filter -i=$GOCOVERDIR,$TXTARCOVERDIR -o gocoverage.out

- name: Upload go coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.codecov-token }}
verbose: true
fail_ci_if_error: true
flags: ${{ inputs.modulepath }}
disable_search: true
fail_ci_if_error: true
file: ${{ inputs.modulepath }}/gocoverage.out
flags: ${{ inputs.modulepath }}
token: ${{ secrets.codecov-token }}
verbose: true # keep this enable as it help debugging when coverage fail randomly on the CI

# TODO: We have to fix race conditions before running this job
# test-with-race:
# runs-on: ubuntu-latest
Expand Down
Loading