Skip to content

Commit

Permalink
ci: improve version update script (#1553)
Browse files Browse the repository at this point in the history
* only apply related changes when bumping version

* ignore Cargo.toml if no match version

* fix shell check

* follow shellcheck SC2035
  • Loading branch information
yihau authored Jun 4, 2024
1 parent c3bd350 commit 5ff7706
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/increment-cargo-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ newVersion="$MAJOR.$MINOR.$PATCH$SPECIAL"

# Update all the Cargo.toml files
for Cargo_toml in "${Cargo_tomls[@]}"; do
# ignore when version inheritant from workspace (exclude programs/sbf/Cargo.toml)
if grep "^version = { workspace = true }" "$Cargo_toml" &>/dev/null && Cargo_toml && ! [[ $Cargo_toml =~ programs/sbf/Cargo.toml ]]; then
if ! grep "$currentVersion" "$Cargo_toml"; then
echo "$Cargo_toml (skipped)"
continue
fi

Expand All @@ -146,6 +146,16 @@ done
# Update cargo lock files
scripts/cargo-for-all-lock-files.sh tree >/dev/null

# Only apply related changes
(
shopt -s globstar
git diff --unified=0 ./**/Cargo.lock >cargo-lock-patch
grep -E '^(diff|index|---|\+\+\+|@@.*@@ name = .*|-version|\+version)' cargo-lock-patch >filtered-cargo-lock-patch
git checkout ./**/Cargo.lock
git apply --unidiff-zero filtered-cargo-lock-patch
rm cargo-lock-patch filtered-cargo-lock-patch
)

echo "$currentVersion -> $newVersion"

exit 0

0 comments on commit 5ff7706

Please sign in to comment.