Skip to content

Commit 8242dda

Browse files
Merge branch 'master' into tyler/ts-sdk-improvements
2 parents 7511d33 + ba31c80 commit 8242dda

16 files changed

Lines changed: 1003 additions & 568 deletions

File tree

.github/workflows/ci.yml

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ jobs:
2222
name: Smoketests
2323
strategy:
2424
matrix:
25+
runner: [spacetimedb-new-runner, windows-latest]
2526
include:
26-
- { runner: spacetimedb-runner, smoketest_args: --docker }
27-
- { runner: windows-latest, smoketest_args: --no-build-cli }
28-
runner: [ spacetimedb-runner, windows-latest ]
27+
- runner: spacetimedb-new-runner
28+
smoketest_args: --docker
29+
container:
30+
image: localhost:5000/spacetimedb-ci:latest
31+
options: --privileged
32+
- runner: windows-latest
33+
smoketest_args: --no-build-cli
34+
container: null
2935
runs-on: ${{ matrix.runner }}
36+
container: ${{ matrix.container }}
37+
3038
steps:
3139
- name: Find Git ref
3240
env:
@@ -63,6 +71,10 @@ jobs:
6371
if: runner.os == 'Windows'
6472
run: choco install psql -y --no-progress
6573
shell: powershell
74+
- name: Start Docker daemon
75+
if: runner.os == 'Linux'
76+
run: /usr/local/bin/start-docker.sh
77+
6678
- name: Build and start database (Linux)
6779
if: runner.os == 'Linux'
6880
run: docker compose up -d
@@ -93,7 +105,11 @@ jobs:
93105

94106
test:
95107
name: Test Suite
96-
runs-on: spacetimedb-runner
108+
runs-on: spacetimedb-new-runner
109+
container:
110+
image: localhost:5000/spacetimedb-ci:latest
111+
options: >-
112+
--privileged
97113
steps:
98114
- name: Find Git ref
99115
env:
@@ -140,8 +156,9 @@ jobs:
140156
#Note: Unreal tests will be run separately
141157
run: cargo test --all -- --skip unreal
142158

159+
# The fallocate tests have been flakely when running in parallel
143160
- name: Run fallocate tests
144-
run: cargo test -p spacetimedb-durability --features fallocate
161+
run: cargo test -p spacetimedb-durability --features fallocate -- --test-threads=1
145162

146163
- name: Check that the test outputs are up-to-date
147164
run: bash tools/check-diff.sh
@@ -157,7 +174,11 @@ jobs:
157174

158175
lints:
159176
name: Lints
160-
runs-on: spacetimedb-runner
177+
runs-on: spacetimedb-new-runner
178+
container:
179+
image: localhost:5000/spacetimedb-ci:latest
180+
options: >-
181+
--privileged
161182
steps:
162183
- name: Checkout sources
163184
uses: actions/checkout@v3
@@ -196,7 +217,11 @@ jobs:
196217
197218
wasm_bindings:
198219
name: Build and test wasm bindings
199-
runs-on: spacetimedb-runner
220+
runs-on: spacetimedb-new-runner
221+
container:
222+
image: localhost:5000/spacetimedb-ci:latest
223+
options: >-
224+
--privileged
200225
steps:
201226
- uses: actions/checkout@v3
202227

@@ -221,7 +246,11 @@ jobs:
221246

222247
publish_checks:
223248
name: Check that packages are publishable
224-
runs-on: ubuntu-latest
249+
runs-on: spacetimedb-new-runner
250+
container:
251+
image: localhost:5000/spacetimedb-ci:latest
252+
options: >-
253+
--privileged
225254
permissions: read-all
226255
steps:
227256
- uses: actions/checkout@v3
@@ -289,7 +318,7 @@ jobs:
289318
name: Unreal Engine Tests
290319
# This can't go on e.g. ubuntu-latest because that runner runs out of disk space. ChatGPT suggested that the general solution tends to be to use
291320
# a custom runner.
292-
runs-on: spacetimedb-runner
321+
runs-on: spacetimedb-new-runner
293322
# Skip if this is an external contribution. GitHub secrets will be empty, so the step would fail anyway.
294323
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
295324
container:
@@ -368,13 +397,17 @@ jobs:
368397
369398
cd "$GITHUB_WORKSPACE/sdks/unreal"
370399
cargo --version
371-
cargo test
400+
cargo test -- --test-threads=1
372401
'
373402
374403
cli_docs:
375404
name: Check CLI docs
376405
permissions: read-all
377-
runs-on: ubuntu-latest
406+
runs-on: spacetimedb-new-runner
407+
container:
408+
image: localhost:5000/spacetimedb-ci:latest
409+
options: >-
410+
--privileged
378411
steps:
379412
- name: Find Git ref
380413
env:

.github/workflows/csharp-test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ concurrency:
1212

