Skip to content

Commit 604bb3e

Browse files
authored
CI - Move simple jobs into cargo ci (#4871)
# Description of Changes Migrate these checks into `cargo ci`: - Check that packages are publishable - Docs test - TypeScript - Tests # API and ABI breaking changes None. CI only. # Expected complexity level and risk 2 # Testing - [ ] CI passes --------- Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent 0a08879 commit 604bb3e

3 files changed

Lines changed: 144 additions & 97 deletions

File tree

.github/workflows/ci.yml

Lines changed: 34 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -342,24 +342,8 @@ jobs:
342342
- uses: dsherret/rust-toolchain-file@v1
343343
- name: Set default rust toolchain
344344
run: rustup default $(rustup show active-toolchain | cut -d' ' -f1)
345-
- name: Set up Python env
346-
run: |
347-
test -d venv || python3 -m venv venv
348-
venv/bin/pip3 install argparse toml
349345
- name: Run checks
350-
run: |
351-
set -ueo pipefail
352-
FAILED=0
353-
ROOTS=(spacetimedb spacetimedb-sdk)
354-
CRATES=$(venv/bin/python3 tools/find-publish-list.py --recursive --directories --quiet "${ROOTS[@]}")
355-
for crate_dir in $CRATES; do
356-
if ! venv/bin/python3 tools/crate-publish-checks.py "${crate_dir}"; then
357-
FAILED=$(( $FAILED + 1 ))
358-
fi
359-
done
360-
if [ $FAILED -gt 0 ]; then
361-
exit 1
362-
fi
346+
run: cargo ci publish-checks
363347

364348
update:
365349
name: Test spacetimedb-update flow (${{ matrix.target }})
@@ -1160,13 +1144,12 @@ jobs:
11601144
restore-keys: |
11611145
${{ runner.os }}-pnpm-store-
11621146
1163-
- name: Install dependencies
1164-
working-directory: docs
1165-
run: pnpm install
1147+
- uses: dsherret/rust-toolchain-file@v1
1148+
- name: Set default rust toolchain
1149+
run: rustup default $(rustup show active-toolchain | cut -d' ' -f1)
11661150

11671151
- name: Docusaurus build
1168-
working-directory: docs
1169-
run: pnpm build
1152+
run: cargo ci docs
11701153

11711154
typescript-test:
11721155
name: TypeScript - Tests
@@ -1198,14 +1181,6 @@ jobs:
11981181
restore-keys: |
11991182
${{ runner.os }}-pnpm-store-
12001183
1201-
- name: Build module library and SDK
1202-
working-directory: crates/bindings-typescript
1203-
run: pnpm build
1204-
1205-
- name: Run module library and SDK tests
1206-
working-directory: crates/bindings-typescript
1207-
run: pnpm test
1208-
12091184
# - name: Extract SpacetimeDB branch name from file
12101185
# id: extract-branch
12111186
# run: |
@@ -1245,76 +1220,38 @@ jobs:
12451220
save-if: false
12461221
prefix-key: v1
12471222

1248-
# This step shouldn't be needed, but somehow we end up with caches that are missing librusty_v8.a.
1249-
# ChatGPT suspects that this could be due to different build invocations using the same target dir,
1250-
# and this makes sense to me because we only see it in this job where we mix `cargo build -p` with
1251-
# `cargo build --manifest-path` (which apparently build different dependency trees).
1252-
# However, we've been unable to fix it so... /shrug
1253-
- name: Check v8 outputs
1254-
run: |
1255-
find "${CARGO_TARGET_DIR}"/ -type f | grep '[/_]v8' || true
1256-
if ! [ -f "${CARGO_TARGET_DIR}"/debug/gn_out/obj/librusty_v8.a ]; then
1257-
echo "Could not find v8 output file librusty_v8.a; rebuilding manually."
1258-
cargo clean -p v8 || true
1259-
cargo build -p v8
1260-
fi
1261-
if ! [ -f "${CARGO_TARGET_DIR}"/release/gn_out/obj/librusty_v8.a ]; then
1262-
echo "Could not find v8 output file librusty_v8.a; rebuilding manually."
1263-
cargo clean --release -p v8 || true
1264-
cargo build --release -p v8
1265-
fi
1266-
1267-
- name: Install SpacetimeDB CLI from the local checkout
1268-
run: |
1269-
export CARGO_HOME="$HOME/.cargo"
1270-
echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
1271-
cargo install --force --path crates/cli --locked --message-format=short
1272-
cargo install --force --path crates/standalone --locked --message-format=short
1273-
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
1274-
ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
1275-
# Clear any existing information
1276-
spacetime server clear -y
1277-
1278-
- name: Generate client bindings
1279-
working-directory: templates/chat-react-ts
1280-
run: |
1281-
pnpm generate
1282-
1283-
- name: Check for changes
1284-
working-directory: templates/chat-react-ts
1285-
run: |
1286-
"${GITHUB_WORKSPACE}"/tools/check-diff.sh src/module_bindings || {
1287-
echo "Error: Bindings are dirty. Please generate bindings again and commit them to this branch."
1288-
exit 1
1289-
}
1290-
1291-
# - name: Start SpacetimeDB
1292-
# run: |
1293-
# spacetime start &
1294-
# disown
1295-
1296-
# - name: Publish module to SpacetimeDB
1297-
# working-directory: SpacetimeDB/templates/quickstart-chat-typescript/spacetimedb
1223+
# # This step shouldn't be needed, but somehow we end up with caches that are missing librusty_v8.a.
1224+
# # ChatGPT suspects that this could be due to different build invocations using the same target dir,
1225+
# # and this makes sense to me because we only see it in this job where we mix `cargo build -p` with
1226+
# # `cargo build --manifest-path` (which apparently build different dependency trees).
1227+
# # However, we've been unable to fix it so... /shrug
1228+
# - name: Check v8 outputs
12981229
# run: |
1299-
# spacetime logout && spacetime login --server-issued-login local
1300-
# spacetime publish -s local quickstart-chat -c -y
1230+
# find "${CARGO_TARGET_DIR}"/ -type f | grep '[/_]v8' || true
1231+
# if ! [ -f "${CARGO_TARGET_DIR}"/debug/gn_out/obj/librusty_v8.a ]; then
1232+
# echo "Could not find v8 output file librusty_v8.a; rebuilding manually."
1233+
# cargo clean -p v8 || true
1234+
# cargo build -p v8
1235+
# fi
1236+
# if ! [ -f "${CARGO_TARGET_DIR}"/release/gn_out/obj/librusty_v8.a ]; then
1237+
# echo "Could not find v8 output file librusty_v8.a; rebuilding manually."
1238+
# cargo clean --release -p v8 || true
1239+
# cargo build --release -p v8
1240+
# fi
13011241

1302-
# - name: Publish module to SpacetimeDB
1303-
# working-directory: SpacetimeDB/templates/quickstart-chat-typescript/spacetimedb
1242+
# - name: Install SpacetimeDB CLI from the local checkout
13041243
# run: |
1305-
# spacetime logs quickstart-chat
1306-
1307-
- name: Check that quickstart-chat builds
1308-
working-directory: templates/chat-react-ts
1309-
run: pnpm build
1310-
1311-
- name: Check that templates build
1312-
working-directory: templates/
1313-
run: pnpm -r --filter "./**" run build
1314-
1315-
- name: Check that subdirectories build
1316-
working-directory: crates/bindings-typescript
1317-
run: pnpm -r --filter "./**" run build
1244+
# export CARGO_HOME="$HOME/.cargo"
1245+
# echo "$CARGO_HOME/bin" >> "$GITHUB_PATH"
1246+
# cargo install --force --path crates/cli --locked --message-format=short
1247+
# cargo install --force --path crates/standalone --locked --message-format=short
1248+
# # Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
1249+
# ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
1250+
# # Clear any existing information
1251+
# spacetime server clear -y
1252+
1253+
- name: Run TypeScript tests
1254+
run: cargo ci typescript-test
13181255

13191256
# - name: Run quickstart-chat tests
13201257
# working-directory: examples/quickstart-chat

tools/ci/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,39 @@ Usage: global-json-policy
195195

196196
- `--help`: Print help
197197

198+
### `publish-checks`
199+
200+
**Usage:**
201+
```bash
202+
Usage: publish-checks
203+
```
204+
205+
**Options:**
206+
207+
- `--help`: Print help
208+
209+
### `typescript-test`
210+
211+
**Usage:**
212+
```bash
213+
Usage: typescript-test
214+
```
215+
216+
**Options:**
217+
218+
- `--help`: Print help
219+
220+
### `docs`
221+
222+
**Usage:**
223+
```bash
224+
Usage: docs
225+
```
226+
227+
**Options:**
228+
229+
- `--help`: Print help
230+
198231
### `help`
199232

200233
**Usage:**

tools/ci/src/main.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ enum CiCmd {
272272

273273
/// Verify that any non-root global.json files are symlinks to the root global.json.
274274
GlobalJsonPolicy,
275+
/// Checks that publishable crates satisfy publish constraints.
276+
PublishChecks,
277+
/// Runs TypeScript workspace tests and template build checks.
278+
TypescriptTest,
279+
/// Builds the docs site.
280+
Docs,
275281
}
276282

277283
fn run_all_clap_subcommands(skips: &[String]) -> Result<()> {
@@ -378,6 +384,65 @@ fn run_dlls() -> Result<()> {
378384
Ok(())
379385
}
380386

387+
fn run_publish_checks() -> Result<()> {
388+
cmd!("bash", "-lc", "test -d venv || python3 -m venv venv").run()?;
389+
cmd!("venv/bin/pip3", "install", "argparse", "toml").run()?;
390+
391+
let crates = cmd!(
392+
"venv/bin/python3",
393+
"tools/find-publish-list.py",
394+
"--recursive",
395+
"--directories",
396+
"--quiet",
397+
"spacetimedb",
398+
"spacetimedb-sdk"
399+
)
400+
.read()?;
401+
402+
let mut failed = Vec::new();
403+
for crate_dir in crates.split_whitespace() {
404+
if let Err(err) = cmd!("venv/bin/python3", "tools/crate-publish-checks.py", crate_dir).run() {
405+
eprintln!("crate publish checks failed for {crate_dir}: {err}");
406+
failed.push(crate_dir.to_string());
407+
}
408+
}
409+
410+
if !failed.is_empty() {
411+
bail!("crate publish checks failed for: {}", failed.join(", "));
412+
}
413+
414+
Ok(())
415+
}
416+
417+
fn run_typescript_tests() -> Result<()> {
418+
cmd!("pnpm", "build").dir("crates/bindings-typescript").run()?;
419+
cmd!("pnpm", "test").dir("crates/bindings-typescript").run()?;
420+
cmd!("pnpm", "generate").dir("templates/chat-react-ts").run()?;
421+
let diff_status = cmd!(
422+
"bash",
423+
"tools/check-diff.sh",
424+
"templates/chat-react-ts/src/module_bindings"
425+
)
426+
.run()?;
427+
if !diff_status.status.success() {
428+
bail!("Bindings are dirty. Please generate bindings again and commit them to this branch.");
429+
}
430+
cmd!("pnpm", "build").dir("templates/chat-react-ts").run()?;
431+
cmd!("pnpm", "-r", "--filter", "./**", "run", "build")
432+
.dir("templates")
433+
.run()?;
434+
cmd!("pnpm", "-r", "--filter", "./**", "run", "build")
435+
.dir("crates/bindings-typescript")
436+
.run()?;
437+
Ok(())
438+
}
439+
440+
fn run_docs_build() -> Result<()> {
441+
cmd!("pnpm", "install").dir("docs").run()?;
442+
cmd!("pnpm", "build").dir("docs").run()?;
443+
Ok(())
444+
}
445+
381446
fn main() -> Result<()> {
382447
env_logger::init();
383448

@@ -638,6 +703,18 @@ fn main() -> Result<()> {
638703
check_global_json_policy()?;
639704
}
640705

706+
Some(CiCmd::PublishChecks) => {
707+
run_publish_checks()?;
708+
}
709+
710+
Some(CiCmd::TypescriptTest) => {
711+
run_typescript_tests()?;
712+
}
713+
714+
Some(CiCmd::Docs) => {
715+
run_docs_build()?;
716+
}
717+
641718
None => run_all_clap_subcommands(&cli.skip)?,
642719
}
643720

0 commit comments

Comments
 (0)