-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: sync CLI version with package.json during publish #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Resolves #501 **Problem:** - CLI flag reported outdated version (e.g., 2.13.2) - package.json and get-local-version showed correct version (e.g., 2.14.0) - Root cause: publish workflow built CLI before bumping version in package.json **Solution:** 1. Created script/bump-version.ts to bump version before build 2. Modified publish workflow to run bump-version.ts before Build step 3. Modified publish.ts to skip version bump if already done **Workflow now:** 1. Bump Version (updates package.json) 2. Build (embeds NEW version into dist/cli/index.js) 3. Publish (uses correct version) **Testing:** - Local build test confirms version correctly embedded in bundle - Workflow now guarantees version sync between package.json and CLI
Greptile SummaryFixed CLI version mismatch by reordering workflow steps to bump Key Changes:
Root Cause: Solution: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant GH as GitHub Workflow
participant BV as bump-version.ts
participant NPM as npm Registry
participant PKG as package.json
participant Build as Build Process
participant Pub as publish.ts
Note over GH: Workflow Triggered (bump=patch/minor/major)
GH->>BV: Execute bump-version.ts
BV->>NPM: Fetch previous version
NPM-->>BV: Return version (e.g., 2.13.2)
BV->>BV: Calculate new version (e.g., 2.14.0)
BV->>NPM: Check if version exists
NPM-->>BV: Not found
BV->>PKG: Update version field to 2.14.0
PKG-->>BV: Success
Note over GH,Build: Build Phase - NEW version now in package.json
GH->>Build: Execute build script
Build->>PKG: Import package.json
PKG-->>Build: { version: "2.14.0" }
Build->>Build: Embed version in dist/cli/index.js
Note over Build: VERSION = "2.14.0" now hardcoded in bundle
GH->>Pub: Execute publish.ts
Pub->>NPM: Fetch previous version
NPM-->>Pub: Return 2.13.2
Pub->>PKG: Read current package.json version
PKG-->>Pub: Return 2.14.0
Pub->>Pub: Detect version already bumped (2.14.0 != 2.13.2)
Pub->>Pub: Skip package.json update
Pub->>NPM: Publish package with matching versions
Note over NPM: package.json = 2.14.0, CLI = 2.14.0 ✅
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 3 files
Confidence score: 3/5
script/bump-version.tstreatsprocess.env.BUMPas valid without runtime validation, so an unexpected value causesbumpVersion()to returnundefined, likely breaking release scripts—worth tightening before merge.main()is invoked without catching its promise, so failures in the bump script could result in silent unhandled rejections instead of a clean non-zero exit.- Pay close attention to
script/bump-version.ts– ensure env validation and promise rejection handling are in place.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="script/bump-version.ts">
<violation number="1" location="script/bump-version.ts:6">
P1: Type assertion on `BUMP` env var doesn't validate the value at runtime. If an invalid value like `"invalid"` is passed, `bumpVersion()` will return `undefined` since the switch has no `default` case. Consider validating the value or adding a default case.</violation>
<violation number="2" location="script/bump-version.ts:69">
P2: The `main()` call doesn't handle the returned promise. Unhandled rejections may not exit with proper error code. Add `.catch()` to handle errors and exit with non-zero code.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| import { $ } from "bun" | ||
|
|
||
| const PACKAGE_NAME = "oh-my-opencode" | ||
| const bump = process.env.BUMP as "major" | "minor" | "patch" | undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Type assertion on BUMP env var doesn't validate the value at runtime. If an invalid value like "invalid" is passed, bumpVersion() will return undefined since the switch has no default case. Consider validating the value or adding a default case.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At script/bump-version.ts, line 6:
<comment>Type assertion on `BUMP` env var doesn't validate the value at runtime. If an invalid value like `"invalid"` is passed, `bumpVersion()` will return `undefined` since the switch has no `default` case. Consider validating the value or adding a default case.</comment>
<file context>
@@ -0,0 +1,69 @@
+import { $ } from "bun"
+
+const PACKAGE_NAME = "oh-my-opencode"
+const bump = process.env.BUMP as "major" | "minor" | "patch" | undefined
+const versionOverride = process.env.VERSION
+
</file context>
| console.log(`New version will be embedded in the next build.`) | ||
| } | ||
|
|
||
| main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The main() call doesn't handle the returned promise. Unhandled rejections may not exit with proper error code. Add .catch() to handle errors and exit with non-zero code.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At script/bump-version.ts, line 69:
<comment>The `main()` call doesn't handle the returned promise. Unhandled rejections may not exit with proper error code. Add `.catch()` to handle errors and exit with non-zero code.</comment>
<file context>
@@ -0,0 +1,69 @@
+ console.log(`New version will be embedded in the next build.`)
+}
+
+main()
</file context>
Summary
Fixes #501 - CLI
-vflag now reports the correct version matching package.jsonProblem
bunx oh-my-opencode -vreported outdated version (e.g., 2.13.2)bunx oh-my-opencode get-local-versionshowed correct version (e.g., 2.14.0) from package.jsonSolution
script/bump-version.ts- Standalone script to bump version in package.jsonscript/publish.ts- Skip version bump if package.json already updatedWorkflow Changes
Before:
After:
Testing
Files Changed
script/bump-version.ts(new) - Version bumping logic.github/workflows/publish.yml- Added bump step before buildscript/publish.ts- Added logic to skip version bump if already doneSummary by cubic
Syncs the CLI -v output with package.json by bumping the version before build in the publish workflow and skipping redundant bumps. Fixes #501.
Written for commit d3a3ef8. Summary will update on new commits.