Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-version-sync-workspace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@googleworkspace/cli": patch
---

Fix version-sync script and bump CLI crate version to 0.21.0

The `version-sync.sh` script was updating the root `Cargo.toml` which no longer has a `[package]` section after the workspace refactor. Updated to target `crates/google-workspace-cli/Cargo.toml`. Also syncs the CLI crate version to 0.21.0 to match `package.json`.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/google-workspace-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

[package]
name = "google-workspace-cli"
version = "0.20.1"
version = "0.21.0"
edition = "2021"
description = "Google Workspace CLI — dynamic command surface from Discovery Service"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/google-workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

[package]
name = "google-workspace"
version = "0.1.0"
version = "0.21.0"
edition = "2021"
description = "Google Workspace API client — Discovery Document types, service registry, and HTTP utilities"
license = "Apache-2.0"
Expand Down
23 changes: 14 additions & 9 deletions scripts/version-sync.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Syncs the version from package.json into Cargo.toml, updates Cargo.lock, and regenerates skills.
# Syncs the version from package.json into all workspace Cargo.toml files,
# updates Cargo.lock, and regenerates skills.
# Used by changesets/action as a custom version command.
set -euo pipefail

Expand All @@ -9,14 +10,17 @@ pnpm changeset version
# Read the new version from package.json
VERSION=$(node -p "require('./package.json').version")

# Update Cargo.toml version field
# Update version in all workspace crate Cargo.toml files
# Uses awk to only change the version under [package], not other sections
awk -v ver="$VERSION" '
/^\[package\]/ { in_pkg=1 }
/^\[/ && !/^\[package\]/ { in_pkg=0 }
in_pkg && /^version = / { $0 = "version = \"" ver "\"" }
{ print }
' Cargo.toml > Cargo.toml.tmp && mv Cargo.toml.tmp Cargo.toml
for cargo_toml in crates/*/Cargo.toml; do
tmp=$(mktemp)
awk -v ver="$VERSION" '
/^\[package\]/ { in_pkg=1 }
/^\[/ && !/^\[package\]/ { in_pkg=0 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current awk script is brittle as it assumes a specific formatting for the version key in Cargo.toml (version = ...). TOML allows for different spacing, such as version=... or version = .... The script will fail to update the version if the spacing is different, which could lead to an inconsistent state in the repository during the release process. It's better to make the pattern matching more flexible to handle optional whitespace.

Suggested change
/^\[/ && !/^\[package\]/ { in_pkg=0 }
in_pkg && /^version[[:space:]]*=/ { $0 = "version = \"" ver "\"" }

in_pkg && /^version = / { $0 = "version = \"" ver "\"" }
{ print }
' "$cargo_toml" > "$tmp" && mv "$tmp" "$cargo_toml"
done
Comment on lines +15 to +23

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of mktemp without proper cleanup can lead to temporary files being left behind, especially if the script exits unexpectedly (e.g., if the awk command fails). This can clutter the temporary directory and potentially fill up disk space over time in a CI environment.

To ensure temporary files are always cleaned up, it's best practice to wrap the file modification logic in a subshell with a trap for the EXIT signal. This guarantees that the temporary file is removed when the subshell exits, regardless of whether it's due to success or failure.

Suggested change
for cargo_toml in crates/*/Cargo.toml; do
tmp=$(mktemp)
awk -v ver="$VERSION" '
/^\[package\]/ { in_pkg=1 }
/^\[/ && !/^\[package\]/ { in_pkg=0 }
in_pkg && /^version = / { $0 = "version = \"" ver "\"" }
{ print }
' "$cargo_toml" > "$tmp" && mv "$tmp" "$cargo_toml"
done
for cargo_toml in crates/*/Cargo.toml; do
( # Run in a subshell to scope the trap and ensure cleanup
set -e # It's good practice to be explicit in subshells
tmp=$(mktemp)
trap "rm -f '$tmp'" EXIT
awk -v ver="$VERSION" '
/^\[package\]/ { in_pkg=1 }
/^\[/ && !/^\[package\]/ { in_pkg=0 }
in_pkg && /^version = / { $0 = "version = \"" ver "\"" }
{ print }
' "$cargo_toml" > "$tmp" && mv "$tmp" "$cargo_toml"
)
done


# Update Cargo.lock to match
cargo generate-lockfile
Expand All @@ -30,4 +34,5 @@ fi
cargo run -- generate-skills --output-dir skills

# Stage the changed files so changesets/action commits them
git add Cargo.toml Cargo.lock flake.nix flake.lock skills/
git add crates/*/Cargo.toml Cargo.lock flake.nix flake.lock skills/

Loading