diff --git a/.github/workflows/web-demo.yml b/.github/workflows/web-demo.yml index fde342b..b544028 100644 --- a/.github/workflows/web-demo.yml +++ b/.github/workflows/web-demo.yml @@ -3,14 +3,14 @@ on: push: branches: [main] -name: Web demo +name: Web apps permissions: contents: read pull-requests: write concurrency: - group: web-demo-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }} + group: web-apps-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: @@ -43,13 +43,35 @@ jobs: ~/.npm ~/.cargo/registry ~/.cargo/git + ~/.ghc-wasm/.cabal target - key: web-demo-${{ runner.os }}-${{ hashFiles('flake.lock', 'Cargo.lock', 'packages/coln-js-runtime/package-lock.json', 'examples/web-demo/pnpm-lock.yaml') }} + dist-newstyle + key: web-apps-${{ runner.os }}-${{ hashFiles('flake.lock', 'Cargo.lock', 'cabal.project', 'packages/**/*.cabal', 'packages/coln-js-runtime/package-lock.json', 'examples/web-demo/pnpm-lock.yaml') }} restore-keys: | - web-demo-${{ runner.os }}- + web-apps-${{ runner.os }}- - name: Build web demo run: nix run --accept-flake-config .#web-demo -- "$GITHUB_WORKSPACE" + env: + VITE_BASE: /demo/ + + - name: Build web compiler + run: nix develop --accept-flake-config --command just packages/coln-compiler-wasm/build-example + + - name: Assemble deploy directory + run: | + mkdir -p _deploy/demo _deploy/compiler + cp -r examples/web-demo/dist/* _deploy/demo/ + cp -r _build/wasm/* _deploy/compiler/ + cat > _deploy/index.html <<'EOF' + + + Coln + + EOF - name: Deploy PR preview to Netlify id: deploy-preview @@ -58,10 +80,10 @@ jobs: npx --yes netlify-cli@latest deploy \ --auth "$NETLIFY_AUTH_TOKEN" \ --site "$NETLIFY_SITE_ID" \ - --dir examples/web-demo/dist \ + --dir _deploy \ --no-build \ --alias "pr-${{ github.event.pull_request.number }}" \ - --message "PR #${{ github.event.pull_request.number }} web demo" \ + --message "PR #${{ github.event.pull_request.number }} web apps" \ --json > netlify-deploy.json cat netlify-deploy.json @@ -73,8 +95,14 @@ jobs: uses: actions/github-script@v8 with: script: | - const marker = '' - const body = `${marker}\nWeb demo preview: ${{ steps.deploy-preview.outputs.deploy-url }}` + const marker = '' + const url = '${{ steps.deploy-preview.outputs.deploy-url }}' + const body = [ + marker, + 'Deploy preview:', + `- [Demo](${url}/demo/)`, + `- [Compiler](${url}/compiler/)`, + ].join('\n') const { owner, repo } = context.repo const issue_number = context.issue.number const comments = await github.rest.issues.listComments({ owner, repo, issue_number, per_page: 100 }) @@ -91,7 +119,7 @@ jobs: npx --yes netlify-cli@latest deploy \ --auth "$NETLIFY_AUTH_TOKEN" \ --site "$NETLIFY_SITE_ID" \ - --dir examples/web-demo/dist \ + --dir _deploy \ --no-build \ --prod \ - --message "main web demo ${{ github.sha }}" + --message "main web apps ${{ github.sha }}" diff --git a/examples/web-demo/vite.config.ts b/examples/web-demo/vite.config.ts index 751b0ef..d704ced 100644 --- a/examples/web-demo/vite.config.ts +++ b/examples/web-demo/vite.config.ts @@ -7,6 +7,7 @@ import react from "@vitejs/plugin-react" import wasm from "vite-plugin-wasm" export default defineConfig({ + base: process.env.VITE_BASE || "/", plugins: [wasm(), react()], build: { target: "esnext" }, }) diff --git a/packages/coln-compiler-wasm/justfile b/packages/coln-compiler-wasm/justfile index d67454d..06c8e57 100644 --- a/packages/coln-compiler-wasm/justfile +++ b/packages/coln-compiler-wasm/justfile @@ -10,7 +10,7 @@ build: libdir="$(wasm32-wasi-ghc --print-libdir)" "$libdir/post-link.mjs" --input {{ dist_dir }}/coln.wasm --output {{ dist_dir }}/ghc_wasm_jsffi.js -serve-example port="8000": build +build-example: build #!/usr/bin/env bash set -euxo pipefail cp example.html {{ build_dir }}/index.html @@ -18,4 +18,6 @@ serve-example port="8000": build mkdir -p "$examples_dir" cp ../../packages/coln-compiler/test/*.coln "$examples_dir/" ls -1 "$examples_dir"/*.coln | xargs -n1 basename | jq -nR '[inputs]' > "$examples_dir/index.json" + +serve-example port="8000": build-example simple-http-server --nocache --index --open --port {{ port }} {{ build_dir }}