Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/actions/publish-npm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ runs:
shell: bash
run: node scripts/verify-android-so.js

# The release tag is the version: no version-bump commit precedes a
# release, so write it into package.json and oh-package.json5 before the
# HAR build and npm publish read them.
- name: Stamp the release version
shell: bash
run: node scripts/stamp-release-version.js

- name: Build Harmony HAR
if: inputs.harmony-har == 'build'
shell: bash
Expand Down Expand Up @@ -98,10 +105,6 @@ runs:
shell: bash
run: test -f harmony/pushy.har

- name: Verify release tag matches package version
shell: bash
run: node scripts/check-release-version.js

- name: Verify publish file list
shell: bash
run: node scripts/check-packlist.js --release
Expand Down
6 changes: 3 additions & 3 deletions harmony/pushy/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ so a debug rebuild does not look like a new binary. Add the generated file to

## Versioning

`oh-package.json5` `version` mirrors the npm package version;
`scripts/build-harmony-har.js` rewrites it before `assembleHar` and
`scripts/check-release-version.js` asserts the committed value matches.
`oh-package.json5` `version` mirrors the npm package version: the publish
workflow writes the release tag's version into both (`scripts/stamp-release-version.js`),
and `scripts/build-harmony-har.js` syncs it from `package.json` before `assembleHar`.

This file is packaged with the npm module (`harmony/pushy/src/`) so it is
available next to the sources in `node_modules/react-native-update`.
4 changes: 2 additions & 2 deletions scripts/build-harmony-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function buildHar() {
// The HAR carries its own version in oh-package.json5. Consumers'
// oh-package-lock.json5 and diagnostics can only tell installs apart when it
// equals the npm version, so rewrite it from package.json before assembleHar
// (scripts/check-release-version.js keeps the committed value honest).
// (scripts/stamp-release-version.js writes both from the release tag).
function syncOhPackageVersion() {
const packageJsonPath = path.join(projectRoot, 'package.json');
const ohPackagePath = path.join(harmonyModuleDir, 'oh-package.json5');
Expand All @@ -166,7 +166,7 @@ function syncOhPackageVersion() {
fail('package.json has no version to write into oh-package.json5');
}
const content = fs.readFileSync(ohPackagePath, 'utf8');
// JSON5 allows the key bare or quoted (check-release-version.js matches
// JSON5 allows the key bare or quoted (stamp-release-version.js matches
// the same shapes).
const versionLine =
/^(\s*(?:"version"|'version'|version)\s*:\s*)(['"])([^'"]*)\2(\s*,?)/m;
Expand Down
40 changes: 0 additions & 40 deletions scripts/check-release-version.js

This file was deleted.

50 changes: 50 additions & 0 deletions scripts/stamp-release-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node
// Releases are cut from the GitHub Release tag alone (vX.Y.Z on a green
// master commit, no version-bump commit), so the version is written into the
// package here, before the HAR build and npm publish:
// - package.json: the version npm publishes and the podspec reads.
// - harmony/pushy/oh-package.json5: the HAR's own version. Consumers'
// oh-package-lock.json5 and diagnostics can only tell installs apart when it
// equals the npm version (scripts/build-harmony-har.js syncs it from
// package.json again before assembleHar).
const fs = require('fs');
const path = require('path');

const tag = process.env.RELEASE_VERSION || '';
const version = tag.replace(/^v/, '');
// semver: X.Y.Z with an optional prerelease (10.62.0-beta.1).
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(version)) {
console.error(
`stamp-release-version: release tag '${tag}' is not vX.Y.Z or vX.Y.Z-prerelease`
);
process.exit(1);
}

const root = path.join(__dirname, '..');
const packageJsonPath = path.join(root, 'package.json');
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
pkg.version = version;
fs.writeFileSync(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);

const ohPackagePath = path.join(root, 'harmony/pushy/oh-package.json5');
const ohPackage = fs.readFileSync(ohPackagePath, 'utf8');
// JSON5 allows the key bare or quoted (syncOhPackageVersion in
// scripts/build-harmony-har.js matches the same shapes).
const versionLine =
/^(\s*(?:"version"|'version'|version)\s*:\s*)(['"])([^'"]*)\2(\s*,?)/m;
if (!versionLine.test(ohPackage)) {
console.error(
'stamp-release-version: no version field in harmony/pushy/oh-package.json5'
);
process.exit(1);
}
fs.writeFileSync(
ohPackagePath,
ohPackage.replace(
versionLine,
(_, prefix, quote, __, suffix) => `${prefix}${quote}${version}${quote}${suffix}`
)
);
console.log(
`stamp-release-version: package.json and oh-package.json5 set to ${version} from ${tag}`
);
Loading