|
| 1 | +name: Compile PHP WASM |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'packages/php-wasm/.recompile-request.json' |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + read-matrix: |
| 15 | + # Only allow Playground maintainers to trigger npm publishes. |
| 16 | + if: > |
| 17 | + ( |
| 18 | + github.actor == 'adamziel' || |
| 19 | + github.actor == 'dmsnell' || |
| 20 | + github.actor == 'bgrgicak' || |
| 21 | + github.actor == 'brandonpayton' || |
| 22 | + github.actor == 'zaerl' || |
| 23 | + github.actor == 'janjakes' || |
| 24 | + github.actor == 'mho22' || |
| 25 | + github.actor == 'ashfame' |
| 26 | + ) |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Build job matrix from .recompile-request.json |
| 34 | + id: set-matrix |
| 35 | + run: | |
| 36 | + MATRIX=$(node -e " |
| 37 | + const data = JSON.parse(require('fs').readFileSync('packages/php-wasm/.recompile-request.json', 'utf8')); |
| 38 | + const items = data.compilations.map(c => ({ |
| 39 | + platform: c.platform, |
| 40 | + phpVersion: c.phpVersion, |
| 41 | + packageSuffix: c.platform + '-' + c.phpVersion.replace('.', '-') |
| 42 | + })); |
| 43 | + console.log(JSON.stringify({ include: items })); |
| 44 | + ") |
| 45 | + echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT" |
| 46 | +
|
| 47 | + compile: |
| 48 | + needs: read-matrix |
| 49 | + runs-on: ubuntu-latest |
| 50 | + strategy: |
| 51 | + fail-fast: false |
| 52 | + matrix: ${{ fromJSON(needs.read-matrix.outputs.matrix) }} |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + submodules: true |
| 57 | + |
| 58 | + - uses: actions/setup-node@v4 |
| 59 | + with: |
| 60 | + node-version: '20' |
| 61 | + |
| 62 | + - name: Install dependencies |
| 63 | + run: npm ci |
| 64 | + |
| 65 | + - name: Free up runner disk space |
| 66 | + run: | |
| 67 | + set -euo pipefail |
| 68 | + sudo rm -rf /usr/local/lib/android |
| 69 | + sudo rm -rf /usr/share/dotnet |
| 70 | + sudo rm -rf "$AGENT_TOOLSDIRECTORY" |
| 71 | + sudo rm -rf /opt/ghc |
| 72 | + sudo rm -rf /opt/hostedtoolcache/CodeQL |
| 73 | +
|
| 74 | + - name: Compile JSPI variant |
| 75 | + run: > |
| 76 | + node packages/php-wasm/compile/build.js |
| 77 | + --PLATFORM=${{ matrix.platform }} |
| 78 | + --PHP_VERSION=${{ matrix.phpVersion }} |
| 79 | + --JSPI=true |
| 80 | +
|
| 81 | + - name: Compile Asyncify variant |
| 82 | + run: > |
| 83 | + node packages/php-wasm/compile/build.js |
| 84 | + --PLATFORM=${{ matrix.platform }} |
| 85 | + --PHP_VERSION=${{ matrix.phpVersion }} |
| 86 | + --JSPI=false |
| 87 | +
|
| 88 | + - name: Upload compiled artifact |
| 89 | + uses: actions/upload-artifact@v4 |
| 90 | + with: |
| 91 | + name: php-wasm-${{ matrix.packageSuffix }} |
| 92 | + path: packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersion.replace('.', '-') }}/ |
| 93 | + retention-days: 3 |
| 94 | + |
| 95 | + publish: |
| 96 | + needs: [read-matrix, compile] |
| 97 | + runs-on: ubuntu-latest |
| 98 | + environment: |
| 99 | + name: npm |
| 100 | + strategy: |
| 101 | + fail-fast: false |
| 102 | + matrix: ${{ fromJSON(needs.read-matrix.outputs.matrix) }} |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + submodules: true |
| 107 | + |
| 108 | + - name: Set up Node.js with OIDC |
| 109 | + uses: actions/setup-node@v4 |
| 110 | + with: |
| 111 | + node-version: '20' |
| 112 | + registry-url: 'https://registry.npmjs.org' |
| 113 | + |
| 114 | + - name: Upgrade npm for trusted publishing |
| 115 | + run: npm install -g npm@latest |
| 116 | + |
| 117 | + - name: Install dependencies |
| 118 | + run: npm ci |
| 119 | + |
| 120 | + - name: Download compiled artifact |
| 121 | + uses: actions/download-artifact@v4 |
| 122 | + with: |
| 123 | + name: php-wasm-${{ matrix.packageSuffix }} |
| 124 | + path: packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersion.replace('.', '-') }}/ |
| 125 | + |
| 126 | + - name: Build package |
| 127 | + run: > |
| 128 | + npx nx build |
| 129 | + php-wasm-${{ matrix.packageSuffix }} |
| 130 | +
|
| 131 | + - name: Determine PR version |
| 132 | + id: version |
| 133 | + run: | |
| 134 | + CURRENT=$(node -e "console.log(require('./lerna.json').version)") |
| 135 | + PR_NUMBER=${{ github.event.pull_request.number || '' }} |
| 136 | + RUN_NUMBER=${{ github.run_number }} |
| 137 | + if [ -n "$PR_NUMBER" ]; then |
| 138 | + VERSION="${CURRENT}-pr.${PR_NUMBER}.${RUN_NUMBER}" |
| 139 | + else |
| 140 | + VERSION="${CURRENT}-sha.$(git rev-parse --short HEAD).${RUN_NUMBER}" |
| 141 | + fi |
| 142 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 143 | +
|
| 144 | + - name: Inject PR version into dist package.json |
| 145 | + run: | |
| 146 | + node -e " |
| 147 | + const pkgPath = 'dist/packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersion.replace('.', '-') }}/package.json'; |
| 148 | + const pkg = JSON.parse(require('fs').readFileSync(pkgPath, 'utf8')); |
| 149 | + pkg.version = '${{ steps.version.outputs.version }}'; |
| 150 | + require('fs').writeFileSync(pkgPath, JSON.stringify(pkg, null, '\t') + '\n'); |
| 151 | + " |
| 152 | +
|
| 153 | + - name: Publish to npm |
| 154 | + run: > |
| 155 | + npm publish |
| 156 | + --tag pr-${{ github.event.pull_request.number || github.run_number }} |
| 157 | + --access public |
| 158 | + working-directory: dist/packages/php-wasm/${{ matrix.platform }}-builds/${{ matrix.phpVersion.replace('.', '-') }} |
| 159 | + env: |
| 160 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 161 | + |
| 162 | + - name: Output published version |
| 163 | + run: echo "Published @php-wasm/${{ matrix.packageSuffix }}@${{ steps.version.outputs.version }}" |
| 164 | + |
| 165 | + update-versions: |
| 166 | + needs: [read-matrix, publish] |
| 167 | + runs-on: ubuntu-latest |
| 168 | + steps: |
| 169 | + - uses: actions/checkout@v4 |
| 170 | + with: |
| 171 | + ref: ${{ github.head_ref || github.ref_name }} |
| 172 | + token: ${{ secrets.GH_TOKEN }} |
| 173 | + |
| 174 | + - name: Configure git |
| 175 | + run: | |
| 176 | + git config user.name "deployment_bot" |
| 177 | + git config user.email "deployment_bot@users.noreply.github.com" |
| 178 | +
|
| 179 | + - uses: actions/setup-node@v4 |
| 180 | + with: |
| 181 | + node-version: '20' |
| 182 | + |
| 183 | + - name: Update wasm-versions.json |
| 184 | + run: | |
| 185 | + node -e " |
| 186 | + const fs = require('fs'); |
| 187 | + const versionsPath = 'packages/php-wasm/wasm-versions.json'; |
| 188 | + const versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8')); |
| 189 | + const matrix = ${{ needs.read-matrix.outputs.matrix }}; |
| 190 | + const currentVersion = require('./lerna.json').version; |
| 191 | + const pr = '${{ github.event.pull_request.number || '' }}'; |
| 192 | + const run = '${{ github.run_number }}'; |
| 193 | + for (const item of matrix.include) { |
| 194 | + const key = item.packageSuffix; |
| 195 | + const version = pr |
| 196 | + ? \`\${currentVersion}-pr.\${pr}.\${run}\` |
| 197 | + : \`\${currentVersion}-sha.\${require('child_process').execSync('git rev-parse --short HEAD').toString().trim()}.\${run}\`; |
| 198 | + versions[key] = version; |
| 199 | + } |
| 200 | + fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t') + '\n'); |
| 201 | + " |
| 202 | +
|
| 203 | + - name: Commit updated wasm-versions.json |
| 204 | + run: | |
| 205 | + git add packages/php-wasm/wasm-versions.json |
| 206 | + git diff --staged --quiet || git commit -m "chore: update wasm-versions.json for PHP WASM recompile [skip ci]" |
| 207 | + git push |
| 208 | +
|
| 209 | + - name: Post PR comment |
| 210 | + if: github.event.pull_request.number != '' |
| 211 | + uses: actions/github-script@v7 |
| 212 | + with: |
| 213 | + script: | |
| 214 | + const matrix = ${{ needs.read-matrix.outputs.matrix }}; |
| 215 | + const currentVersion = require('./lerna.json').version; |
| 216 | + const pr = context.payload.pull_request?.number; |
| 217 | + const run = context.runNumber; |
| 218 | + const lines = matrix.include.map(item => { |
| 219 | + const version = `${currentVersion}-pr.${pr}.${run}`; |
| 220 | + return `- \`@php-wasm/${item.packageSuffix}@${version}\``; |
| 221 | + }); |
| 222 | + const body = [ |
| 223 | + '### PHP WASM packages published', |
| 224 | + '', |
| 225 | + 'The following pre-release packages are now available on npm:', |
| 226 | + '', |
| 227 | + ...lines, |
| 228 | + '', |
| 229 | + 'These packages will be available until the PR is merged.', |
| 230 | + 'The `wasm-versions.json` has been updated on this branch.', |
| 231 | + ].join('\n'); |
| 232 | + await github.rest.issues.createComment({ |
| 233 | + owner: context.repo.owner, |
| 234 | + repo: context.repo.repo, |
| 235 | + issue_number: pr, |
| 236 | + body, |
| 237 | + }); |
0 commit comments