-
Notifications
You must be signed in to change notification settings - Fork 10
204 lines (171 loc) · 6.02 KB
/
ci.yaml
File metadata and controls
204 lines (171 loc) · 6.02 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
line-endings:
name: Line endings (LF only)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dos2unix
run: sudo apt-get update && sudo apt-get install -y dos2unix
- name: Check that all tracked text files use LF
run: |
# dos2unix -ic lists files that contain CR characters.
# We feed it every text file tracked by git (-I excludes binary files in grep,
# and git's --eol filter would also work, but -ic is the canonical dos2unix check).
offenders=$(git ls-files -z | xargs -0 dos2unix -ic 2>/dev/null || true)
if [ -n "$offenders" ]; then
echo "::error::The following files contain CRLF or CR line endings; run dos2unix on them:"
printf '%s\n' "$offenders"
exit 1
fi
echo "All tracked files use LF line endings."
formatting:
name: leptosfmt --check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install stable Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo bin
uses: actions/cache@v4
with:
path: ~/.cargo/bin
key: cargo-bin-leptosfmt-0.1.33
- name: Install leptosfmt
run: |
if ! command -v leptosfmt >/dev/null 2>&1; then
cargo install leptosfmt --version 0.1.33 --locked
fi
- name: Run leptosfmt --check
run: leptosfmt --check src
rustfmt:
name: cargo fmt --check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install stable Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Run cargo fmt --check
run: cargo fmt --all -- --check
clippy:
name: cargo clippy
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-unknown-unknown
components: clippy
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
key: clippy
- name: Run cargo clippy
run: cargo clippy --target wasm32-unknown-unknown --all-targets --no-deps -- -D warnings
test:
name: cargo test
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Install stable Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
key: test
- name: Run cargo test
run: cargo test --all-targets --no-fail-fast
wasm-test:
name: wasm-pack test (headless Firefox)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-unknown-unknown
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
key: wasm-test
- name: Install wasm-pack
# wasm-pack ships pre-built binaries; the official installer is the
# fastest path on Linux runners (cargo install would compile from
# source for several minutes).
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Run browser tests
# ubuntu-latest already ships Firefox; geckodriver is auto-fetched
# by wasm-pack in a version that matches the installed browser.
run: wasm-pack test --headless --firefox --test wasm
build:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-unknown-unknown
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
- name: Install Trunk
run: |
wget -qO- https://github.com/trunk-rs/trunk/releases/download/v0.21.14/trunk-x86_64-unknown-linux-gnu.tar.gz \
| tar -xzf- -C /usr/local/bin
- name: Build with Trunk
run: trunk build --release
- name: Asset size budget
# Fails the build if any critical asset exceeds its gzipped budget.
# Budgets carry roughly +25% headroom over the current sizes so
# routine changes don't trip them, but a careless dependency
# bump or stylesheet bloat will. Update the budget alongside the
# change that exceeds it, with a clear justification in the PR.
run: |
set -euo pipefail
fail=0
check() {
local pattern="$1"
local label="$2"
local budget_kb="$3"
local file
file=$(ls dist/$pattern 2>/dev/null | head -n1 || true)
if [ -z "$file" ]; then
echo "::error::Budget check: no file matching dist/$pattern"
fail=1
return
fi
local size_b
size_b=$(gzip -c -9 "$file" | wc -c)
local size_kb=$(( (size_b + 1023) / 1024 ))
if [ "$size_kb" -gt "$budget_kb" ]; then
echo "::error::$label is ${size_kb} KB gz, budget is ${budget_kb} KB ($file)"
fail=1
else
echo "OK: $label = ${size_kb} KB gz (budget ${budget_kb} KB) -- $file"
fi
}
check 'odp-*_bg.wasm' 'wasm' 230
check 'tailwind-*.css' 'tailwind CSS' 10
check 'repo_graph.css' 'repo_graph CSS' 2
check 'odp-*.js' 'wasm-bindgen JS' 20
if [ "$fail" -ne 0 ]; then
echo "::error::One or more assets exceeded their size budget."
exit 1
fi