From f6ec1b8aba1c565f2b216865a233ca100c95ef5a Mon Sep 17 00:00:00 2001 From: Kyzgor Date: Tue, 23 Jun 2026 22:09:49 +0100 Subject: [PATCH] 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). --- .github/workflows/node_sdk_publish.yaml | 11 ++++++++--- package.json | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/node_sdk_publish.yaml b/.github/workflows/node_sdk_publish.yaml index 7f03e5f..1a2a429 100644 --- a/.github/workflows/node_sdk_publish.yaml +++ b/.github/workflows/node_sdk_publish.yaml @@ -83,9 +83,14 @@ jobs: - name: Bump version at package.json run: | - sed -i "s/\"version\": \".*\"/\"version\": \"${{ github.event.release.tag_name }}\"/" package.json - cat package.json - + # Bump only the top-level "version" field. npm is JSON-aware (unlike the + # previous greedy sed, which also rewrote scripts.version); no git + # tag/commit is created, re-runs on the same version are tolerated, and + # the "version" lifecycle script (standard-version) is skipped. + npm version "${{ github.event.release.tag_name }}" --no-git-tag-version --allow-same-version --ignore-scripts + # Fail fast if the bump ever corrupts the scripts.version lifecycle hook again (the original #89 bug). + node -e "if (require('./package.json').scripts.version !== 'standard-version') { console.error('scripts.version was corrupted by the version bump'); process.exit(1); }" + - name: Publish package to NPM run: | if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then diff --git a/package.json b/package.json index c8efff7..c285f68 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100", "docs": "typedoc", "docs:watch": "typedoc --watch", - "version": "2.5.2", + "version": "standard-version", "reset-hard": "git clean -dfx && git reset --hard && yarn", "prepare": "npm run build && husky install", "prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish",