Skip to content

Build box2d3-wasm

Build box2d3-wasm #4

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: 'Version increment type'
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'
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
- name: install global deps
run: npm i -g typescript yarn
- 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
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 "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: npm-package
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
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 }}