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