name: Publish on: push: tags: - "v[0-9]+.[0-9]+.[0-9]+" - "v[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+.sha-[0-9a-f]+" - "v[0-9]+.[0-9]+.[0-9]+-preview.[0-9]+" - "v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" jobs: publish: name: Publish runs-on: ubuntu-latest if: github.repository == 'playcanvas/engine' permissions: contents: read id-token: write steps: - name: Check out code uses: actions/checkout@v7.0.1 - name: Set up Node.js 24.x uses: actions/setup-node@v7 with: node-version: 26.x cache: "npm" registry-url: "https://registry.npmjs.org/" - name: Parse tag name run: | TAG_NAME=${GITHUB_REF#refs/tags/} echo "TAG=${TAG_NAME}" >> $GITHUB_ENV echo "VERSION=${TAG_NAME/v/}" >> $GITHUB_ENV - name: Install dependencies run: npm clean-install --progress=false --no-fund - name: Run ESLint run: npm run lint - name: Run unit tests run: npm test - name: Build API reference manual run: npm run docs - name: Build PlayCanvas run: npm run build - name: Build Scripts API reference manual run: npm run docs:scripts - name: Run Post-build tests run: npm run test:build - name: Compile TypeScript declarations run: npm run test:types - name: Run Publint run: npm run publint - name: Publish to npm run: | if [[ "${{ env.TAG }}" =~ "alpha" ]]; then tag=alpha elif [[ "${{ env.TAG }}" =~ "preview" ]]; then tag=preview elif [[ "${{ env.TAG }}" =~ "beta" ]]; then tag=beta else tag=latest fi npm publish --tag $tag --provenance - name: Write version run: echo "${{ env.VERSION }}" > version.txt - name: Upload version uses: actions/upload-artifact@v7 with: name: version path: version.txt # npm publish is asynchronous: it returns as soon as the tarball is accepted ("Your package # is being processed and may take a few minutes to become available"), so the job above going # green no longer means the version is on the registry - it can lag by many minutes, and a # publish that is rejected during processing would leave this workflow green having shipped # nothing. This job holds the run open until the version actually resolves, so the workflow's # conclusion means "published" for everything keyed off it (the Upload workflow, and anyone # reading the run). It is a separate job so a timeout can be re-run on its own without # re-running the build and re-attempting a publish that would now conflict. await-npm: name: Await npm needs: publish runs-on: ubuntu-latest permissions: contents: read steps: - name: Parse tag name run: | TAG_NAME=${GITHUB_REF#refs/tags/} echo "VERSION=${TAG_NAME/v/}" >> $GITHUB_ENV - name: Wait for npm run: | url="https://registry.npmjs.org/playcanvas/${{ env.VERSION }}" for i in $(seq 1 120); do code=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 30 -H 'Cache-Control: no-cache' "$url" || true) if [ "$code" = "200" ]; then echo "playcanvas@${{ env.VERSION }} is available on npm" exit 0 fi echo "Not on npm yet (HTTP $code), retrying in 15s ($i/120)" sleep 15 done echo "Timed out waiting for playcanvas@${{ env.VERSION }} to appear on npm" exit 1