Skip to content

Commit f6ec1b8

Browse files
committed
fix(ci): replace sed version bump with npm version
The publish workflow bumped the package version with a greedy sed that matched every "version": "..." entry in package.json, corrupting scripts.version (which the prepare-release lifecycle invokes via run-s). Use npm version, which is JSON-aware and only touches the top-level field, and restore the corrupted scripts.version back to "standard-version". A post-bump assertion fails the release if scripts.version is ever clobbered again. For the repo's bare-semver release tags the bump is equivalent; npm version additionally strips a stray leading "v" and validates semver (failing fast) where the old sed wrote the tag verbatim. Flags: --no-git-tag-version (no CI commit/tag), --allow-same-version (tolerate re-runs), --ignore-scripts (don't fire the version lifecycle in CI).
1 parent ee5f42e commit f6ec1b8

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

.github/workflows/node_sdk_publish.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ jobs:
8383
8484
- name: Bump version at package.json
8585
run: |
86-
sed -i "s/\"version\": \".*\"/\"version\": \"${{ github.event.release.tag_name }}\"/" package.json
87-
cat package.json
88-
86+
# Bump only the top-level "version" field. npm is JSON-aware (unlike the
87+
# previous greedy sed, which also rewrote scripts.version); no git
88+
# tag/commit is created, re-runs on the same version are tolerated, and
89+
# the "version" lifecycle script (standard-version) is skipped.
90+
npm version "${{ github.event.release.tag_name }}" --no-git-tag-version --allow-same-version --ignore-scripts
91+
# Fail fast if the bump ever corrupts the scripts.version lifecycle hook again (the original #89 bug).
92+
node -e "if (require('./package.json').scripts.version !== 'standard-version') { console.error('scripts.version was corrupted by the version bump'); process.exit(1); }"
93+
8994
- name: Publish package to NPM
9095
run: |
9196
if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
4848
"docs": "typedoc",
4949
"docs:watch": "typedoc --watch",
50-
"version": "2.5.2",
50+
"version": "standard-version",
5151
"reset-hard": "git clean -dfx && git reset --hard && yarn",
5252
"prepare": "npm run build && husky install",
5353
"prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish",

0 commit comments

Comments
 (0)