Skip to content

Commit 90d1d42

Browse files
committed
WASM version file reset to Lerna version
1 parent 884b745 commit 90d1d42

3 files changed

Lines changed: 66 additions & 43 deletions

File tree

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

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

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

87-
- name: Publish NPM packages
88-
# Version bump, release, tag a new version on GitHub.
89-
# On non-trunk branches, --no-push avoids pushing the version
90-
# bump commit back to the branch. The published packages still
91-
# get the version bump in their package.json on npm.
92-
run: >
93-
lerna publish ${{ inputs.version_bump || 'patch' }}
94-
--yes --no-private --loglevel=verbose
95-
--dist-tag=${{ inputs.dist_tag || 'latest' }}
96-
${{ github.ref != 'refs/heads/trunk' && '--no-push --no-git-tag-version' || '' }}
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
9793

98-
- name: Update wasm-versions.json to new stable version
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.
9998
if: github.ref == 'refs/heads/trunk'
10099
run: |
101-
node -e "
102-
const fs = require('fs');
103-
const versionsPath = 'packages/php-wasm/wasm-versions.json';
104-
const newVersion = require('./lerna.json').version;
105-
const versions = JSON.parse(fs.readFileSync(versionsPath, 'utf8'));
106-
for (const key of Object.keys(versions)) {
107-
versions[key] = newVersion;
108-
}
109-
fs.writeFileSync(versionsPath, JSON.stringify(versions, null, '\t') + '\n');
110-
"
100+
echo '{}' > packages/php-wasm/wasm-versions.json
111101
git add packages/php-wasm/wasm-versions.json
112-
git diff --staged --quiet || git commit -m "chore: update wasm-versions.json to $(node -e \"console.log(require('./lerna.json').version)\")"
113-
git push origin trunk
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'
118+
run: >
119+
lerna publish ${{ inputs.version_bump || 'patch' }}
120+
--yes --no-private --loglevel=verbose
121+
--dist-tag=${{ inputs.dist_tag || 'latest' }}
122+
--no-push --no-git-tag-version
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1 @@
1-
{
2-
"web-7-4": "3.1.4",
3-
"web-8-0": "3.1.4",
4-
"web-8-1": "3.1.4",
5-
"web-8-2": "3.1.4",
6-
"web-8-3": "3.1.4",
7-
"web-8-4": "3.1.4",
8-
"web-8-5": "3.1.4",
9-
"node-7-4": "3.1.4",
10-
"node-8-0": "3.1.4",
11-
"node-8-1": "3.1.4",
12-
"node-8-2": "3.1.4",
13-
"node-8-3": "3.1.4",
14-
"node-8-4": "3.1.4",
15-
"node-8-5": "3.1.4"
16-
}
1+
{}

tools/scripts/download-wasm.mjs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
* Used by local developers (after git bisect, fresh clone) and by CI jobs
66
* before building wasm-dependent packages.
77
*
8-
* Reads packages/php-wasm/wasm-versions.json and fetches each package if the
9-
* local jspi/ or asyncify/ directories are missing or empty.
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.
1012
*/
1113

1214
import { execSync } from 'child_process';
@@ -24,8 +26,33 @@ const versionsFile = path.join(
2426
'packages/php-wasm/wasm-versions.json'
2527
);
2628

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;
2734
const versions = JSON.parse(fs.readFileSync(versionsFile, 'utf8'));
2835

36+
// Build the full list of packages from the filesystem so wasm-versions.json
37+
// only needs to contain overrides, not every entry.
38+
const allKeys = [];
39+
for (const platform of ['web', 'node']) {
40+
const buildsDir = path.join(
41+
repoRoot,
42+
`packages/php-wasm/${platform}-builds`
43+
);
44+
45+
if (fs.existsSync(buildsDir)) {
46+
for (const entry of fs.readdirSync(buildsDir, {
47+
withFileTypes: true,
48+
})) {
49+
if (entry.isDirectory() && /^\d+-\d+$/.test(entry.name)) {
50+
allKeys.push(`${platform}-${entry.name}`);
51+
}
52+
}
53+
}
54+
}
55+
2956
// Warn if a recompile was requested but CI hasn't published PR builds yet.
3057
const triggerFile = path.join(
3158
repoRoot,
@@ -38,7 +65,8 @@ if (fs.existsSync(triggerFile)) {
3865
({ platform, phpVersion }) => {
3966
const [major, minor] = phpVersion.split('.');
4067
const key = `${platform}-${major}-${minor}`;
41-
return key in versions && !versions[key].includes('-pr.');
68+
const version = versions[key] ?? defaultVersion;
69+
return !version.includes('-pr.');
4270
}
4371
);
4472

@@ -59,7 +87,8 @@ if (fs.existsSync(triggerFile)) {
5987
let downloaded = 0;
6088
let skipped = 0;
6189

62-
for (const [key, version] of Object.entries(versions)) {
90+
for (const key of allKeys) {
91+
const version = versions[key] ?? defaultVersion;
6392
// key format: "{platform}-{major}-{minor}" e.g. "web-8-5"
6493
const parts = key.split('-');
6594
const platform = parts[0]; // "web" or "node"

0 commit comments

Comments
 (0)