Skip to content

fix(core): stamp libraryInfo.version with the version being released - #1338

Merged
abueide merged 1 commit into
masterfrom
fix/core-release-version-stamp
Oct 9, 2026
Merged

abueide merged 1 commit into
masterfrom
fix/core-release-version-stamp

Conversation

@abueide

@abueide abueide commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Every @segment/analytics-react-native release since 2.22.0 ships info.js stamped 2.21.4, so every event reports context.library.version: '2.21.4'.

  • packages/core/src/info.ts is gitignored and generated by constants-generator.js from package.json.
  • fix(ci): remove @semantic-release/git, add sync-versions command #1141 removed @semantic-release/git, so version bumps are no longer committed back. packages/core/package.json on master has been stuck at 2.21.4 since.
  • release.yml runs yarn build before semantic-release, so lib/ gets 2.21.4. Semantic-release then bumps package.json only in the tarball. prepack would regenerate, but it's skipped because NPM_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 a prepare step. It runs yarn build in core with SEGMENT_LIBRARY_VERSION=${nextRelease.version}. It then checks that src/info.ts, lib/commonjs/info.js and lib/module/info.js all 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's prepare before any publish, so the order is npm prepare (bump), then stamp + rebuild, then npm publish. Only core gets this. Other packages are untouched.
  • constants-generator.js: uses SEGMENT_LIBRARY_VERSION when it's set and falls back to package.json for local builds. It also switches to writeFileSync, so a write failure fails the build instead of only being logged.
  • I used a local plugin instead of @semantic-release/exec so there's no new dependency and no curation risk.

Answers to the open questions in the RCA:

  • The publish job does its own build in the same job as semantic-release, not an artifact from "Lint + Build + Test". The prepare step rebuilds in that job.
  • multi-semantic-release runs each package's semantic-release with cwd set to the package dir, so ./release-stamp-version.js resolves from packages/core and context.cwd is packages/core.

Verification

  • I ran the plugin's prepare locally against packages/core with nextRelease.version = 9.9.9-beta.1. src/info.ts, lib/commonjs/info.js and lib/module/info.js all came out 9.9.9-beta.1.
  • I loaded the resolved semantic-release config through msr's config loader with logging on. Core shows prepare from @semantic-release/npm and then prepare from ./release-stamp-version.js. Sovran shows only the npm one.
  • multi-semantic-release --dry-run loads every package without errors. Dry-run skips prepare, so it doesn't exercise the stamp itself.
  • Still to do: publish a beta, then npm pack @segment/analytics-react-native@<beta> and confirm lib/commonjs/info.js matches package.json.

Not in this PR

  • Events already sent from 2.22.0 through 2.24.1 keep reporting 2.21.4.
  • packages/core/package.json on master is still 2.21.4, so local builds keep reporting that. scripts/sync-versions.sh can fix it in a separate PR.
  • The core CHANGELOG.md has likely been stale since 2.21.4 for the same reason. I haven't checked.

🤖 Generated with Claude Code

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>
@abueide
abueide merged commit af1fb1b into master Oct 9, 2026
11 checks passed
@abueide
abueide deleted the fix/core-release-version-stamp branch October 9, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant