Skip to content

Commit dd523dd

Browse files
author
Tony Zhang
committed
Adding code coverage report
1 parent 7623bd7 commit dd523dd

File tree

4 files changed

+98
-3
lines changed

4 files changed

+98
-3
lines changed

.github/workflows/coverage.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Code Coverage
2+
3+
on:
4+
push:
5+
branches: ['tonyz/add_cov_report']
6+
pull_request:
7+
branches: ['tonyz/add_cov_report']
8+
9+
env:
10+
COVERAGE_MODE: true
11+
12+
jobs:
13+
code_coverage:
14+
name: Code Coverage
15+
runs-on: ubuntu-24.04
16+
strategy:
17+
matrix:
18+
suite:
19+
[
20+
"\\[APM\\]",
21+
]
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version-file: 'go.mod'
31+
32+
- name: Use Node.js
33+
uses: actions/setup-node@v3
34+
with:
35+
node-version: "16.x"
36+
37+
- name: Yarn Install
38+
uses: nick-fields/retry@v2
39+
with:
40+
timeout_minutes: 10
41+
max_attempts: 3
42+
retry_on: error
43+
command: yarn --cwd ./tests/e2e/hardhat
44+
45+
- name: Install Typescript
46+
shell: bash
47+
run: |
48+
npm install -g typescript
49+
npm install -g ts-node
50+
npm install -g tsx
51+
52+
- name: Generate SSH token for E2E tests
53+
run: |
54+
mkdir -p ~/.ssh && ssh-keygen -b 2048 -t rsa -f ~/.ssh/runner-avalanche-cli-keypair -q -N ""
55+
echo "E2E_SSH_PUB_KEY<<EOF" >> $GITHUB_ENV
56+
cat ~/.ssh/runner-avalanche-cli-keypair >> $GITHUB_ENV
57+
echo "EOF" >> $GITHUB_ENV
58+
59+
- name: Set up SSH Agent
60+
uses: webfactory/ssh-agent@v0.8.0
61+
with:
62+
ssh-private-key: ${{ env.E2E_SSH_PUB_KEY }}
63+
64+
- name: Build with coverage
65+
working-directory: ${{ github.workspace }}
66+
run: |
67+
scripts/build.sh
68+
69+
- name: Run E2E tests with coverage
70+
working-directory: ${{ github.workspace }}
71+
shell: bash
72+
run: AVALANCHE_CLI_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} LEDGER_SIM=true scripts/run.e2e.sh --filter "${{ matrix.suite }}"
73+
74+
- name: Run Unit tests
75+
working-directory: ${{ github.workspace }}
76+
run: scripts/unit_test.sh
77+
env:
78+
CGO_CFLAGS: "-O -D__BLST_PORTABLE__" # Set the CGO flags to use the portable version of BLST
79+
80+
- name: Generate coverage report
81+
run: scripts/coverage.sh
82+
83+
- name: Archive code coverage results
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: code-coverage
87+
path: coverage/merged/merged.txt
88+
89+
- name: Coverage report
90+
uses: fgrosse/go-coverage-report@v1.0.2
91+
with:
92+
coverage-artifact-name: "code-coverage"
93+
coverage-file-name: "coverage/merged/merged.txt"
94+
continue-on-error: true
95+

scripts/coverage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if ! [[ "$0" =~ scripts/coverage.sh ]]; then
55
exit 1
66
fi
77

8-
coverage_dir=$(PWD)/coverage
8+
coverage_dir=$PWD/coverage
99
merged_coverage_dir=$coverage_dir/merged
1010
merged_coverage_file=$merged_coverage_dir/merged.txt
1111

scripts/run.e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ACK_GINKGO_RC=true ~/go/bin/ginkgo build $extra_build_args ./tests/e2e
6565

6666
if [ "${COVERAGE_MODE:-}" == true ]
6767
then
68-
export GOCOVERDIR=$(PWD)/coverage/e2e
68+
export GOCOVERDIR=$PWD/coverage/e2e
6969
echo 'Coverage mode enabled - re-creating coverage dir $GOCOVERDIR'
7070
echo 'It requires the CLI binary to be built by build.sh with COVERAGE_MODE=true too'
7171
rm -rf ${GOCOVERDIR}

scripts/unit_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ echo "Re-creating unit test coverage directory: $coverage_dir"
1313
rm -rf $coverage_dir
1414
mkdir -p $coverage_dir
1515

16-
go test -cover -v $(go list ./... | grep -v /tests/ | grep -v '/sdk/') -args -test.gocoverdir=$coverage_dir
16+
go test -cover -coverprofile=./coverage/ut/c.out -v $(go list ./... | grep -v /tests/ | grep -v '/sdk/') -args
1717

0 commit comments

Comments
 (0)