Build box2d3-wasm #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | |
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | |
name: Build box2d3-wasm | |
on: | |
workflow_dispatch: | |
inputs: | |
mode: | |
description: 'Build mode' | |
required: true | |
type: choice | |
options: | |
- debug | |
- relwithdebinfo | |
- release | |
action: | |
description: 'Package action' | |
required: true | |
type: choice | |
options: | |
- pack | |
- publish | |
default: pack | |
version_type: | |
description: '[if publish] Version bump' | |
required: true | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
env: | |
EM_VERSION: 3.1.73 | |
EM_CACHE_FOLDER: 'emsdk-cache' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
# Only use release environment if we're publishing | |
environment: ${{ (github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release') && 'release' || '' }} | |
permissions: | |
contents: write # this permission is only exercised in mode == 'release' | |
id-token: write # for npm publish --provenance # https://docs.npmjs.com/generating-provenance-statements | |
steps: | |
- name: validate inputs | |
run: | | |
if [ "${{ github.event.inputs.action }}" = "publish" ] && [ "${{ github.event.inputs.mode }}" != "release" ]; then | |
echo "::error::Publish action is only allowed in release mode" | |
exit 1 | |
fi | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: setup cache | |
id: cache-system-libraries | |
uses: actions/cache@v4 | |
with: | |
path: ${{env.EM_CACHE_FOLDER}} | |
key: ${{env.EM_VERSION}}-${{ runner.os }} | |
- uses: mymindstorm/setup-emsdk@v14 | |
with: | |
version: ${{env.EM_VERSION}} | |
actions-cache-folder: ${{env.EM_CACHE_FOLDER}} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: "https://registry.npmjs.org" | |
scope: '' | |
- name: install global deps | |
run: npm i -g typescript yarn | |
- name: install local deps | |
run: npm ci | |
- name: set build type | |
id: build-type | |
run: | | |
if [ "${{ github.event.inputs.mode }}" = "debug" ]; then | |
echo "target_type=Debug" >> $GITHUB_OUTPUT | |
elif [ "${{ github.event.inputs.mode }}" = "relwithdebinfo" ]; then | |
echo "target_type=RelWithDebInfo" >> $GITHUB_OUTPUT | |
else | |
echo "target_type=Release" >> $GITHUB_OUTPUT | |
fi | |
- name: build makefile | |
working-directory: box2d3-wasm | |
run: shell/0_build_makefile.sh | |
env: | |
FLAVOUR: simd | |
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }} | |
- name: emmake | |
working-directory: box2d3-wasm | |
run: emmake make -j8 -C cmake-build | |
- name: build wasm | |
working-directory: box2d3-wasm | |
run: shell/1_build_wasm.sh | |
env: | |
FLAVOUR: simd | |
TARGET_TYPE: ${{ steps.build-type.outputs.target_type }} | |
# Pack mode: Create prerelease version without git tags | |
- name: version for pack | |
id: pack_version | |
if: github.event.inputs.action == 'pack' | |
working-directory: box2d3-wasm | |
run: | | |
# Get current version and add prerelease suffix | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
PRERELEASE_VERSION="${CURRENT_VERSION}-pre.$(date +%Y%m%d%H%M%S)" | |
# Use the full version string with npm version | |
npm version "${PRERELEASE_VERSION}" --no-git-tag-version | |
echo "version=${PRERELEASE_VERSION}" >> $GITHUB_OUTPUT | |
echo "Created prerelease version ${PRERELEASE_VERSION}" | |
- name: pack and upload | |
if: github.event.inputs.action == 'pack' | |
working-directory: box2d3-wasm | |
run: | | |
npm pack | |
echo "Package created:" | |
ls *.tgz | |
- name: upload package artifact | |
if: github.event.inputs.action == 'pack' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: box2d3-wasm-${{ steps.pack_version.outputs.version }}-${{ github.event.inputs.mode }} | |
path: box2d3-wasm/*.tgz | |
- name: configure git | |
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release' | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: version and tag | |
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release' | |
working-directory: box2d3-wasm | |
run: | | |
npm version ${{ github.event.inputs.version_type }} -m "release %s [skip ci]" | |
- name: publish to npm | |
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release' | |
working-directory: box2d3-wasm | |
run: npm publish --provenance | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} | |
- name: push changes | |
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release' | |
working-directory: box2d3-wasm | |
run: | | |
echo "Pushing commits and tags..." | |
git push | |
git push --tags | |
echo "Done!" | |
- name: trigger deploy workflow | |
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release' | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
event-type: deploy-triggered | |
token: ${{ secrets.GITHUB_TOKEN }} |