From cba51469f9ce85756aaccd7fb401051df62c89ef Mon Sep 17 00:00:00 2001 From: dmjio Date: Thu, 22 Oct 2026 12:55:45 -0700 Subject: [PATCH] CI: build every template for the browser with emcc The smoke test builds native programs only: it switches each project to target: native and replaces its Main.hs. Nothing compiled a template, or built anything for the browser, so a release could ship templates that do not build, or a browser build (or miso dev's) that does not work. scripts/template-test.sh does what a new user does: miso new with each template, miso build for target: browser (WebAssembly) and browser_js (JavaScript), and miso build --dev (miso dev's build: combinators, and the runtime that runs them, built with emcc). The templates job runs it on Linux and Apple Silicon, with the emscripten of the nixpkgs miso is built with (from flake.lock), and the release waits for it. --- .github/workflows/release.yml | 29 ++++++++++++++++++++- scripts/template-test.sh | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 scripts/template-test.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1acb609..71742d3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,6 +41,33 @@ jobs: name: miso-${{ matrix.system }} path: result/* + # Every template built for the browser with emcc, as a new user would: + # the smoke test builds native programs only (scripts/template-test.sh). + # emcc comes from the nixpkgs miso is built with (flake.lock), so this + # builds with the emscripten miso is tested against. + templates: + needs: build + strategy: + fail-fast: false + matrix: + include: + - { system: x86_64-linux, runner: ubuntu-latest } + - { system: aarch64-darwin, runner: macos-latest } + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v5 + - uses: cachix/install-nix-action@v31 + - uses: actions/download-artifact@v5 + with: + name: miso-${{ matrix.system }} + path: dist + - name: Build the templates for the browser + run: | + rev=$(jq -r '.nodes[.nodes.miso.inputs.nixpkgs].locked.rev' flake.lock) + echo "emscripten from nixpkgs $rev" + nix shell "github:NixOS/nixpkgs/$rev#emscripten" \ + --command scripts/template-test.sh dist/miso-${{ matrix.system }}.tar.gz + build-intel-mac: # GitHub retired the macos-13 image (jobs wait for it forever); # macos-15-intel is the free Intel runner. @@ -88,7 +115,7 @@ jobs: release: if: startsWith(github.ref, 'refs/tags/v') - needs: [build, build-intel-mac, build-windows] + needs: [build, templates, build-intel-mac, build-windows] runs-on: ubuntu-latest permissions: contents: write diff --git a/scripts/template-test.sh b/scripts/template-test.sh new file mode 100755 index 0000000..160eb23 --- /dev/null +++ b/scripts/template-test.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Build every template for the browser with emcc, as a new user would: +# miso new, then miso build for target: browser (WebAssembly) and +# browser_js (JavaScript), and the counter as miso dev builds it (miso build +# --dev: combinators, run by a runtime built with emcc). The smoke test +# builds native programs only, so without this a release could ship +# templates that do not build for the browser. +# +# scripts/template-test.sh miso-SYSTEM.tar.gz (emcc on the PATH) +set -eu +tarball=$1 +tmp=$(mktemp -d) +tar -C "$tmp" -xzf "$tarball" +export MISO_HOME=$tmp/home PATH="$(ls -d "$tmp"/miso-*)/bin:$PATH" +miso version +emcc --version | head -1 +cd "$tmp" + +fail() { echo "template test: $1" >&2; [ -f "${2:-}" ] && cat "$2" >&2; exit 1; } + +for template in $(miso templates | awk '$1 != "==>" { print $1 }'); do + for target in browser browser_js; do + name=$template-$(echo "$target" | tr _ -) + miso new "$name" --template "$template" > /dev/null + ( + cd "$name" + sed "s/^target: browser\$/target: $target/" miso.yml > miso.yml.new + mv miso.yml.new miso.yml + grep -q "^target: $target\$" miso.yml || fail "$name: miso.yml has no target: $target" miso.yml + miso build > build.log 2>&1 || fail "$name: miso build failed" build.log + [ -s public/index.js ] || fail "$name: miso build made no public/index.js" build.log + [ -s public/index.html ] || fail "$name: miso build made no public/index.html" build.log + echo "template test: $name ok ($(du -sh public | cut -f1))" + ) + done +done + +# miso dev's build: the program as combinators, and the runtime that runs them +miso new counter-dev > /dev/null +( + cd counter-dev + miso build --dev counter-dev > build.log 2>&1 || fail "counter-dev: miso build --dev failed" build.log + [ -s public/app.comb ] || fail "counter-dev: miso build --dev made no public/app.comb" build.log + [ -s public/index.js ] || fail "counter-dev: miso build --dev made no public/index.js" build.log + echo "template test: counter-dev ok (miso build --dev)" +) +echo "template test: ok"