Repository navigation
228 lines (217 loc) · 11.2 KB
/
Copy pathci.yml
File metadata and controls
228 lines (217 loc) · 11.2 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: ci
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
# A newer push to a PR supersedes its older run.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
# The checks run as parallel jobs; `threert`, the last one, is the one to read: it fails when any of them failed or was
# cancelled, and passes when every one passed or was skipped by its paths. A PR runs a job only when it changes that
# job's inputs (the `changes` job); a push to main and a manual run run them all.
jobs:
changes:
runs-on: ubuntu-26.04
timeout-minutes: 5
permissions:
pull-requests: read
outputs:
renderer: ${{ steps.paths.outputs.renderer }}
voxel: ${{ steps.paths.outputs.voxel }}
physics: ${{ steps.paths.outputs.physics }}
wasm: ${{ steps.paths.outputs.wasm }}
web: ${{ steps.paths.outputs.web }}
steps:
# Each job's inputs, as patterns on the paths a PR changes (the old and the new path of a rename). A change to the
# workflows, a PR of 3,000 files or more (the most the API lists) and any event other than a PR run every job.
- id: paths
env:
GH_TOKEN: ${{ github.token }}
EVENT: ${{ github.event_name }}
PR: ${{ github.event.pull_request.number }}
CHANGED: ${{ github.event.pull_request.changed_files }}
run: |
all=false files=
if [ "$EVENT" != pull_request ] || [ "$CHANGED" -ge 3000 ]; then
all=true
else
files=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR/files" --paginate --jq '.[] | .filename, (.previous_filename // empty)')
printf '%s\n' "$files"
if grep -Eq '^\.github/' <<< "$files"; then all=true; fi
fi
# job <name> <the paths it runs for> [<paths among those it does not>]
job() {
if [ "$all" = true ] || grep -Ev "${3:-^$}" <<< "$files" | grep -Eq "$2"; then run=true; else run=false; fi
echo "$1=$run" | tee -a "$GITHUB_OUTPUT"
}
# The renderer's release build: the crate, its path dependencies (voxel-core, physics-core, third_party) and
# the presets it embeds (src/files.rs); not the browser module's crate (renderer/web), which it does not build.
# Every Rust job runs for the toolchain (rust-toolchain.toml: the Rust they all build with).
job renderer '^(renderer/|presets/|rust-toolchain\.toml$)' '^renderer/web/'
# voxel-core and its determinism check.
job voxel '^(renderer/voxel-core/|tools/voxel-determinism\.ts$|rust-toolchain\.toml$)'
# physics-core, the patched crates it builds with, its determinism check, and what that check builds of the
# renderer for wasm32 (examples/physics_bits.rs, in the renderer's crate graph: its manifest and lock file;
# the voxel bodies' script it runs there: voxel-core, the renderer's voxel and physics adapters, and the api
# and world they go through).
job physics '^(renderer/(physics-core/|voxel-core/|third_party/|Cargo\.toml$|Cargo\.lock$|examples/physics_bits\.rs$|src/(voxel|physics|api|world)\.rs$)|tools/physics-determinism\.ts$|rust-toolchain\.toml$)'
# The engine's library for wasm32: the same as the renderer's.
job wasm '^(renderer/|presets/|rust-toolchain\.toml$)' '^renderer/web/'
# The browser module (renderer/web, on the engine's library) and tools/web-engine.ts: the module in Node with
# the physics hello world's bundle (games/, packages/, the bundler's and the build's tools, the npm manifests).
job web '^(renderer/|presets/|games/|packages/|tools/(web-engine\.ts|bundle-game\.ts|lib/)|package(-lock)?\.json$|rust-toolchain\.toml$)'
ts:
name: "ts: typecheck, tests"
runs-on: ubuntu-26.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run typecheck
- run: npm test
# The npm packages as they are published: built, installed into an empty project, typechecked and run there.
- run: node tools/npm-pack.ts
renderer:
name: "renderer: release build, unit tests"
needs: changes
if: needs.changes.outputs.renderer == 'true'
runs-on: ubuntu-26.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/cargo-cache
with:
workspaces: renderer
- run: cd renderer && cargo build --release --locked
# The renderer's unit tests (the merge gate's `cargo test --release`). The runner has no GPU: the few tests that
# open a device say "skipped" and return, the rest (scene, world, script, voxel, physics, the merged layout's
# naga checks, the kernel's source switches) run as on a Mac.
- run: cd renderer && cargo test --release --locked
# The voxel bodies and the physics on the CPU, through the engine's own path (ROADMAP § 6 step 8), on the
# physics' own threads as the renderer steps (src/physics.rs `in_pool`; tools/physics-determinism.ts steps from
# outside any pool, which is not that path): the recorded hashes at 2 and 4 threads (native parallel = native
# sequential = wasm32 = recorded), then 10 runs of a fuzz of edits and calls with its checks and a small world
# stepped back to back a million times, which is where the step hung. A step that does not return in 30 s fails
# the job (the example's watchdog), it is not waited for.
- run: cd renderer && THREERT_PHYSICS_THREADS=2 cargo run --release --locked --example physics_fuzz -- --bits --runs 0 --stress 0
- run: cd renderer && THREERT_PHYSICS_THREADS=4 cargo run --release --locked --example physics_fuzz -- --bits --runs 10 --stress 1000000
voxel:
name: "voxel: wasm32, tests, determinism"
needs: changes
if: needs.changes.outputs.voxel == 'true'
runs-on: ubuntu-26.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- run: rustup target add wasm32-unknown-unknown
- uses: ./.github/actions/cargo-cache
with:
workspaces: renderer/voxel-core
# The voxel engine's core builds for the browser (wasm32: players run the game there) and passes its tests.
- run: cd renderer/voxel-core && cargo build --release --locked --target wasm32-unknown-unknown && cargo test --release --locked
# Its edits are deterministic: the same script natively and in wasm32 leaves the same voxels (ROADMAP § 6 step 6).
- run: node tools/voxel-determinism.ts
physics:
name: "physics: wasm32, tests, determinism"
needs: changes
if: needs.changes.outputs.physics == 'true'
runs-on: ubuntu-26.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- run: rustup target add wasm32-unknown-unknown
# Cargo takes a path dependency's sources as changed when they are newer than its build, which a checkout always
# makes them: third_party/glamx, the patched crate under Rapier's (a path dependency), was rebuilt in each of the
# four builds of physics-core below, and Rapier's crates on top of it with it. Its sources get one fixed old
# time instead, and the cache's key holds their hash: it is only restored from a run with the same third_party, so
# the build of glamx it keeps is of these sources (a change to them starts from no cache).
- run: find renderer/third_party -exec touch -d 2000-01-01T00:00:00Z {} +
# physics-core's own target directory, and the renderer's (the determinism check builds the renderer's crate graph
# for wasm32 there).
- uses: ./.github/actions/cargo-cache
with:
key: third-party-${{ hashFiles('renderer/third_party/**') }}
workspaces: |
renderer/physics-core
renderer
# The physics core (Rapier) builds for the browser too, passes its tests, and steps to the same bits natively and
# in wasm32 (ROADMAP § 6 step 7).
- run: cd renderer/physics-core && cargo build --release --locked --target wasm32-unknown-unknown && cargo test --release --locked
- run: node tools/physics-determinism.ts
wasm:
name: "engine: wasm32 library"
needs: changes
if: needs.changes.outputs.wasm == 'true'
runs-on: ubuntu-26.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- run: rustup target add wasm32-unknown-unknown
- uses: ./.github/actions/cargo-cache
with:
workspaces: renderer
# The engine's library builds for the browser (wasm32; docs/RUNTIME.md "The engine's library in a browser").
- run: cd renderer && cargo build --release --locked --lib --target wasm32-unknown-unknown
web:
name: "web: browser module, hello world in Node"
needs: changes
if: needs.changes.outputs.web == 'true'
runs-on: ubuntu-26.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: rustup target add wasm32-unknown-unknown
- uses: ./.github/actions/cargo-cache
with:
workspaces: renderer/web
# The module a page loads: the engine's exports for the browser's JavaScript (renderer/web; docs/RUNTIME.md
# "The engine in a browser"). Running it needs a browser with a GPU: tools/web-hello.ts, on a developer's machine.
- run: cd renderer/web && cargo build --release --locked --target wasm32-unknown-unknown
# wasm-bindgen's CLI writes the module's JavaScript; its version is the crate's (renderer/web/Cargo.toml). Built
# from crates.io with its own lock file (`cargo install --locked`) the first time a version is asked for, and
# the binary kept for the runs after.
- id: bindgen
run: echo "version=$(grep -o 'wasm-bindgen = "=[0-9.]*"' renderer/web/Cargo.toml | grep -o '[0-9][0-9.]*')" >> "$GITHUB_OUTPUT"
- id: bindgen-cli
uses: actions/cache@v6
with:
path: ~/.cargo/bin/wasm-bindgen
key: wasm-bindgen-${{ runner.os }}-${{ steps.bindgen.outputs.version }}
- if: steps.bindgen-cli.outputs.cache-hit != 'true'
env:
VERSION: ${{ steps.bindgen.outputs.version }}
run: cargo install wasm-bindgen-cli --version "$VERSION" --locked
# The browser's side of it without a browser or a GPU: the module in Node, the page's `__engine` over its exports,
# the game bundle the native runtime loads, the physics hello world's script and its checks (tools/web-engine.ts).
- run: node tools/web-engine.ts
# The check to read before merging (`gh pr checks <n>`: `threert`).
threert:
needs: [changes, ts, renderer, voxel, physics, wasm, web]
if: ${{ !cancelled() }}
runs-on: ubuntu-26.04
timeout-minutes: 5
steps:
- env:
RESULTS: ${{ toJSON(needs) }}
run: |
jq -r 'to_entries[] | "\(.key): \(.value.result)"' <<< "$RESULTS"
jq -e 'all(.[]; .result == "success" or .result == "skipped")' <<< "$RESULTS" > /dev/null