Repository navigation
fix(core): stamp libraryInfo.version with the version being released - #1338
Merged
Merged
Conversation
Since #1141 stopped committing version bumps, packages/core/package.json on master stayed at 2.21.4, and the build that runs before semantic-release baked that into info.ts/info.js. Every release since 2.22.0 reports context.library.version 2.21.4. Add a local semantic-release prepare plugin for core that runs after @semantic-release/npm's prepare, rebuilds with SEGMENT_LIBRARY_VERSION set to nextRelease.version, and refuses to publish if src/info.ts or lib/*/info.js don't carry that version. constants-generator.js reads the env var and falls back to package.json for local builds. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every
@segment/analytics-react-nativerelease since 2.22.0 shipsinfo.jsstamped2.21.4, so every event reportscontext.library.version: '2.21.4'.packages/core/src/info.tsis gitignored and generated byconstants-generator.jsfrompackage.json.@semantic-release/git, so version bumps are no longer committed back.packages/core/package.jsonon master has been stuck at2.21.4since.release.ymlrunsyarn buildbefore semantic-release, solib/gets2.21.4. Semantic-release then bumpspackage.jsononly in the tarball.prepackwould regenerate, but it's skipped becauseNPM_CONFIG_IGNORE_SCRIPTS=true.Fix
Stamp the version after semantic-release has computed it. #1141's branch-protection workaround stays as is.
packages/core/release-stamp-version.js: a local semantic-release plugin with apreparestep. It runsyarn buildin core withSEGMENT_LIBRARY_VERSION=${nextRelease.version}. It then checks thatsrc/info.ts,lib/commonjs/info.jsandlib/module/info.jsall contain that version, and fails the release before publish if any of them don't. That check is the guard against this coming back.packages/core/release.config.js: inserts the plugin right after@semantic-release/npm. Semantic-release runs every plugin'spreparebefore anypublish, so the order is npm prepare (bump), then stamp + rebuild, then npm publish. Only core gets this. Other packages are untouched.constants-generator.js: usesSEGMENT_LIBRARY_VERSIONwhen it's set and falls back topackage.jsonfor local builds. It also switches towriteFileSync, so a write failure fails the build instead of only being logged.@semantic-release/execso there's no new dependency and no curation risk.Answers to the open questions in the RCA:
cwdset to the package dir, so./release-stamp-version.jsresolves frompackages/coreandcontext.cwdispackages/core.Verification
preparelocally againstpackages/corewithnextRelease.version = 9.9.9-beta.1.src/info.ts,lib/commonjs/info.jsandlib/module/info.jsall came out9.9.9-beta.1.preparefrom@semantic-release/npmand thenpreparefrom./release-stamp-version.js. Sovran shows only the npm one.multi-semantic-release --dry-runloads every package without errors. Dry-run skipsprepare, so it doesn't exercise the stamp itself.npm pack @segment/analytics-react-native@<beta>and confirmlib/commonjs/info.jsmatchespackage.json.Not in this PR
packages/core/package.jsonon master is still 2.21.4, so local builds keep reporting that.scripts/sync-versions.shcan fix it in a separate PR.CHANGELOG.mdhas likely been stale since 2.21.4 for the same reason. I haven't checked.🤖 Generated with Claude Code