Skip to content

box2d3-wasm-released #9

box2d3-wasm-released

box2d3-wasm-released #9

name: Update gh-pages dependency on box2d3-wasm
on:
workflow_dispatch:
inputs:
version:
description: 'box2d3-wasm ver. [default: package.json]'
required: false
repository_dispatch:
types: [box2d3-wasm-released]
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
concurrency:
group: "gh-pages-deps"
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
environment: release
permissions:
contents: write # for committing update to gh-pages dependencies
actions: write # for triggering other workflows
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
- name: Get version
id: get_version
working-directory: box2d3-wasm
run: |
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
VERSION="${{ github.event.client_payload.version }}"
elif [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="$(npm pkg get version | tr -d '"')"
fi
echo "got version: $VERSION"
if [ -z "$VERSION" ]; then
echo "Error: Version is empty"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: configure git
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: wait for the specified box2d3-wasm to become available
# another timeout in case uhh I dunno like npm view being unexpectedly slow or whatever. probably overkill
timeout-minutes: 6
env:
MAX_ATTEMPTS: 30
DELAY: 10
VERSION: ${{ steps.get_version.outputs.version }}
run: |
for ((i=1; i<=$MAX_ATTEMPTS; i++)); do
if npm view box2d3-wasm@$VERSION version >/dev/null 2>&1; then
echo "box2d3-wasm $VERSION is now available!"
exit 0
fi
echo "Attempt $i/$MAX_ATTEMPTS: Package version $VERSION not found, waiting ${DELAY}s..."
sleep $DELAY
done
echo "Timed out waiting for package to be available"
exit 1
- name: update gh-pages box2d3-wasm version
working-directory: gh-pages
run: npm install --save "box2d3-wasm@^${{ steps.get_version.outputs.version }}"
- name: commit updated gh-pages
working-directory: gh-pages
run: |
git add package.json package-lock.json
git commit -m "update gh-pages box2d3-wasm to v${{ steps.get_version.outputs.version }} [skip ci]"
- name: push gh-pages changes
working-directory: gh-pages
run: |
echo "Pushing commit..."
git push || { echo "Push failed"; exit 1; }
echo "Done!"
- name: trigger update-gh-pages workflow
uses: peter-evans/repository-dispatch@v3
with:
event-type: gh-pages-deps-updated
token: ${{ secrets.GITHUB_TOKEN }}