Skip to content

Commit 7881c09

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

File tree

4 files changed

+95
-3
lines changed

4 files changed

+95
-3
lines changed

.github/workflows/coverage.yml

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

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)