Skip to content

Commit

Permalink
Add initial city game build script
Browse files Browse the repository at this point in the history
  • Loading branch information
elihunter173 committed Jan 28, 2024
1 parent 6200945 commit 21b310e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
branches: ["main"]

name: Build and deploy on push

env:
RUST_CHANNEL: stable

jobs:
build:
name: Deploy website
Expand All @@ -13,9 +17,16 @@ jobs:
with:
node-version: '16'

- name: Install npm
- name: Install asteroids deps
uses: actions/setup-node@v2

- name: Install city-game deps
run: |
rustup update --no-self-update ${{ env.RUST_CHANNEL }}
rustup default ${{ env.RUST_CHANNEL }}
rustup target install wasm32-unknown-unknown
cargo install wasm-bindgen-cli
- name: Build website
run: ./scripts/build.sh
env:
Expand Down
7 changes: 7 additions & 0 deletions content/projects/the_merp_experiment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
+++
title = "The Merp Experiment"
description = "Game"
weight = 1
+++

[Play here](/the-merp-experiment/).
43 changes: 37 additions & 6 deletions scripts/build-subprojects.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
#!/usr/bin/env bash

set -e
set -ex

HERE="$(dirname "${BASH_SOURCE[0]}")"
cd "$HERE"
REPO_DIR="$(git rev-parse --show-toplevel)"

ASTEROIDS="$(mktemp -d -t asteroids-3d.XXX)"
echo "Building subproject [directory=$ASTEROIDS]"
git clone https://github.com/elihunter173/asteroids-3d.git "$ASTEROIDS"
cd "$ASTEROIDS"
subproject() {
proj="$1"
dir="$(mktemp -d -t "$proj".XXX)"
echo "Building subproject [directory=$dir]"
git clone "https://github.com/elihunter173/$proj.git" "$dir"
cd "$dir"
}

subproject asteroids-3d
npm install --production
npm run build
cp -r "$ASTEROIDS/dist" "$REPO_DIR/static/asteroids"
cp -r ./dist "$REPO_DIR/static/asteroids"

eval `ssh-agent -s`
ssh-add - <<< '${{ secrets.CITY_GAME_PRIVATE_DEPLOY_KEY }}'
subproject city-game
cargo build --release --target wasm32-unknown-unknown
wasm-bindgen --no-typescript --target web \
--out-dir ./out/ \
--out-name "game" \
./target/wasm32-unknown-unknown/web/game.wasm
cat << EOF > ./out/index.html
<!doctype html>
<html lang="en">
<body style="margin: 0px;">
<script type="module">
import init from './game.js'
init().catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
throw error;
}
});
</script>
</body>
</html>
EOF
cp -r ./assets ./out/.
cp -r ./out "$REPO_DIR/static/the-merp-experiment"

0 comments on commit 21b310e

Please sign in to comment.