1313
jobs:
1414
unity-testsuite:
15-
runs-on: spacetimedb-runner
15+
runs-on: spacetimedb-new-runner
16+
container:
17+
image: localhost:5000/spacetimedb-ci:latest
18+
options: >-
19+
--privileged
20+
--cgroupns=host
1621
# Cancel any previous testsuites running on the same PR and/or ref.
1722
concurrency:
1823
group: unity-test-${{ github.event.pull_request.number || github.ref }}
@@ -81,7 +86,7 @@ jobs:
8186
cargo install --force --path crates/cli --locked --message-format=short
8287
cargo install --force --path crates/standalone --locked --message-format=short
8388
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
84-
ln -sf $HOME/.cargo/bin/spacetimedb-cli $HOME/.cargo/bin/spacetime
89+
ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
8590
env:
8691
# Share the target directory with our local project to avoid rebuilding same SpacetimeDB crates twice.
8792
CARGO_TARGET_DIR: demo/Blackholio/server-rust/target
@@ -157,6 +162,9 @@ jobs:
157162
key: Unity-${{ github.head_ref }}
158163
restore-keys: Unity-
159164

165+
# We need this to support "Docker in Docker"
166+
- name: Start Docker daemon
167+
run: /usr/local/bin/start-docker.sh
160168
- name: Run Unity tests
161169
uses: game-ci/unity-test-runner@v4
162170
with:

.github/workflows/discord-posts.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
PR_NUMBER: ${{ github.event.pull_request.number }}
2828
PR_URL: ${{ github.event.pull_request.html_url }}
2929
MENTION_ON_FAILURE: ${{ secrets.DEV_OPS_ROLE_ID }}
30+
DISCORD_USER_MAP: ${{ secrets.DISCORD_USER_MAP }}
3031
run: |
3132
message="PR merged: [(#${PR_NUMBER}) ${PR_TITLE}](<${PR_URL}>)"
3233
# Note that anything besides success is treated as a failure (e.g. if the check did not run at all, or if it is still pending).
@@ -39,6 +40,18 @@ jobs:
3940
' |
4041
jq -r '"\(.workflow) / \(.name): \(.state)"'
4142
)"
43+
44+
# Lookup PR author's Discord ID from the provided JSON map (if any)
45+
author_discord_id="$(
46+
jq -r \
47+
--arg u "${{ github.event.pull_request.user.login }}" \
48+
'try .[$u] catch empty' \
49+
<<<"${DISCORD_USER_MAP}"
50+
)"
51+
if [ -z "${author_discord_id}" ]; then
52+
echo "Warning: PR author not found not found in USER_LOOKUP_JSON"
53+
fi
54+
4255
message+=$'\n'
4356
if [[ -z "${FAILED_CHECKS}" ]]; then
4457
message+='All checks passed.'
@@ -47,7 +60,11 @@ jobs:
4760
message+=$'\n'
4861
# This uses special Discord syntax for pinging a particular role.
4962
# Note the '&' - this is the difference between pinging a *role* and pinging a *person*.
50-
message+=" (cc <@&${MENTION_ON_FAILURE}>)"
63+
message+=" (cc <@&${MENTION_ON_FAILURE}>"
64+
if [[ -n "${author_discord_id}" ]]; then
65+
message+=" <@${author_discord_id}>"
66+
fi
67+
message+=")"
5168
fi
5269
# Use `jq` to construct the json data blob in the format required by the webhook.
5370
data="$(jq --null-input --arg msg "$message" '.content=$msg')"

