-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: derive CLI version from git tags instead of hard-coded package.json #1221
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
940f599
fix: derive CLI version from git tags instead of hard-coded package.json
cv 987e9bd
Merge branch 'main' into fix/derive-version-from-git-tags
cv 26bbb0f
fix: resolve ESLint error and speed up gateway recovery tests
cv 4dd9896
fix: align importOriginal type pattern across all test files
cv 9cbda4a
fix: use safe env var parsing for health-poll settings
cv e3e8b74
fix: skip sleep after final recovery poll attempt
cv fa3b31c
Merge branch 'main' into fix/derive-version-from-git-tags
cv c67e67b
fix(install): fall back cleanly when git tags are unavailable
cv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # Build artifacts and caches | ||
| .version | ||
| *.pyc | ||
| *.tsbuildinfo | ||
| .pytest_cache/ | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * Resolve the NemoClaw version from (in order): | ||
| * 1. `git describe --tags --match "v*"` — works in dev / source checkouts | ||
| * 2. `.version` file at repo root — stamped at publish time | ||
| * 3. `package.json` version — hard-coded fallback | ||
| */ | ||
|
|
||
| const { execFileSync } = require("child_process"); | ||
| const path = require("path"); | ||
| const fs = require("fs"); | ||
|
|
||
| const ROOT = path.resolve(__dirname, "..", ".."); | ||
|
|
||
| function getVersion() { | ||
| // 1. Try git (available in dev clones and CI) | ||
| try { | ||
| const raw = execFileSync("git", ["describe", "--tags", "--match", "v*"], { | ||
| cwd: ROOT, | ||
| encoding: "utf-8", | ||
| stdio: ["ignore", "pipe", "ignore"], | ||
| }).trim(); | ||
| // raw looks like "v0.3.0" or "v0.3.0-4-gabcdef1" | ||
| if (raw) return raw.replace(/^v/, ""); | ||
| } catch { | ||
| // no git, or no matching tags — fall through | ||
| } | ||
|
|
||
| // 2. Try .version file (stamped by prepublishOnly) | ||
| try { | ||
| const ver = fs.readFileSync(path.join(ROOT, ".version"), "utf-8").trim(); | ||
| if (ver) return ver; | ||
| } catch { | ||
| // not present — fall through | ||
| } | ||
|
|
||
| // 3. Fallback to package.json | ||
| return require(path.join(ROOT, "package.json")).version; | ||
| } | ||
|
|
||
| module.exports = { getVersion }; |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Pre-push hook: when pushing a v* tag, verify that package.json at the | ||
| # tagged commit has a matching version. Blocks the push if they differ. | ||
| # | ||
| # Usage (called by prek as a pre-push hook): | ||
| # echo "<local-ref> <local-sha> <remote-ref> <remote-sha>" | bash scripts/check-version-tag-sync.sh | ||
| # | ||
| # Manual check (no stdin needed — compares latest v* tag with package.json): | ||
| # bash scripts/check-version-tag-sync.sh --check | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| RED=$'\033[1;31m' | ||
| GREEN=$'\033[32m' | ||
| DIM=$'\033[2m' | ||
| RESET=$'\033[0m' | ||
|
|
||
| ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
|
|
||
| # Extract the "version" field from the package.json at a given commit. | ||
| version_at_commit() { | ||
| local sha="$1" | ||
| git -C "$ROOT" show "${sha}:package.json" 2>/dev/null \ | ||
| | sed -nE 's/^[[:space:]]*"version":[[:space:]]*"([^"]+)".*/\1/p' \ | ||
| | head -1 | ||
| } | ||
|
|
||
| check_tag() { | ||
| local tag="$1" sha="$2" | ||
| local tag_version="${tag#v}" | ||
| local pkg_version | ||
| pkg_version="$(version_at_commit "$sha")" | ||
|
|
||
| if [[ -z "$pkg_version" ]]; then | ||
| echo "${RED}✗${RESET} Tag ${tag}: could not read package.json at ${sha:0:8}" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| if [[ "$pkg_version" != "$tag_version" ]]; then | ||
| cat >&2 <<EOF | ||
|
|
||
| ${RED}✗ Version mismatch for tag ${tag}${RESET} | ||
|
|
||
| Tag version: ${tag_version} | ||
| package.json version: ${pkg_version} | ||
|
|
||
| Update package.json before tagging: | ||
|
|
||
| ${DIM}npm version ${tag_version} --no-git-tag-version | ||
| git add package.json | ||
| git commit --amend --no-edit | ||
| git tag -f ${tag}${RESET} | ||
|
|
||
| EOF | ||
| return 1 | ||
| fi | ||
|
|
||
| echo "${GREEN}✓${RESET} Tag ${tag} matches package.json (${pkg_version})" | ||
| return 0 | ||
| } | ||
|
|
||
| # ------------------------------------------------------------------ | ||
| # --check mode: compare the latest v* tag against current package.json | ||
| # ------------------------------------------------------------------ | ||
| if [[ "${1:-}" == "--check" ]]; then | ||
| latest_tag="$(git -C "$ROOT" describe --tags --match 'v*' --abbrev=0 2>/dev/null || true)" | ||
| if [[ -z "$latest_tag" ]]; then | ||
| echo "${DIM}No v* tags found — nothing to check.${RESET}" | ||
| exit 0 | ||
| fi | ||
| sha="$(git -C "$ROOT" rev-list -1 "$latest_tag")" | ||
| check_tag "$latest_tag" "$sha" | ||
| exit $? | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------ | ||
| # Pre-push mode: read pushed refs from stdin | ||
| # ------------------------------------------------------------------ | ||
| errors=0 | ||
|
|
||
| while IFS=' ' read -r local_ref local_sha _remote_ref _remote_sha; do | ||
| # Only care about v* tag pushes | ||
| case "$local_ref" in | ||
| refs/tags/v*) | ||
| tag="${local_ref#refs/tags/}" | ||
| check_tag "$tag" "$local_sha" || errors=$((errors + 1)) | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if ((errors > 0)); then | ||
| exit 1 | ||
| fi |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.