Skip to content

Commit 545a53f

Browse files
committed
CI - Move simple jobs into cargo ci
1 parent cf5250a commit 545a53f

2 files changed

Lines changed: 86 additions & 71 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 70 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 }})
@@ -1178,13 +1162,12 @@ jobs:
11781162
restore-keys: |
11791163
${{ runner.os }}-pnpm-store-
11801164
1181-
- name: Install dependencies
1182-
working-directory: docs
1183-
run: pnpm install
1165+
- uses: dsherret/rust-toolchain-file@v1
1166+
- name: Set default rust toolchain
1167+
run: rustup default $(rustup show active-toolchain | cut -d' ' -f1)
11841168

11851169
- name: Docusaurus build
1186-
working-directory: docs
1187-
run: pnpm build
1170+
run: cargo ci docs
11881171

11891172
typescript-test:
11901173
name: TypeScript - Tests
@@ -1216,14 +1199,6 @@ jobs:
12161199
restore-keys: |
12171200
${{ runner.os }}-pnpm-store-
12181201
1219-
- name: Build module library and SDK
1220-
working-directory: crates/bindings-typescript
1221-
run: pnpm build
1222-
1223-
- name: Run module library and SDK tests
1224-
working-directory: crates/bindings-typescript
1225-
run: pnpm test
1226-
12271202
# - name: Extract SpacetimeDB branch name from file
12281203
# id: extract-branch
12291204
# run: |
@@ -1293,46 +1268,8 @@ jobs:
12931268
# Clear any existing information
12941269
spacetime server clear -y
12951270
1296-
- name: Generate client bindings
1297-
working-directory: templates/chat-react-ts
1298-
run: |
1299-
pnpm generate
1300-
1301-
- name: Check for changes
1302-
working-directory: templates/chat-react-ts
1303-
run: |
1304-
"${GITHUB_WORKSPACE}"/tools/check-diff.sh src/module_bindings || {
1305-
echo "Error: Bindings are dirty. Please generate bindings again and commit them to this branch."
1306-
exit 1
1307-
}
1308-
1309-
# - name: Start SpacetimeDB
1310-
# run: |
1311-
# spacetime start &
1312-
# disown
1313-
1314-
# - name: Publish module to SpacetimeDB
1315-
# working-directory: SpacetimeDB/templates/quickstart-chat-typescript/spacetimedb
1316-
# run: |
1317-
# spacetime logout && spacetime login --server-issued-login local
1318-
# spacetime publish -s local quickstart-chat -c -y
1319-
1320-
# - name: Publish module to SpacetimeDB
1321-
# working-directory: SpacetimeDB/templates/quickstart-chat-typescript/spacetimedb
1322-
# run: |
1323-
# spacetime logs quickstart-chat
1324-
1325-
- name: Check that quickstart-chat builds
1326-
working-directory: templates/chat-react-ts
1327-
run: pnpm build
1328-
1329-
- name: Check that templates build
1330-
working-directory: templates/
1331-
run: pnpm -r --filter "./**" run build
1332-
1333-
- name: Check that subdirectories build
1334-
working-directory: crates/bindings-typescript
1335-
run: pnpm -r --filter "./**" run build
1271+
- name: Run TypeScript tests
1272+
run: cargo ci typescript-test
13361273

13371274
# - name: Run quickstart-chat tests
13381275
# working-directory: examples/quickstart-chat

tools/ci/src/main.rs

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#![allow(clippy::disallowed_macros)]
22

3-
use anyhow::{bail, Result};
3+
use anyhow::{bail, ensure, Result};
44
use clap::{CommandFactory, Parser, Subcommand};
55
use duct::cmd;
6+
use regex::Regex;
67
use std::ffi::OsStr;
78
use std::ffi::OsString;
89
use std::path::Path;
@@ -272,6 +273,12 @@ enum CiCmd {
272273

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

277284
fn run_all_clap_subcommands(skips: &[String]) -> Result<()> {
@@ -300,6 +307,65 @@ fn tracked_rs_files_under(path: &str) -> Result<Vec<PathBuf>> {
300307
.collect())
301308
}
302309

310+
fn run_publish_checks() -> Result<()> {
311+
cmd!("bash", "-lc", "test -d venv || python3 -m venv venv").run()?;
312+
cmd!("venv/bin/pip3", "install", "argparse", "toml").run()?;
313+
314+
let crates = cmd!(
315+
"venv/bin/python3",
316+
"tools/find-publish-list.py",
317+
"--recursive",
318+
"--directories",
319+
"--quiet",
320+
"spacetimedb",
321+
"spacetimedb-sdk"
322+
)
323+
.read()?;
324+
325+
let mut failed = Vec::new();
326+
for crate_dir in crates.split_whitespace() {
327+
if let Err(err) = cmd!("venv/bin/python3", "tools/crate-publish-checks.py", crate_dir).run() {
328+
eprintln!("crate publish checks failed for {crate_dir}: {err}");
329+
failed.push(crate_dir.to_string());
330+
}
331+
}
332+
333+
if !failed.is_empty() {
334+
bail!("crate publish checks failed for: {}", failed.join(", "));
335+
}
336+
337+
Ok(())
338+
}
339+
340+
fn run_typescript_tests() -> Result<()> {
341+
cmd!("pnpm", "build").dir("crates/bindings-typescript").run()?;
342+
cmd!("pnpm", "test").dir("crates/bindings-typescript").run()?;
343+
cmd!("pnpm", "generate").dir("templates/chat-react-ts").run()?;
344+
let diff_status = cmd!(
345+
"bash",
346+
"tools/check-diff.sh",
347+
"templates/chat-react-ts/src/module_bindings"
348+
)
349+
.run()?;
350+
if !diff_status.status.success() {
351+
bail!("Bindings are dirty. Please generate bindings again and commit them to this branch.");
352+
}
353+
cmd!("pnpm", "build").dir("templates/chat-react-ts").run()?;
354+
cmd!("pnpm", "-r", "--filter", "./**", "run", "build")
355+
.dir("templates")
356+
.run()?;
357+
cmd!("pnpm", "-r", "--filter", "./**", "run", "build")
358+
.dir("crates/bindings-typescript")
359+
.run()?;
360+
Ok(())
361+
}
362+
363+
fn run_docs_build() -> Result<()> {
364+
cmd!("pnpm", "install").dir("docs").run()?;
365+
cmd!("pnpm", "build").dir("docs").run()?;
366+
Ok(())
367+
}
368+
303369
fn main() -> Result<()> {
304370
env_logger::init();
305371

@@ -627,6 +693,18 @@ fn main() -> Result<()> {
627693
check_global_json_policy()?;
628694
}
629695

696+
Some(CiCmd::PublishChecks) => {
697+
run_publish_checks()?;
698+
}
699+
700+
Some(CiCmd::TypescriptTest) => {
701+
run_typescript_tests()?;
702+
}
703+
704+
Some(CiCmd::Docs) => {
705+
run_docs_build()?;
706+
}
707+
630708
None => run_all_clap_subcommands(&cli.skip)?,
631709
}
632710

0 commit comments

Comments
 (0)