Skip to content

Build box2d3-wasm

Build box2d3-wasm #34

Workflow file for this run

# 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
actions: write # for triggering other workflows
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"
- name: install global deps
run: npm i -g typescript yarn
- name: install local deps
run: npm ci
working-directory: box2d3-wasm
- 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"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
- name: version and tag
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
id: versioning
working-directory: box2d3-wasm
# we use --no-git-tag-version because npm version can't use git from a subdirectory of a repository(?) https://github.com/npm/cli/issues/2010
run: |
NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version -m "release %s [skip ci]")
# Remove the 'v' prefix
NEW_VERSION=${NEW_VERSION#v}
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: commit updated version
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: |
git add package.json package-lock.json
git commit -m "box2d3-wasm v${{ steps.versioning.outputs.version }} [skip ci]"
- name: tag updated version
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: git tag "v${{ steps.versioning.outputs.version }}"
- 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 box2d3-wasm changes
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
working-directory: box2d3-wasm
run: |
echo "Pushing commits and tags..."
git push || { echo "Push failed"; exit 1; }
git push --tags || { echo "Push tags failed"; exit 1; }
echo "Done!"
- name: trigger update-gh-pages workflow
if: github.event.inputs.action == 'publish' && github.event.inputs.mode == 'release'
uses: peter-evans/repository-dispatch@v3
with:
event-type: box2d3-wasm-released
token: ${{ secrets.GITHUB_TOKEN }}
client-payload: '{"version": "${{ steps.versioning.outputs.version }}"}'