Skip to content

Commit 273bcf5

Browse files
committed
[bfops/typescript-sdk-ci]: add back test.yml
1 parent f554334 commit 273bcf5

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: TypeScript - Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
compile-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 18
21+
22+
- uses: pnpm/action-setup@v4
23+
with:
24+
version: 9.7
25+
run_install: true
26+
27+
- name: Get pnpm store directory
28+
shell: bash
29+
working-directory: sdks/typescript
30+
run: |
31+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
32+
33+
- uses: actions/cache@v4
34+
name: Setup pnpm cache
35+
with:
36+
path: ${{ env.STORE_PATH }}
37+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38+
restore-keys: |
39+
${{ runner.os }}-pnpm-store-
40+
41+
- name: Compile
42+
working-directory: sdks/typescript
43+
run: pnpm compile
44+
45+
- name: Run sdk tests
46+
working-directory: sdks/typescript/packages/sdk
47+
run: pnpm test
48+
49+
# - name: Extract SpacetimeDB branch name from file
50+
# id: extract-branch
51+
# run: |
52+
# # Define the path to the branch file
53+
# BRANCH_FILE=".github/spacetimedb-branch.txt"
54+
55+
# # Default to master if file doesn't exist
56+
# if [ ! -f "$BRANCH_FILE" ]; then
57+
# echo "::notice::No SpacetimeDB branch file found, using 'master'"
58+
# echo "branch=master" >> $GITHUB_OUTPUT
59+
# exit 0
60+
# fi
61+
62+
# # Read and trim whitespace from the file
63+
# branch=$(cat "$BRANCH_FILE" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
64+
65+
# # Fallback to master if empty
66+
# if [ -z "$branch" ]; then
67+
# echo "::warning::SpacetimeDB branch file is empty, using 'master'"
68+
# branch="master"
69+
# fi
70+
71+
# echo "branch=$branch" >> $GITHUB_OUTPUT
72+
# echo "Using SpacetimeDB branch from file: $branch"
73+
74+
- name: Install Rust toolchain
75+
uses: dtolnay/rust-toolchain@stable
76+
77+
- name: Cache Rust dependencies
78+
uses: Swatinem/rust-cache@v2
79+
with:
80+
workspaces: modules/quickstart-chat
81+
shared-key: quickstart-chat-test
82+
83+
- name: Install SpacetimeDB CLI from the local checkout
84+
run: |
85+
cargo install --force --path crates/cli --locked --message-format=short
86+
cargo install --force --path crates/standalone --locked --message-format=short
87+
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
88+
rm -f $HOME/.cargo/bin/spacetime
89+
ln -s $HOME/.cargo/bin/spacetimedb-cli $HOME/.cargo/bin/spacetime
90+
# Clear any existing information
91+
spacetime server clear -y
92+
env:
93+
# Share the target directory with our local project to avoid rebuilding same SpacetimeDB crates twice.
94+
CARGO_TARGET_DIR: modules/quickstart-chat/target
95+
96+
- name: Generate client bindings
97+
working-directory: modules/quickstart-chat
98+
run: |
99+
spacetime generate --lang typescript --out-dir ../../sdks/typescript/examples/quickstart-chat/src/module_bindings
100+
pnpm lint --write
101+
102+
- name: Check for changes
103+
working-directory: sdks/typescript
104+
run: |
105+
# This was copied from SpacetimeDB/tools/check-diff.sh.
106+
# It's required because `spacetime generate` creates lines with the SpacetimeDB commit
107+
# version, which would make this `git diff` check very brittle if included.
108+
PATTERN='^// This was generated using spacetimedb cli version.*'
109+
if ! git diff --exit-code --ignore-matching-lines="$PATTERN" -- examples/quickstart-chat/src/module_bindings; then
110+
echo "Error: Bindings are dirty. Please generate bindings again and commit them to this branch."
111+
exit 1
112+
fi
113+
114+
# - name: Start SpacetimeDB
115+
# run: |
116+
# spacetime start &
117+
# disown
118+
119+
# - name: Publish module to SpacetimeDB
120+
# working-directory: SpacetimeDB/modules/quickstart-chat
121+
# run: |
122+
# spacetime logout && spacetime login --server-issued-login local
123+
# spacetime publish -s local quickstart-chat -c -y
124+
125+
# - name: Publish module to SpacetimeDB
126+
# working-directory: SpacetimeDB/modules/quickstart-chat
127+
# run: |
128+
# spacetime logs quickstart-chat
129+
130+
- name: Check that quickstart-chat builds
131+
working-directory: sdks/typescript/examples/quickstart-chat
132+
run: pnpm build
133+
134+
# - name: Run quickstart-chat tests
135+
# working-directory: examples/quickstart-chat
136+
# run: pnpm test
137+
#
138+
# # Run this step always, even if the previous steps fail
139+
# - name: Print rows in the user table
140+
# if: always()
141+
# run: spacetime sql quickstart-chat "SELECT * FROM user"

0 commit comments

Comments
 (0)