.github/workflows/internal-tests.yml

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ jobs:
1818
# Skip if this is an external contribution. GitHub secrets will be empty, so the step would fail anyway.
1919
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
2020
runs-on: ubuntu-latest
21+
env:
22+
TARGET_OWNER: clockworklabs
23+
TARGET_REPO: SpacetimeDBPrivate
2124
steps:
22-
- name: Trigger and wait for Internal Tests
25+
- id: dispatch
26+
name: Trigger tests
2327
uses: actions/github-script@v7
2428
with:
2529
github-token: ${{ secrets.SPACETIMEDB_PRIVATE_TOKEN }}
2630
script: |
27-
const targetOwner = 'clockworklabs';
28-
const targetRepo = 'SpacetimeDBPrivate';
2931
const workflowId = 'ci.yml';
3032
const targetRef = 'master';
33+
const targetOwner = process.env.TARGET_OWNER;
34+
const targetRepo = process.env.TARGET_REPO;
3135
// Use the ref for pull requests because the head sha is brittle (github does some extra dance where it merges in master).
3236
const publicRef = (context.eventName === 'pull_request') ? context.payload.pull_request.head.ref : context.sha;
3337
const preDispatch = new Date().toISOString();
@@ -48,12 +52,10 @@ jobs:
4852
4953
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
5054
51-
// Wait for workflow to be kicked off
52-
await sleep(30000);
53-
5455
// Find the dispatched run by name
5556
let runId = null;
5657
for (let attempt = 0; attempt < 20 && !runId; attempt++) { // up to ~10 minutes to locate the run
58+
await sleep(5000);
5759
const runsResp = await github.rest.actions.listWorkflowRuns({
5860
owner: targetOwner,
5961
repo: targetRepo,
@@ -72,7 +74,6 @@ jobs:
7274
runId = candidates[0].id;
7375
break;
7476
}
75-
await sleep(30000);
7677
}
7778
7879
if (!runId) {
@@ -83,9 +84,23 @@ jobs:
8384
// Provide direct link and context prior to waiting
8485
const runUrl = `https://github.com/${targetOwner}/${targetRepo}/actions/runs/${runId}`;
8586
core.info(`View run: ${runUrl}`);
86-
core.info('Waiting for workflow result...');
8787
88-
// Wait for completion
88+
core.setOutput('run_id', String(runId));
89+
core.setOutput('run_url', runUrl);
90+
91+
- name: Wait for Internal Tests to complete
92+
uses: actions/github-script@v7
93+
with:
94+
github-token: ${{ secrets.SPACETIMEDB_PRIVATE_TOKEN }}
95+
script: |
96+
const targetOwner = process.env.TARGET_OWNER;
97+
const targetRepo = process.env.TARGET_REPO;
98+
const runId = Number(`${{ steps.dispatch.outputs.run_id }}`);
99+
const runUrl = `${{ steps.dispatch.outputs.run_url }}`;
100+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
101+
102+
core.info(`Waiting for workflow result... ${runUrl}`);
103+
89104
let conclusion = null;
90105
for (let attempt = 0; attempt < 240; attempt++) { // up to ~2 hours
91106
const runResp = await github.rest.actions.getWorkflowRun({
@@ -110,3 +125,24 @@ jobs:
110125
if (conclusion !== 'success') {
111126
core.setFailed(`Private workflow failed with conclusion: ${conclusion}`);
112127
}
128+
129+
- name: Cancel invoked run if workflow cancelled
130+
if: ${{ cancelled() }}
131+
uses: actions/github-script@v7
132+
with:
133+
github-token: ${{ secrets.SPACETIMEDB_PRIVATE_TOKEN }}
134+
script: |
135+
const targetOwner = process.env.TARGET_OWNER;
136+
const targetRepo = process.env.TARGET_REPO;
137+
const runId = Number(`${{ steps.dispatch.outputs.run_id }}`);
138+
if (!runId) {
139+
core.warning('No run_id available to cancel.');
140+
return;
141+
}
142+
core.info(`Cancelling private workflow run ${runId} in ${targetOwner}/${targetRepo}...`);
143+
await github.rest.actions.cancelWorkflowRun({
144+
owner: targetOwner,
145+
repo: targetRepo,
146+
run_id: runId,
147+
});
148+
core.info('Cancellation requested.');

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ enum-map = "2.6.3"
178178
env_logger = "0.10"
179179
ethnum = { version = "1.5.0", features = ["serde"] }
180180
flate2 = "1.0.24"
181+
flume = { version = "0.11", default-features = false, features = ["async"] }
181182
foldhash = "0.1.4"
182183
fs-err = "2.9.0"
183184
fs_extra = "1.3.0"
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
mod module_bindings;
22
use module_bindings::*;
33
use std::env;
4+
use std::io::{self, Read};
45

5-
use spacetimedb_sdk::{DbConnection, Table};
6+
use spacetimedb_sdk::{DbContext, Table};
67

78
fn main() {
89
// The URI of the SpacetimeDB instance hosting our chat module.
@@ -14,28 +15,31 @@ fn main() {
1415
// Connect to the database
1516
let conn = DbConnection::builder()
1617
.with_module_name(db_name)
17-
.with_host(host)
18+
.with_uri(host)
1819
.on_connect(|_, _, _| {
1920
println!("Connected to SpacetimeDB");
2021
})
21-
.on_connect_error(|e| {
22+
.on_connect_error(|_ctx, e| {
2223
eprintln!("Connection error: {:?}", e);
2324
std::process::exit(1);
2425
})
2526
.build()
2627
.expect("Failed to connect");
2728

29+
conn.run_threaded();
30+
2831
// Subscribe to the person table
29-
conn.subscribe(&[
30-
"SELECT * FROM person"
31-
]);
32+
conn.subscription_builder()
33+
.on_applied(|_ctx| println!("Subscripted to the person table"))
34+
.on_error(|_ctx, e| eprintln!("There was an error when subscring to the person table: {e}"))
35+
.subscribe(["SELECT * FROM person"]);
3236

3337
// Register a callback for when rows are inserted into the person table
34-
Person::on_insert(|_ctx, person| {
38+
conn.db().person().on_insert(|_ctx, person| {
3539
println!("New person: {}", person.name);
3640
});
3741

38-
// Run the connection on the current thread
39-
// This will block and handle all database events
40-
conn.run();
42+
println!("Press any key to exit...");
43+
44+
let _ = io::stdin().read(&mut [0u8]).unwrap();
4145
}

crates/cli/templates/basic-rust/server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use spacetimedb::{ReducerContext, Table};
22

3-
#[spacetimedb::table(name = person)]
3+
#[spacetimedb::table(name = person, public)]
44
pub struct Person {
55
name: String,
66
}

0 commit comments

Comments
 (0)