Skip to content

Commit 11f2ef1

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

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

.github/workflows/coverage.yml

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

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)