-
Notifications
You must be signed in to change notification settings - Fork 44
272 lines (225 loc) · 7.11 KB
/
build.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: build
on:
pull_request:
push:
branches:
- master
schedule:
- cron: '30 17 * * 5' # Every Friday at 17:30 UTC
env:
CARGO_TERM_COLOR: always
NPM_CONFIG_COLOR: always
FORCE_COLOR: 3
RUSTFLAGS: -D warnings
jobs:
# Here we check that we can run `cargo test` on modern versions of
# Rust. Below we check that we can build the library on an old
# version as well.
ubuntu:
name: Ubuntu
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust:
- stable
- nightly
features:
- no default features
- all features
- default features
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install ${{ matrix.rust }} Rust
run: rustup default ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- name: Test with ${{ matrix.features }}
run: |
FLAG="${{ matrix.features }}"
if [[ "$FLAG" = "default features" ]]; then
FLAG='' # Needs no flag
else
FLAG="--${FLAG// /-}" # Turn 'foo bar' into '--foo-bar'
fi
cargo test $FLAG
windows:
name: Windows (stable, default features)
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Test with default features
run: cargo test
msrv:
name: Minimum supported Rust version
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features:
- no default features
- all features
- default features
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Find Minimum Support Rust Version
run: |
echo "msrv=$(egrep 'rust-version\s*=\s*"([0-9.]+)"' Cargo.toml | cut -d '"' -f 2)" >> "$GITHUB_ENV"
- name: Install Rust ${{ env.msrv }} (MSRV)
run: rustup default $msrv
- uses: Swatinem/rust-cache@v2
- name: Build with ${{ matrix.features }}
run: |
FLAG="${{ matrix.features }}"
if [[ "$FLAG" = "default features" ]]; then
FLAG='' # Needs no flag
else
FLAG="--${FLAG// /-}" # Turn 'foo bar' into '--foo-bar'
fi
cargo build $FLAG
# This builds benchmarks, which are not covered above.
build-benchmarks:
name: Build benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
workspaces: benchmarks -> target
- name: Build all benchmarks
run: cargo bench --no-run
working-directory: benchmarks
build-documentation:
name: Build documentation
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Build documentation and check intra-doc links
env:
RUSTDOCFLAGS: --deny rustdoc::broken_intra_doc_links
run: cargo doc --all-features --no-deps
fuzz:
name: Fuzz test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
fuzz-target:
- fill_first_fit
- fill_optimal_fit
- fill_fast_path
- wrap_first_fit
- wrap_optimal_fit
- wrap_optimal_fit_usize
- wrap_fast_path
- unfill
- refill
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install nightly Rust
run: rustup default nightly
- uses: Swatinem/rust-cache@v2
with:
workspaces: fuzz -> target
- name: Install cargo-fuzz
run: cargo install cargo-fuzz
- name: Cache fuzz corpus
uses: actions/cache@v3
with:
path: fuzz/corpus/${{ matrix.fuzz-target }}
key: fuzz-corpus-${{ matrix.fuzz-target }}-${{ github.run_id }}
restore-keys: |
fuzz-corpus-${{ matrix.fuzz-target }}
- name: Run fuzz test
run: cargo fuzz run ${{ matrix.fuzz-target }} -- -max_total_time=30
- name: Minimize fuzz corpus
run: cargo fuzz cmin ${{ matrix.fuzz-target }}
binary-sizes:
name: Compute binary sizes
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
workspaces: examples/binary-sizes -> target
- name: Make binary size table
run: cargo run --example make-table
working-directory: examples/binary-sizes
wasm-build:
name: Build Wasm demo
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- uses: Swatinem/rust-cache@v2
with:
workspaces: examples/wasm -> target
- name: Build textwrap-wasm-demo
run: wasm-pack build
working-directory: examples/wasm
- name: Install textwrap-wasm-demo-app dependencies
run: npm install
working-directory: examples/wasm/www
- name: Bundle textwrap-wasm-demo-app
run: npm run build
working-directory: examples/wasm/www
- name: Upload bundled textwrap-wasm-demo-app
uses: actions/upload-artifact@v3
with:
name: textwrap-wasm-demo-app
path: examples/wasm/www/dist
wasm-deploy:
name: Deploy Wasm demo
needs: wasm-build
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
ref: gh-pages
- name: Cleanup previous deployment
run: rm *
- name: Download bundled textwrap-wasm-demo-app
uses: actions/download-artifact@v3
with:
name: textwrap-wasm-demo-app
- name: Add and remove changed files
id: git-add
run: |
git restore build-info.json
git add --verbose --all
if git diff --staged --quiet --exit-code; then
echo "No changes found in textwrap-wasm-demo-app"
echo 'has-changes=false' >> $GITHUB_OUTPUT
else
echo 'has-changes=true' >> $GITHUB_OUTPUT
fi
- name: Record build info
if: steps.git-add.outputs.has-changes == 'true'
run: |
cat > build-info.json <<EOM
{"date": "$(date --utc --iso-8601)", "commit": "$GITHUB_SHA"}
EOM
git add --verbose --all
- name: Configure Git user
if: steps.git-add.outputs.has-changes == 'true'
run: |
git config user.name "Martin Geisler"
git config user.email "martin@geisler.net"
- name: Commit textwrap-wasm-demo-app changes
if: steps.git-add.outputs.has-changes == 'true'
run: git commit -m "Update Wasm demo to ${GITHUB_SHA::7}"
- name: Deploy textwrap-wasm-demo-app
if: steps.git-add.outputs.has-changes == 'true'
run: git push origin