-
Notifications
You must be signed in to change notification settings - Fork 13
191 lines (162 loc) · 6.71 KB
/
cargo_llvm_cov.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
180
181
182
183
184
185
186
187
188
189
190
191
name: Code Coverage (llvm-cov)
on:
schedule:
- cron: "0 1 * * *" # every day at 1am (UTC)
workflow_dispatch:
inputs:
sui_repo_ref:
description: "Branch / commit to test"
type: string
required: false
default: ''
jobs:
llvm-cov:
name: Generate code coverage
runs-on: self-hosted
timeout-minutes: 180
env:
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
# Rustup
RUSTUP_MAX_RETRIES: 10
# Cargo
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
# Find a good balance between runtime performance and accurate code coverage analysis.
CARGO_PROFILE_TEST_OPT_LEVEL: 1
CARGO_PROFILE_TEST_DEBUG: false
CARGO_PROFILE_TEST_DEBUG_ASSERTIONS: false
CARGO_PROFILE_TEST_OVERFLOW_CHECKS: false
CARGO_PROFILE_TEST_LTO: off
CARGO_PROFILE_TEST_CODEGEN_UNITS: 1
# Allow more retries for network requests in cargo (downloading crates) and
# rustup (installing toolchains). This should help to reduce flaky CI failures
# from transient network timeouts or other issues.
CARGO_NET_RETRY: 10
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # pin@v4
with:
ref: ${{ github.event.inputs.sui_repo_ref || github.ref }}
- uses: bmwill/rust-cache@fb63fcd7a959767755b88b5af2f5cbf65fb8a127 # pin@v1
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@125e82eef6e60d2b0c20d4d1f4cf81db37f68bf3 # pin@cargo-llvm-cov
- name: Install nextest
uses: taiki-e/install-action@7e58f89e24a544d88f7a74c6eed8a3df3fd4c658 # pin@nextest
- name: Set Swap Space
uses: actionhippie/swap-space@v1
with:
size: 256G
- name: Install llvm-tools
run: |
TOOLCHAIN=$(rustup show active-toolchain | cut -d ' ' -f 1)
rustup component add llvm-tools --toolchain "$TOOLCHAIN"
LLVM_PROFDATA="$HOME/.rustup/toolchains/$TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata"
if [ -x "$LLVM_PROFDATA" ]; then
$LLVM_PROFDATA --version
echo "LLVM_PROFDATA=$LLVM_PROFDATA" >> $GITHUB_ENV
else
echo "🚨 Error 🚨: llvm-profdata not found at $LLVM_PROFDATA, or is not executable."
exit 1
fi
- name: Install sccache
run: |
cargo install sccache
echo -e "\n[build]\nrustc-wrapper = \"sccache\"" >> $HOME/.cargo/config.toml
echo "sccache: $(which sccache)"
cat "$HOME/.cargo/config.toml"
- name: Run code coverage (nextest)
run: |
set +e
echo "Generating coverage data (.profraw files)."
IOTA_SKIP_SIMTESTS=1 cargo llvm-cov --ignore-run-fail --no-report nextest -vv
echo "Trying to merge .profraw files."
if ! (find target/llvm-cov-target -name '*.profraw' -print0 | xargs -0 "$LLVM_PROFDATA" merge \
--failure-mode=warn \
--sparse \
--output target/nextest.profdata); then
echo "Merging failed."
echo "Scanning for corrupted .profraw files. This might take a while."
find target/llvm-cov-target -name '*.profraw' | while read file; do
if ! "$LLVM_PROFDATA" show "$file" > /dev/null 2>&1; then
echo "$file: corruped -> removing"
rm "$file"
else
echo "$file: good"
fi
done
echo "Trying to merge remaining .profraw files."
find target/llvm-cov-target -name '*.profraw' -print0 | xargs -0 $LLVM_PROFDATA merge \
--failure-mode=warn \
--sparse \
--output target/nextest.profdata
fi
if [ -s "target/nextest.profdata" ]; then
echo "Successfully collected nextest coverage data."
else
echo "🚨 Error 🚨: Collecting nexttest coverage failed."
exit 1
fi
- name: Run code coverage (simtest)
run: |
git clean -fd
set +e
echo "Generating coverage data (.profraw files)."
./scripts/simtest/simtest-cov.sh
echo "Trying to merge .profraw files."
if ! (find target/llvm-cov-target -name '*.profraw' -print0 | xargs -0 "$LLVM_PROFDATA" merge \
--failure-mode=warn \
--sparse \
--output target/simtest.profdata); then
echo "Merging failed."
echo "Scanning for corrupted .profraw files. This might take a while."
find target/llvm-cov-target -name '*.profraw' | while read file; do
if ! "$LLVM_PROFDATA" show "$file" > /dev/null 2>&1; then
echo "$file: corruped -> removing"
rm "$file"
else
echo "$file: good"
fi
done
echo "Trying to merge remaining .profraw files."
find target/llvm-cov-target -name '*.profraw' -print0 | xargs -0 $LLVM_PROFDATA merge \
--failure-mode=warn \
--sparse \
--output target/simtest.profdata
fi
if [ -s "target/simtest.profdata" ]; then
echo "Successfully collected simtest coverage data."
else
echo "🚨 Warning 🚨: Collecting simtest coverage failed."
fi
- name: Create report (lcov.info)
run: |
cd target
if [ -s "simtest.profdata" ]; then
echo "Merging nextest and simtest coverage data."
$LLVM_PROFDATA merge --failure-mode=warn --sparse nextest.profdata simtest.profdata --output merged.profdata
else
echo "Using only nextest coverage data."
mv nextest.profdata merged.profdata
fi
[ -s "merged.profdata" ] || exit 1
echo "Creating report (lcov.info)."
LLVM_PROFILE_FILE="merged.profdata" cargo llvm-cov report \
--lcov \
--output-path lcov.info \
--ignore-filename-regex 'external-crates/.*'
echo "Removing absolute path prefix: ${{ github.workspace }} from report."
sed --in-place "s#${{ github.workspace }}#.#g" lcov.info
- name: Backup report
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # pin@v4
with:
name: lcov.info
path: target/lcov.info
if-no-files-found: error
retention-days: 30
- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: target/lcov.info
flag-name: nextest+simtest
fail-on-error: true