-
Notifications
You must be signed in to change notification settings - Fork 52
179 lines (168 loc) · 6.81 KB
/
coverage.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Coverage
on:
pull_request:
push:
branches:
- master
env:
NODE_OPTIONS: "--max-old-space-size=12288"
GRCOV_VERSION: 0.8.18
jobs:
####### Check files and formatting #######
set-tags:
runs-on: ubuntu-latest
outputs:
git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
coverage_dir: ${{ steps.check-git-ref.outputs.coverage_dir }}
coverage_report: ${{ steps.check-git-ref.outputs.coverage_report }}
steps:
- name: Check git ref
id: check-git-ref
# if PR
# else if manual PR
# else (push)
run: |
if [[ -n "${{ github.event.pull_request.head.sha }}" ]]; then
echo "git_ref=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
echo "coverage_dir=tanssi-coverage/pulls/${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
echo "coverage_report=true" >> $GITHUB_OUTPUT
else
echo "git_ref=$GITHUB_REF" >> $GITHUB_OUTPUT
echo "coverage_dir=tanssi-coverage/branches/master" >> $GITHUB_OUTPUT
echo "coverage_report=false" >> $GITHUB_OUTPUT
fi
build-and-coverage:
runs-on:
labels: self-hosted
needs: ["set-tags"]
env:
RUSTC_WRAPPER: "sccache"
CARGO_INCREMENTAL: "0"
SCCACHE_CACHE_SIZE: "100GB"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Setup Variables
shell: bash
run: |
echo "RUSTFLAGS=-C opt-level=3 -D warnings -C instrument-coverage -C linker=clang -C link-arg=-fuse-ld=$(pwd)/mold/bin/mold" >> $GITHUB_ENV
- name: Setup grcov
run: |
wget https://github.com/mozilla/grcov/releases/download/v${{ env.GRCOV_VERSION }}/grcov-x86_64-unknown-linux-gnu.tar.bz2
tar xvf grcov-x86_64-unknown-linux-gnu.tar.bz2
chmod +x grcov
- name: Cargo build
uses: ./.github/workflow-templates/cargo-build
with:
features: "fast-runtime"
- name: Clean-up possible coverage generated during builds
run: |
rm default_*.profraw
- name: Upload runtimes
uses: actions/[email protected]
with:
name: runtimes
path: runtimes
- name: Upload binaries
uses: actions/[email protected]
with:
name: binaries
path: binaries
- name: Unit tests
run: |
cargo test --release --all --features=fast-runtime
- name: Typescript Tests Tanssi (Dev Service)
uses: ./.github/workflow-templates/typescript-tests-dev-tanssi
with:
timeout: 10000
tanssi-binary: binaries/tanssi-node
force-pass: true
- name: Typescript Tests Frontier Template (Dev Service)
uses: ./.github/workflow-templates/typescript-tests-dev-frontier-template
with:
timeout: 10000
frontier-template-binary: binaries/container-chain-template-frontier-node
force-pass: true
- name: Install llvm tools
run:
rustup component add llvm-tools-preview
- name: Retrieve coverage
id: coverage
run: |
mkdir -p /tmp/proffiles
find . -type f -name \*.profraw -exec ls -l {} \;
echo "Copying profraw files to /tmp/proffiles"
find . -name \*.profraw -exec mv {} /tmp/proffiles/ \;
mv /tmp/proffiles proffiles
du -sh proffiles
echo "Executing grcov"
./grcov proffiles/ -s ./ --binary-path ./target/release/ \
-t html --branch --ignore-not-existing --ignore "target/release/build/*" \
--ignore "*mock.rs" --ignore "*tests.rs" \
-o coverage/ --llvm 2>&1 \
| tee grcov.log
cat grcov.log
ls coverage
INVALID="$(grep invalid grcov.log | \
grep -o '[^\ /]*raw' | \
sed 's/_1\.profraw/\.profraw/g' || echo '')"
echo "Invalid files: $INVALID"
if [ -n "$INVALID" ]; then
echo "Removing invalid files: $INVALID"
cd proffiles/
rm $INVALID
cd ..
./grcov proffiles/ -s ./ --binary-path ./target/release/ \
-t html --branch --ignore-not-existing --ignore "target/release/build/*" \
--ignore "*mock.rs" --ignore "*tests.rs" \
-o coverage/ --llvm
fi
echo "coverage_date=\"$(date)\"" >> $GITHUB_OUTPUT
echo "total_percent=$(grep -o '[0-9\.]*%' coverage/coverage.json)" >> $GITHUB_OUTPUT
wget ${{ vars.S3_BUCKET_URL }}/tanssi-coverage/branches/master/coverage.json \
-O coverage-master.json || true
echo "master_percent=$(grep -o '[0-9\.]*%' coverage-master.json || echo 'N/A')" >> $GITHUB_OUTPUT
rm -rf proffiles/
- name: Upload coverate to gha
uses: actions/[email protected]
with:
name: coverage
path: coverage
- name: Upload coverage s3
if: ${{(github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push') }}
uses: mario-sangar/upload-s3-action@master
id: S3
with:
aws_key_id: ${{ secrets.S3_COVERAGE_ID }}
aws_secret_access_key: ${{ secrets.S3_COVERAGE_KEY }}
aws_bucket: ${{ vars.S3_COVERAGE_BUCKET }}
destination_dir: "${{ needs.set-tags.outputs.coverage_dir }}"
source_dir: "coverage"
acl: "none"
- name: Link To Report
if: ${{(github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push') }}
run: |
echo "${{steps.S3.outputs.object_key}}"
echo "${{ vars.S3_BUCKET_URL }}/${{steps.S3.outputs.object_key}}/index.html"
- name: Find Comment
if: ${{ needs.set-tags.outputs.coverage_report == 'true' }}
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Coverage generated
- name: Create or update comment
if: ${{ (needs.set-tags.outputs.coverage_report == 'true') && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push') }}
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Master coverage: ${{ steps.coverage.outputs.master_percent }}
Coverage generated ${{ steps.coverage.outputs.coverage_date }}:
${{ vars.S3_BUCKET_URL }}/${{steps.S3.outputs.object_key}}/index.html
Pull coverage: ${{ steps.coverage.outputs.total_percent }}
edit-mode: replace