magic/.github/workflows/npm-publish.yml

150 lines
5.5 KiB
YAML

name: Publish npm package
# Publishes magic-vlsi-wasm to GitHub Packages (npm.pkg.github.com).
# Triggered automatically on version tags (v*); can also be run manually.
# Requires the default GITHUB_TOKEN — no extra secret needed.
#
# Publishing to GitHub Packages first allows testing and evaluation before a
# wider release to the public npm registry. Consumers can install from here via
# npm with an appropriate .npmrc pointing at npm.pkg.github.com.
#
# WASM is architecture-independent — built once on x86-64, usable everywhere.
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
emsdk_version:
description: 'emsdk version to build with (default: pinned release; use "latest" to track HEAD)'
type: string
default: 'latest'
dry_run:
description: 'Dry run: pack only, do not publish'
type: boolean
default: true
# actions/upload-artifact@v5 still runs on Node.js 20. Force Node 24 to
# silence the deprecation warning until upload-artifact ships a Node-24
# release. Drop this once upgraded.
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
registry-url: 'https://npm.pkg.github.com'
- name: Install emsdk
env:
# Pinned to match .github/workflows/main.yml (see post-build.sh for why the
# versions must stay in sync). The default here is the published-release pin;
# pass emsdk_version: 'latest' via workflow_dispatch to track emsdk HEAD and
# catch breakage before it affects a real release.
EMSDK_VERSION: ${{ github.event.inputs.emsdk_version || 'latest' }}
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install "$EMSDK_VERSION"
./emsdk activate "$EMSDK_VERSION"
- name: Build WASM
run: |
source ./emsdk/emsdk_env.sh
# --without/--disable flags: no WASM library available for these features
CFLAGS="--std=c17 -D_DEFAULT_SOURCE=1 -DEMSCRIPTEN=1" emconfigure ./configure \
--without-cairo --without-opengl --without-x --without-tk --without-tcl \
--disable-readline --disable-compression \
--host=asmjs-unknown-emscripten \
--target=asmjs-unknown-emscripten
# Append WASM linker flags and activate the WASM link target
cat toolchains/emscripten/defs.mak >> defs.mak
# Build in order: techs must exist before mains (--embed-file embeds them)
emmake make depend
emmake make -j$(nproc) modules libs
emmake make techs
emmake make mains
- name: Copy WASM artifacts into npm/
run: |
cp magic/magic.js npm/
cp magic/magic.wasm npm/
- name: Set package version
run: |
base=$(cat VERSION) # e.g. 8.3.637
date=$(git show -s --format=%cs | tr -d '-') # e.g. 20260414
hash=$(git show -s --format=%h) # e.g. d157eea
# npm requires semver; use pre-release syntax as the closest equivalent
# to the AppImage form 8.3.637~20260414~d157eea
VERSION="${base}-${date}.${hash}"
cd npm
npm version "$VERSION" --no-git-tag-version
- name: Pack
run: ./npm/pack.sh
- name: Upload tarball as artifact
uses: actions/upload-artifact@v5
with:
name: magic-wasm-npm-package
path: npm/*.tgz
- name: Publish to GitHub Packages
if: startsWith(github.ref, 'refs/tags/v') && github.event.inputs.dry_run != 'true'
run: cd npm && npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-wasm-arm:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v5
- name: Install emsdk
env:
EMSDK_VERSION: ${{ github.event.inputs.emsdk_version || 'latest' }}
run: |
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install "$EMSDK_VERSION"
./emsdk activate "$EMSDK_VERSION"
- name: Emscripten diagnostics
# Captures compiler predefined macros for all four toolchains.
# Kept intentionally: emsdk changes over time and these logs are the
# fastest way to diagnose a broken build without reproducing it locally.
run: |
source ./emsdk/emsdk_env.sh
echo "===== gcc -dM -E - ====="; echo | gcc -dM -E - | sort
echo "===== g++ -dM -E - ====="; echo | g++ -dM -E - | sort
echo "===== emcc -dM -E - ====="; echo | emcc -dM -E - | sort
echo "===== em++ -dM -E - ====="; echo | em++ -dM -E - | sort
- name: Build WASM
run: |
source ./emsdk/emsdk_env.sh
# --without/--disable flags: no WASM library available for these features
CFLAGS="--std=c17 -D_DEFAULT_SOURCE=1 -DEMSCRIPTEN=1" emconfigure ./configure \
--without-cairo --without-opengl --without-x --without-tk --without-tcl \
--disable-readline --disable-compression \
--target=asmjs-unknown-emscripten
echo "===== defs.mak ====="; cat defs.mak; echo "===== defs.mak ====="
emmake make
- name: Upload WASM artifact (arm)
uses: actions/upload-artifact@v5
with:
name: magic-wasm-bundle-arm
path: magic/magic.wasm