Skip to content

Fix: On Windows GitHub Actions runners, tar in PATH resolves to Git f… #4

Fix: On Windows GitHub Actions runners, tar in PATH resolves to Git f…

Fix: On Windows GitHub Actions runners, tar in PATH resolves to Git f… #4

name: Compile PHP WASM
on:
push:
paths:
- 'packages/php-wasm/.recompile-request.json'
permissions:
id-token: write
contents: write
pull-requests: write
jobs:
read-matrix:
# Only allow Playground maintainers to trigger npm publishes.
if: >
(
github.actor == 'adamziel' ||
github.actor == 'dmsnell' ||
github.actor == 'bgrgicak' ||
github.actor == 'brandonpayton' ||
github.actor == 'zaerl' ||
github.actor == 'janjakes' ||
github.actor == 'mho22' ||
github.actor == 'ashfame'
)
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Build job matrix from .recompile-request.json
id: set-matrix
run: |
MATRIX=$(node -e "
const data = JSON.parse(require('fs').readFileSync('packages/php-wasm/.recompile-request.json', 'utf8'));
const items = data.compilations.map(c => ({
platform: c.platform,
phpVersion: c.phpVersion,
phpVersionSlug: c.phpVersion.replace('.', '-'),
packageSuffix: c.platform + '-' + c.phpVersion.replace('.', '-')
}));
console.log(JSON.stringify({ include: items }));
")
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
compile:
needs: read-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.read-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Free up runner disk space
run: |
set -euo pipefail
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/share/dotnet
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
- name: Compile JSPI variant
run: >
node packages/php-wasm/compile/build.js
--PLATFORM=${{ matrix.platform }}
--PHP_VERSION=${{ matrix.phpVersion }}
--JSPI=true
- name: Compile Asyncify variant
run: >
node packages/php-wasm/compile/build.js
--PLATFORM=${{ matrix.platform }}
--PHP_VERSION=${{ matrix.phpVersion }}
--JSPI=false
- name: Upload compiled artifact
uses: actions/upload-artifact@v4
with:
name: php-wasm-${{ matrix.packageSuffix }}
path: packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersionSlug }}/
retention-days: 3
publish:
needs: [read-matrix, compile]
runs-on: ubuntu-latest
environment:
name: npm
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.read-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Node.js with OIDC
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Upgrade npm for trusted publishing
run: npm install -g npm@latest
- name: Install dependencies
run: npm ci
- name: Download compiled artifact
uses: actions/download-artifact@v4
with:
name: php-wasm-${{ matrix.packageSuffix }}
path: packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersionSlug }}/
- name: Build package
run: >
npx nx build
php-wasm-${{ matrix.packageSuffix }}
- name: Determine PR version
id: version
run: |
CURRENT=$(node -e "console.log(require('./lerna.json').version)")
PR_NUMBER=${{ github.event.pull_request.number || '' }}
RUN_NUMBER=${{ github.run_number }}
if [ -n "$PR_NUMBER" ]; then
VERSION="${CURRENT}-pr.${PR_NUMBER}.${RUN_NUMBER}"
else
VERSION="${CURRENT}-sha.$(git rev-parse --short HEAD).${RUN_NUMBER}"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Inject PR version into dist package.json
run: |
node -e "
const pkgPath = 'dist/packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersionSlug }}/package.json';
const pkg = JSON.parse(require('fs').readFileSync(pkgPath, 'utf8'));
pkg.version = '${{ steps.version.outputs.version }}';
require('fs').writeFileSync(pkgPath, JSON.stringify(pkg, null, '\t') + '\n');
"
- name: Publish to npm
run: >
npm publish
--tag pr-${{ github.event.pull_request.number || github.run_number }}
--access public
working-directory: dist/packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersionSlug }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Output published version
run: echo "Published @php-wasm/${{ matrix.packageSuffix }}@${{ steps.version.outputs.version }}"
update-versions:
needs: [read-matrix, publish]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
token: ${{ secrets.GH_TOKEN }}
- name: Configure git
run: |
git config user.name "deployment_bot"
git config user.email "deployment_bot@users.noreply.github.com"
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Update wasm-versions.json
run: |
node -e "
const fs = require('fs');
const versionsPath = 'packages/php-wasm/wasm-versions.json';
const versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8'));
const matrix = ${{ needs.read-matrix.outputs.matrix }};
const currentVersion = require('./lerna.json').version;
const pr = '${{ github.event.pull_request.number || '' }}';
const run = '${{ github.run_number }}';
for (const item of matrix.include) {
const key = item.packageSuffix;
const version = pr
? \`\${currentVersion}-pr.\${pr}.\${run}\`
: \`\${currentVersion}-sha.\${require('child_process').execSync('git rev-parse --short HEAD').toString().trim()}.\${run}\`;
versions[key] = version;
}
fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t') + '\n');
"
- name: Commit updated wasm-versions.json
run: |
git add packages/php-wasm/wasm-versions.json
git diff --staged --quiet || git commit -m "chore: update wasm-versions.json for PHP WASM recompile [skip ci]"
git push
- name: Post PR comment
if: github.event.pull_request.number != ''
uses: actions/github-script@v7
with:
script: |
const matrix = ${{ needs.read-matrix.outputs.matrix }};
const currentVersion = require('./lerna.json').version;
const pr = context.payload.pull_request?.number;
const run = context.runNumber;
const lines = matrix.include.map(item => {
const version = `${currentVersion}-pr.${pr}.${run}`;
return `- \`@php-wasm/${item.packageSuffix}@${version}\``;
});
const body = [
'### PHP WASM packages published',
'',
'The following pre-release packages are now available on npm:',
'',
...lines,
'',
'These packages will be available until the PR is merged.',
'The `wasm-versions.json` has been updated on this branch.',
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
body,
});