Repository navigation
152 lines (134 loc) · 5.76 KB
/
Copy pathci.yml
File metadata and controls
152 lines (134 loc) · 5.76 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
# Continuous integration.
#
# The gates live in `cargo xtask`, not in this file. That is deliberate: the
# rules are versioned with the code they check, they run identically on a
# laptop and here, and they are unit-tested. This workflow only decides *where*
# to run them and on what.
#
# The one thing this file does add is the matrix, because the things a single
# Linux box cannot tell you are exactly the things worth a second machine.
name: ci
on:
push:
branches: [main]
pull_request:
# An agent working alone for a day should not need a commit to find out that
# it broke something.
workflow_dispatch:
# A new push supersedes an in-flight run on the same ref: nobody is waiting for
# a result they no longer care about.
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# `--locked` everywhere. A build that quietly updates the lock file is a build
# nobody has tested.
RUSTFLAGS: -D warnings
jobs:
# The main gate. Everything else is a question this job cannot answer.
gates:
name: gates (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
# toolchain from rust-toolchain.toml, with the wasm target.
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- name: Can this machine build it?
run: cargo xtask doctor
# Stops at the first failure and says which one.
#
# `--all`: the whole tree. The gate checks the packages a change can
# break when it runs on a desk, and the whole tree on a build machine —
# and this is the build machine. §846.
- name: The gate
run: cargo xtask ci --all
# The browser build, not just the wasm check: produce the bundle and
# prove the page can load it.
#
# The v2 tree has no `wasm-bindgen`: the browser door is a plain
# WebAssembly module, and the tree's own bundler
# (`apps/craftkit-wasm/src/bin/bundle.rs`) copies it and the page into
# `dist/`. So there is no CLI to install and no version to match — the
# bundler is this tree's own code, and it cannot drift from the page.
- name: Produce the browser bundle
run: cargo xtask bundle
- name: The page loads the module this job just produced
# bash for the same reason as the step above.
shell: bash
run: |
# Read the one constant the page and the bundler both come from, and
# require the file to exist. A version of this step that only ran
# `cargo xtask wasm` passed on a page that 404s.
name=$(sed -n 's/.*const BUNDLE_NAME: &str = "\(.*\)";.*/\1/p' xtask/src/wasm.rs)
echo "the module is named $name"
cd apps/craftkit-wasm
test -f "dist/$name.wasm" || {
echo "::error::apps/craftkit-wasm/dist/$name.wasm was not produced"; exit 1; }
test -f dist/index.html || {
echo "::error::apps/craftkit-wasm/dist/index.html was not produced"; exit 1; }
grep -q "./$name.wasm" index.html || {
echo "::error::index.html does not fetch ./$name.wasm"; exit 1; }
echo "ok: the page fetches ./$name.wasm and the job produced it"
# The module is driven with no browser at all, under Node. A page that
# loads a module the script cannot drive is a page that only looks right.
- name: Drive the module without a browser
run: node apps/craftkit-wasm/browser-check.mjs apps/craftkit-wasm/dist/craftkit_wasm.wasm
# What a Linux build machine cannot tell you.
portability:
name: portability
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
# An old toolchain that still compiles is still a broken promise.
- name: The declared minimum toolchain
run: |
rustup toolchain install "$(grep -m1 rust-version Cargo.toml | cut -d'"' -f2)" \
--profile minimal --component clippy,rustfmt
cargo +"$(grep -m1 rust-version Cargo.toml | cut -d'"' -f2)" xtask ci
# Not part of `cargo xtask ci`, because it needs a network and a licence
# database, and a gate that fails for want of either gets switched off.
#
# It is a gate all the same, and it has a name in the tree: `cargo xtask
# deny`. The workflow runs that command, so the rule and the check that
# applies it live in the same place.
policy:
name: policy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
# The tool the tree's own gate needs, installed where the gate can find
# it.
#
# The tool is installed the way the tree's own documentation says:
# `cargo install cargo-deny --locked`, into `$CARGO_HOME/bin`, which is
# on the PATH of every later step.
- name: Install cargo-deny
run: cargo install cargo-deny --locked
# Licences, bans, sources and advisories. `deny.toml` is in the
# repository; `cargo xtask deny` reads it.
- name: Licence and advisory policy
run: cargo xtask deny
# ATTRIBUTION.md must exist and agree with the tree. Already part of
# `cargo xtask assets`; run again on its own so a failure here is
# obviously about attribution rather than about layering.
- name: Attribution
run: cargo xtask assets