Fix #472: Emscripten Frontend#662
Conversation
…d ChaiScript Port Rob Loach's ChaiScript.js work (https://github.com/RobLoach/ChaiScript.js) into the main repository as an Emscripten build target. Adds a GitHub Actions workflow that builds ChaiScript to WebAssembly and publishes artifacts (JS, WASM, HTML) for embedding in the official ChaiScript.com website. Includes an HTML interactive playground frontend and a native test validating the eval API surface. Co-Authored-By: Rob Loach <[email protected]> Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
@leftibot what is the next steps for actually utilizing this on the website? |
|
Good question. Right now the workflow builds the artifacts and uploads them via 1. Decide on hosting strategyA few options depending on where chaiscript.com is hosted:
2. Integrate with the site designThe current
3. Serve
|
|
@leftibot can it be deployed to https://github.com/ChaiScript/chaiscript.github.io directly with an action? The site is currently in a separate repo, not in the gh-pages branch |
|
Yes, absolutely. You can push to Using a deploy key (recommended)
Then add a deploy job to the workflow: deploy:
needs: emscripten
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: chaiscript-web
path: artifacts
- name: Clone target repo
env:
SSH_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
mkdir -p ~/.ssh
echo "$SSH_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no"
git clone [email protected]:ChaiScript/chaiscript.github.io.git target
- name: Copy artifacts and push
run: |
export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no"
# Copy into a subdirectory so it doesn't clobber the existing site
mkdir -p target/playground
cp artifacts/build-em/chaiscript.js target/playground/
cp artifacts/build-em/chaiscript.wasm target/playground/
cp artifacts/build-em/chaiscript.html target/playground/index.html
cd target
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add playground/
git diff --cached --quiet || git commit -m "Update ChaiScript playground from ChaiScript/ChaiScript@${GITHUB_SHA::8}"
git pushThis would make the playground available at Alternative: PATA GitHub PAT with Want me to update the workflow in this PR to include the deploy job? You'd just need to set up the deploy key / secret on both repos. |
|
@leftibot can it possibly go the other way there the website is triggered to rebuild whenever there's a new artifact on "main" or "develop" here so that we don't need to do the keys and permissions thing? |
|
Unfortunately, there's no fully "zero-auth" way to trigger a cross-repo workflow in GitHub Actions. The That said, there's a lightweight approach that avoids deploy keys entirely: Publish as a GitHub Release asset (no cross-repo auth needed)
# In chaiscript.github.io
on:
schedule:
- cron: '*/15 * * * *' # every 15 min
jobs:
update-playground:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch latest WASM build
run: |
mkdir -p playground
# Public API, no token needed for public repos
RELEASE=$(curl -s https://api.github.com/repos/ChaiScript/ChaiScript/releases/tags/wasm-latest)
for file in chaiscript.js chaiscript.wasm chaiscript.html; do
URL=$(echo "$RELEASE" | jq -r ".assets[] | select(.name==\"$file\") | .browser_download_url")
curl -sL "$URL" -o "playground/$file"
done
- name: Commit if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add playground/
git diff --cached --quiet || git commit -m "Update ChaiScript playground"
git pushThe tradeoff is up to 15 minutes of latency (or whatever cron interval you pick), but it requires zero secrets, zero keys, zero cross-repo permissions. The website repo just pulls from a public URL. If you want instant triggeringYou'd need at minimum a fine-grained PAT stored as a secret in this repo, scoped to just The cron-based approach is probably the better fit here given that playground updates aren't time-critical. |
|
@leftibot update this emscripten thing to publish assets under some tag, but only from |
Add a publish job to the emscripten workflow that creates a prerelease tagged wasm-latest with chaiscript.js, chaiscript.wasm, and chaiscript.html as downloadable assets. Runs only on pushes to the develop branch. The website repo can fetch these via the public GitHub Releases API on a daily cron without any cross-repo auth. Requested by @lefticus in PR ChaiScript#662 review. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Addressed review feedback from @lefticus. New commits: |
Automated fix by @leftibot.
What changed
Files
Closes #472
Triggered by @lefticus.