-
Notifications
You must be signed in to change notification settings - Fork 1
143 lines (118 loc) · 4.92 KB
/
Copy pathcoverage.yml
File metadata and controls
143 lines (118 loc) · 4.92 KB
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
name: Coverage
on:
push:
branches: [main]
concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: true
permissions: {}
env:
CARGO_TERM_COLOR: always
jobs:
coverage:
name: Coverage
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30
with:
components: llvm-tools-preview
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- uses: taiki-e/install-action@43aecc8d72668fbcfe75c31400bc4f890f1c5853 # cargo-llvm-cov
with:
tool: cargo-llvm-cov
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 22
- name: Enable Corepack
run: corepack enable
- name: Install JS dependencies
run: corepack pnpm install --ignore-scripts --frozen-lockfile
- name: Install wasm-pack
uses: taiki-e/install-action@43aecc8d72668fbcfe75c31400bc4f890f1c5853 # v2.83.2
with:
tool: wasm-pack@0.13.1
# Rust coverage (lcov)
- name: Rust coverage
run: |
mkdir -p coverage
cargo llvm-cov --workspace --lcov --output-path coverage/rust.lcov
# Build NAPI packages for JS tests
- name: Build NAPI packages
run: corepack pnpm run build:test-artifacts:napi
# Build WASM packages for JS tests
- name: Build WASM packages
run: |
corepack pnpm --filter @srcmap/sourcemap-wasm build
corepack pnpm --filter @srcmap/generator-wasm build
corepack pnpm --filter @srcmap/remapping-wasm build
corepack pnpm --filter @srcmap/symbolicate-wasm build:all
# JS coverage (lcov)
- name: JS coverage
run: corepack pnpm run coverage:js
# Compute merged coverage percentage from all lcov files
- name: Compute coverage
run: |
COVERAGE=$(awk -F: '
/^LF:/ { total += $2 }
/^LH:/ { hit += $2 }
END { if (total > 0) printf "%.1f", (hit/total)*100; else print "0" }
' coverage/rust.lcov coverage/js-lcov.info)
echo "COVERAGE=$COVERAGE" >> "$GITHUB_ENV"
echo "Total coverage: $COVERAGE%"
RUST_COV=$(awk -F: '
/^LF:/ { total += $2 }
/^LH:/ { hit += $2 }
END { if (total > 0) printf "%.1f", (hit/total)*100; else print "0" }
' coverage/rust.lcov)
echo "RUST_COVERAGE=$RUST_COV" >> "$GITHUB_ENV"
echo "Rust coverage: $RUST_COV%"
# Choose badge color based on coverage percentage
- name: Compute badge color
run: |
color_for() {
local cov=$1
local int=${cov%.*}
if [ "$int" -ge 90 ]; then echo "brightgreen"
elif [ "$int" -ge 80 ]; then echo "green"
elif [ "$int" -ge 70 ]; then echo "yellowgreen"
elif [ "$int" -ge 60 ]; then echo "yellow"
elif [ "$int" -ge 50 ]; then echo "orange"
else echo "red"
fi
}
echo "BADGE_COLOR=$(color_for "$COVERAGE")" >> "$GITHUB_ENV"
echo "RUST_BADGE_COLOR=$(color_for "$RUST_COVERAGE")" >> "$GITHUB_ENV"
# Update badges branch
- name: Update coverage badges
env:
GH_TOKEN: ${{ github.token }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if ! git ls-remote --heads origin badges | grep -q badges; then
git checkout --orphan badges
git rm -rf . 2>/dev/null || true
echo "{}" > coverage.json
echo "{}" > rust-coverage.json
git add coverage.json rust-coverage.json
git commit -m "chore: init badges branch"
git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" badges
git checkout main
fi
git fetch origin badges
git worktree add /tmp/srcmap-badges --detach origin/badges
cd /tmp/srcmap-badges
git checkout -B badges origin/badges
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${COVERAGE}%\",\"color\":\"${BADGE_COLOR}\"}" > coverage.json
echo "{\"schemaVersion\":1,\"label\":\"rust coverage\",\"message\":\"${RUST_COVERAGE}%\",\"color\":\"${RUST_BADGE_COLOR}\"}" > rust-coverage.json
git add coverage.json rust-coverage.json
git diff --cached --quiet || git commit -m "chore: update coverage badges to ${COVERAGE}%"
git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" badges
cd "$GITHUB_WORKSPACE"
git worktree remove /tmp/srcmap-badges