build(mwpw-179848): stamp builds with correct version tag and release-it #319
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.
Fix Webpack Bundle Version Stamping in CI/CD Pipeline
Background & Root Cause
Currently, our Webpack builds (using BannerPlugin) read the version straight from
package.jsonat build time. However, our CI/CD release pipeline usesrelease-it, which runs Webpack before it bumps and tagspackage.json. As a result, every published bundle is stamped with the previous version rather than the newly released version—an off‐by‐one version mismatch in the banner.Root Cause:
package.json.versionwhen Webpack runsrelease-it(vianpm run release) does:package.jsonSolution Overview
Modify BannerPlugin to read from
git describe --tags(with an optionalRELEASE_TAGoverride).git describe --tags --abbrev=0always returns the latest annotated tag (e.g.v0.35.4)release-ittagsv0.35.5, BannerPlugin'sgit describecall sees exactly that new tagHook into
release-itso that Webpack builds after the new tag is created. We use theafter:git:taghook to run:This means:
release-itbumps & tags (e.g. 0.35.5)npm run build(BannerPlugin sees 0.35.5)dist/and amend the same "chore: release v0.35.5" commit to includedist/release-itpushes that amended commit and tag to GitHub and creates the Release—sodist/is always stamped with the correct versionWhat Changed
webpack.config.jsBefore: BannerPlugin read from
packageJson.versionAfter:
Rationale: By using
git describe --tags, Webpack always picks up the latest Git tag (e.g.v0.35.5), so banners cannot be off by one.package.jsonBefore:
release-itran Webpack in CI before taggingAfter: Under
"release-it"→"hooks", we added:Rationale:
release-ithas created the new tag (e.g. 0.35.5), our hook triggers a rebuildgit describe --tagsreturns the just‐created tag, guaranteeing the new version is baked intodist/git commit --amendso thatpackage.json,CHANGELOG.md, and the rebuiltdist/all live in a single commit (chore: release v0.35.5).release-itthen pushes and publishes normallyHow to Test
1. Local BannerPlugin Check (without running
npm run release)Ensure you have at least one Git tag. If none exist, create a lightweight tag:
Run a plain build:
Verify the top lines of
dist/main.jsshow:/*! Chimera UI Libraries - Build 0.35.4 (YYYY-MM-DD) */Override via
RELEASE_TAGto simulate an upcoming release:Check
dist/main.jsagain—banner should read "Build 0.35.5 …".2. Dry‐run
release-itLocallyCreate a dummy commit so there's something new to release:
touch DUMMY.md git add DUMMY.md git commit -m "chore: test release-it integration"Run:
Expected output sequence:
v0.35.5npm run build(BannerPlugin now seesv0.35.5)git add distgit commit --amend --no-edit(amend "chore: release v0.35.5" commit to includedist/)Final local state: one commit tagged 0.35.5 containing both the bumped
package.jsonand builtdist/.Validate:
Confirm banner reads 0.35.5 in
dist/main.js.3. CI Verification
mainpush: main) runnpm run release. WithGITHUB_TOKENset in Secrets:release-itwill bump → tag → run our hook → rebuild → amend → push → publishv0.35.6). Download or view the publisheddist/main.jsfrom that release—banner must say "Build 0.35.6" (or whichever version CI picked)Why We Chose This Approach
Simplicity
release-it(no major tooling changes)release-itfeature; no external shell scripts or manual stepsReliability
git describe --tagsalways returns the exact tag that was just created, so no off‐by‐one issuespackage.json,CHANGELOG.md, anddist/stay in syncConsistency (Local vs. CI)
npm run buildand see the latest Git tag in the bannerChecklist
RELEASE_TAGoverride)release-itconfigured to build/commitdist/after creating the release tagnpm run build,git show 0.35.5:dist/main.js) passednpx release-it --ci --no-pushshowed correct behavior (bump, tag, rebuild, amend)mainconfirms new release is published with correctly stampeddistassetsPlease let me know if you need any further tweaks or clarifications!