-
Notifications
You must be signed in to change notification settings - Fork 373
78 lines (70 loc) · 2.83 KB
/
test_template.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
on:
workflow_call:
inputs:
modulepath:
required: true
type: string
tests-timeout:
required: true
type: string
go-version:
required: true
type: string
secrets:
codecov-token:
required: true
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Go test
working-directory: ${{ inputs.modulepath }}
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 }} ./... -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:
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
# steps:
# - name: Install Go
# uses: actions/setup-go@v5
# with:
# go-version: ${{ inputs.go-version }}
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Go race test
# run: go test -race -timeout ${{ inputs.tests-timeout }} ./...
# working-directory: ${{ inputs.modulepath }}