-
Notifications
You must be signed in to change notification settings - Fork 17
release: adopt package.json semver as canonical version #208
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
Changes from all commits
9c28cff
cbc7551
a113401
0e75b01
a13333a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/bash | ||
| # Shared version helpers for Baudbot shell scripts. | ||
| # Prerequisite: callers must source bin/lib/json-common.sh before this file. | ||
|
|
||
| bb_package_json_path() { | ||
| local root="${1:?repo root required}" | ||
| echo "$root/package.json" | ||
| } | ||
|
|
||
| bb_package_lock_json_path() { | ||
| local root="${1:?repo root required}" | ||
| echo "$root/package-lock.json" | ||
| } | ||
|
|
||
| bb_package_version() { | ||
| local root="${1:?repo root required}" | ||
| local package_json="" | ||
|
|
||
| package_json="$(bb_package_json_path "$root")" | ||
| [ -r "$package_json" ] || return 1 | ||
| if ! command -v json_get_string >/dev/null 2>&1; then | ||
| echo "json_get_string unavailable; source bin/lib/json-common.sh before version-common.sh" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| json_get_string "$package_json" "version" | ||
| } | ||
|
Comment on lines
+15
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: bin/lib/version-common.sh
Line: 14-22
Comment:
**Undocumented dependency on `json_get_string` from `json-common.sh`**
`bb_package_version` calls `json_get_string`, which is defined in `bin/lib/json-common.sh` and not in this file. All current callers (`deploy.sh`, `update-release.sh`, `baudbot`, the test file) correctly source `json-common.sh` first, but there is no declaration of this requirement in `version-common.sh` itself. A sourcing guard or a comment at the top noting the prerequisite would prevent subtle breakage if this helper is ever sourced in a new context without the dependency.
How can I resolve this? If you propose a fix, please make it concise.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by documenting the json-common.sh prerequisite and adding a runtime guard in bb_package_version so a missing json_get_string fails clearly instead of breaking later. This comment was generated by Pi using OpenAI GPT-5 |
||
|
|
||
| bb_package_version_or_unknown() { | ||
| local root="${1:?repo root required}" | ||
| bb_package_version "$root" 2>/dev/null || echo "unknown" | ||
| } | ||
|
|
||
| bb_release_tag_for_version() { | ||
| local version="${1:?version required}" | ||
| echo "v$version" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/bin/bash | ||
| # Tests for bin/lib/version-common.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| # shellcheck source=bin/lib/json-common.sh | ||
| source "$SCRIPT_DIR/json-common.sh" | ||
| # shellcheck source=bin/lib/version-common.sh | ||
| source "$SCRIPT_DIR/version-common.sh" | ||
|
|
||
| TOTAL=0 | ||
| PASSED=0 | ||
| FAILED=0 | ||
|
|
||
| run_test() { | ||
| local name="$1" | ||
| shift | ||
| local out | ||
|
|
||
| TOTAL=$((TOTAL + 1)) | ||
| printf " %-45s " "$name" | ||
|
|
||
| out="$(mktemp /tmp/baudbot-version-common-test-output.XXXXXX)" | ||
| if "$@" >"$out" 2>&1; then | ||
| echo "✓" | ||
| PASSED=$((PASSED + 1)) | ||
| else | ||
| echo "✗ FAILED" | ||
| tail -40 "$out" | sed 's/^/ /' | ||
| FAILED=$((FAILED + 1)) | ||
| fi | ||
| rm -f "$out" | ||
| } | ||
|
|
||
| test_reads_package_version() { | ||
| ( | ||
| set -euo pipefail | ||
| local tmp | ||
| tmp="$(mktemp -d /tmp/baudbot-version-common.XXXXXX)" | ||
| trap 'rm -rf "$tmp"' EXIT | ||
|
|
||
| printf '{"version":"1.2.3"}\n' > "$tmp/package.json" | ||
| [ "$(bb_package_version "$tmp")" = "1.2.3" ] | ||
| ) | ||
| } | ||
|
|
||
| test_formats_release_tag() { | ||
| ( | ||
| set -euo pipefail | ||
| [ "$(bb_release_tag_for_version "2.3.4")" = "v2.3.4" ] | ||
| ) | ||
| } | ||
|
|
||
| echo "=== version-common tests ===" | ||
| echo "" | ||
|
|
||
| run_test "reads package.json version" test_reads_package_version | ||
| run_test "formats release tag" test_formats_release_tag | ||
|
|
||
| echo "" | ||
| echo "=== $PASSED/$TOTAL passed, $FAILED failed ===" | ||
|
|
||
| if [ "$FAILED" -gt 0 ]; then | ||
| exit 1 | ||
| fi |
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.
"vunknown"written into metadata JSON when version is unavailableWhen neither the git repo nor an existing
$RELEASE_META_FILEprovides a version (e.g., a freshly checked-out archive with nopackage.json),RELEASE_VERSIONis set to"unknown". The subsequentbb_release_tag_for_version "unknown"call then writes"tag": "vunknown"intobaudbot-version.json. Tools or operators parsing the tag field for semver validity would receive an unexpected value. Guarding thebb_release_tag_for_versioncall to only run whenRELEASE_VERSIONis not"unknown"would be more consistent.Prompt To Fix With AI
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.
Fixed. deploy.sh now only derives a release tag when the package version is known, so unknown-version metadata no longer becomes vunknown.
This comment was generated by Pi using OpenAI GPT-5