Explorar o código

ci: improve version update script (#1553)

* only apply related changes when bumping version

* ignore Cargo.toml if no match version

* fix shell check

* follow shellcheck SC2035
Yihau Chen hai 1 ano
pai
achega
5ff77062b2
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      scripts/increment-cargo-version.sh

+ 12 - 2
scripts/increment-cargo-version.sh

@@ -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
 
@@ -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