-
Notifications
You must be signed in to change notification settings - Fork 447
238 lines (211 loc) · 9.4 KB
/
Copy pathcompile-php-wasm.yml
File metadata and controls
238 lines (211 loc) · 9.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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,
});