diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000..9db574c --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + pull_request: + +jobs: + check: + runs-on: ubuntu-22.04 + permissions: + contents: "read" + id-token: "write" + pages: "write" + + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/flake-checker-action@main + + - name: Run `nix build wasm` + run: nix build .#tadventure-wasm + + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: result/dist + + - name: Deploy to gh-pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/assets/index.html b/assets/index.html new file mode 100644 index 0000000..71bbdbb --- /dev/null +++ b/assets/index.html @@ -0,0 +1,29 @@ + + + + + + Tadventure + + + + + + + + + + diff --git a/flake.nix b/flake.nix index f72e5b4..69d370c 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,7 @@ # Extra targets if required }; craneLib = (crane.mkLib pkgs).overrideToolchain stableToolchain; - src = craneLib.cleanCargoSource (craneLib.path ./.); + src = craneLib.path ./.; commonArgs = { inherit src; buildInputs = with pkgs; @@ -61,7 +61,7 @@ ]; }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; - in { + in rec { checks = { tadventure-clippy = craneLib.cargoClippy (commonArgs // { @@ -111,10 +111,35 @@ inherit src; doCheck = false; cargoExtraArgs = "--target wasm32-unknown-unknown"; + installPhase = '' + mkdir -p $out/dist + cp target/wasm32-unknown-unknown/release/tadventure.wasm $out/dist/tadventure.wasm + cp $src/assets/index.html $out/dist/index.html + ''; + meta.mainProgram = null; }; default = tadventure; }; + apps = { + default = let + wasm = pkgs.writeShellApplication { + # Our shell script name is serve + # so it is available at $out/bin/serve + name = "tadventure"; + # Caddy is a web server with a convenient CLI interface + runtimeInputs = [pkgs.caddy]; + text = '' + # Serve the current directory on port 8090 + caddy file-server --listen :8000 --root ${packages.tadventure-wasm}/dist + ''; + }; + in { + type = "app"; + program = "${wasm}/bin/tadventure"; + }; + }; + devShells.default = (craneLib.overrideToolchain stableToolchainWithRustAnalyzer).devShell (commonArgs // { buildInputs = [];