Skip to content

Commit 20e2a68

Browse files
committed
Move versions to package.json, and not a separate file
1 parent 90d1d42 commit 20e2a68

4 files changed

Lines changed: 40 additions & 68 deletions

File tree

.github/workflows/compile-php-wasm.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,30 +181,30 @@ jobs:
181181
with:
182182
node-version: '20'
183183

184-
- name: Update wasm-versions.json
184+
- name: Bump package.json versions to PR/SHA pre-release
185185
run: |
186186
node -e "
187187
const fs = require('fs');
188-
const versionsPath = 'packages/php-wasm/wasm-versions.json';
189-
const versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8'));
190188
const matrix = ${{ needs.read-matrix.outputs.matrix }};
191189
const currentVersion = require('./lerna.json').version;
192190
const pr = '${{ github.event.pull_request.number || '' }}';
193191
const run = '${{ github.run_number }}';
192+
const sha = require('child_process').execSync('git rev-parse --short HEAD').toString().trim();
193+
const version = pr
194+
? \`\${currentVersion}-pr.\${pr}.\${run}\`
195+
: \`\${currentVersion}-sha.\${sha}.\${run}\`;
194196
for (const item of matrix.include) {
195-
const key = item.packageSuffix;
196-
const version = pr
197-
? \`\${currentVersion}-pr.\${pr}.\${run}\`
198-
: \`\${currentVersion}-sha.\${require('child_process').execSync('git rev-parse --short HEAD').toString().trim()}.\${run}\`;
199-
versions[key] = version;
197+
const pkgPath = \`packages/php-wasm/\${item.platform}-builds/\${item.phpVersionSlug}/package.json\`;
198+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
199+
pkg.version = version;
200+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, '\t') + '\n');
200201
}
201-
fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t') + '\n');
202202
"
203203
204-
- name: Commit updated wasm-versions.json
204+
- name: Commit updated package.json files
205205
run: |
206-
git add packages/php-wasm/wasm-versions.json
207-
git diff --staged --quiet || git commit -m "chore: update wasm-versions.json for PHP WASM recompile [skip ci]"
206+
git add packages/php-wasm/web-builds packages/php-wasm/node-builds
207+
git diff --staged --quiet || git commit -m "chore: bump WASM package versions for PHP WASM recompile [skip ci]"
208208
git push
209209
210210
- name: Post PR comment
@@ -228,7 +228,7 @@ jobs:
228228
...lines,
229229
'',
230230
'These packages will be available until the PR is merged.',
231-
'The `wasm-versions.json` has been updated on this branch.',
231+
'The `package.json` files have been updated on this branch.',
232232
].join('\n');
233233
await github.rest.issues.createComment({
234234
owner: context.repo.owner,

.github/workflows/publish-npm-packages.yml

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,39 +84,15 @@ jobs:
8484

8585
- uses: ./.github/actions/prepare-playground
8686

87-
- name: Bump version (trunk)
88-
# Bump all package versions and create a local git commit + tag,
89-
# but do not push yet — we amend the commit in the next step to
90-
# include the wasm-versions.json reset so both land as one commit.
91-
if: github.ref == 'refs/heads/trunk'
92-
run: lerna version ${{ inputs.version_bump || 'patch' }} --yes --no-push
93-
94-
- name: Clear wasm-versions.json overrides and push (trunk)
95-
# wasm-versions.json may contain PR/SHA pre-release overrides from
96-
# the last WASM recompile. Reset it to {} so download-wasm.mjs
97-
# falls back to the lerna version for all packages.
98-
if: github.ref == 'refs/heads/trunk'
99-
run: |
100-
echo '{}' > packages/php-wasm/wasm-versions.json
101-
git add packages/php-wasm/wasm-versions.json
102-
git commit --amend --no-edit
103-
NEW_VERSION=$(node -e "console.log(require('./lerna.json').version)")
104-
git tag -f "v${NEW_VERSION}"
105-
git push origin trunk --follow-tags
106-
107-
- name: Publish NPM packages (trunk)
108-
if: github.ref == 'refs/heads/trunk'
109-
run: >
110-
lerna publish from-git
111-
--yes --no-private --loglevel=verbose
112-
--dist-tag=${{ inputs.dist_tag || 'latest' }}
113-
114-
- name: Publish NPM packages (non-trunk)
115-
# On non-trunk branches no commit or tag is created — the version
116-
# bump only affects the published package.json on npm.
117-
if: github.ref != 'refs/heads/trunk'
87+
- name: Publish NPM packages
88+
# Version bump, release, tag a new version on GitHub.
89+
# Lerna resets all package.json versions (including WASM packages)
90+
# to the new stable version, clearing any PR/SHA pre-release bumps.
91+
# On non-trunk branches, --no-push avoids pushing the version
92+
# bump commit back to the branch. The published packages still
93+
# get the version bump in their package.json on npm.
11894
run: >
11995
lerna publish ${{ inputs.version_bump || 'patch' }}
12096
--yes --no-private --loglevel=verbose
12197
--dist-tag=${{ inputs.dist_tag || 'latest' }}
122-
--no-push --no-git-tag-version
98+
${{ github.ref != 'refs/heads/trunk' && '--no-push --no-git-tag-version' || '' }}

packages/php-wasm/wasm-versions.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/scripts/download-wasm.mjs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
* Used by local developers (after git bisect, fresh clone) and by CI jobs
66
* before building wasm-dependent packages.
77
*
8-
* Package versions default to the current lerna.json version. The file
9-
* packages/php-wasm/wasm-versions.json is an optional sparse overrides map
10-
* used during active WASM recompiles to point specific packages at PR/SHA
11-
* pre-release builds. It is reset to {} on every stable release.
8+
* The version to download for each package is read directly from its
9+
* package.json. Stable releases use the lerna version; PR/SHA recompiles
10+
* temporarily bump the package.json to a pre-release version.
1211
*/
1312

1413
import { execSync } from 'child_process';
@@ -21,20 +20,8 @@ import { createGunzip } from 'zlib';
2120

2221
const __dirname = path.dirname(fileURLToPath(import.meta.url));
2322
const repoRoot = path.resolve(__dirname, '../../');
24-
const versionsFile = path.join(
25-
repoRoot,
26-
'packages/php-wasm/wasm-versions.json'
27-
);
28-
29-
// Default version comes from lerna.json (the current stable release).
30-
// wasm-versions.json only stores overrides for PR/SHA pre-release builds.
31-
const defaultVersion = JSON.parse(
32-
fs.readFileSync(path.join(repoRoot, 'lerna.json'), 'utf8')
33-
).version;
34-
const versions = JSON.parse(fs.readFileSync(versionsFile, 'utf8'));
3523

36-
// Build the full list of packages from the filesystem so wasm-versions.json
37-
// only needs to contain overrides, not every entry.
24+
// Discover all WASM packages from the filesystem.
3825
const allKeys = [];
3926
for (const platform of ['web', 'node']) {
4027
const buildsDir = path.join(
@@ -64,8 +51,14 @@ if (fs.existsSync(triggerFile)) {
6451
const stale = (trigger.compilations ?? []).filter(
6552
({ platform, phpVersion }) => {
6653
const [major, minor] = phpVersion.split('.');
67-
const key = `${platform}-${major}-${minor}`;
68-
const version = versions[key] ?? defaultVersion;
54+
const pkgPath = path.join(
55+
repoRoot,
56+
`packages/php-wasm/${platform}-builds/${major}-${minor}/package.json`
57+
);
58+
if (!fs.existsSync(pkgPath)) return false;
59+
const version = JSON.parse(
60+
fs.readFileSync(pkgPath, 'utf8')
61+
).version;
6962
return !version.includes('-pr.');
7063
}
7164
);
@@ -75,8 +68,8 @@ if (fs.existsSync(triggerFile)) {
7568
.map((c) => ` - ${c.platform} PHP ${c.phpVersion}`)
7669
.join('\n');
7770
console.warn(
78-
`\nWARNING: .recompile-request.json exists but wasm-versions.json still points\n` +
79-
`to stable versions for the following entries (CI may not have finished yet):\n` +
71+
`\nWARNING: .recompile-request.json exists but the following packages\n` +
72+
`still have a stable version (CI may not have finished yet):\n` +
8073
`${list}\n` +
8174
`You are downloading the previous stable binaries — not the recompiled ones.\n` +
8275
`Wait for the "Compile PHP WASM" CI job to complete and re-run prepare-wasm.\n`
@@ -88,7 +81,6 @@ let downloaded = 0;
8881
let skipped = 0;
8982

9083
for (const key of allKeys) {
91-
const version = versions[key] ?? defaultVersion;
9284
// key format: "{platform}-{major}-{minor}" e.g. "web-8-5"
9385
const parts = key.split('-');
9486
const platform = parts[0]; // "web" or "node"
@@ -99,6 +91,11 @@ for (const key of allKeys) {
9991
repoRoot,
10092
`packages/php-wasm/${platform}-builds/${versionDir}`
10193
);
94+
95+
const version = JSON.parse(
96+
fs.readFileSync(path.join(buildsDir, 'package.json'), 'utf8')
97+
).version;
98+
10299
const jspiDir = path.join(buildsDir, 'jspi');
103100
const asyncifyDir = path.join(buildsDir, 'asyncify');
104101

0 commit comments

Comments
 (0)