From 22cc68e0adb7a501296c533adf05ef86d2272e99 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Wed, 10 Jul 2024 17:06:09 -0500 Subject: [PATCH] add `tag-new-crates.sh` --- ci/detect-changed-manifests.sh | 23 +++++++++++++++++++++++ ci/tag-new-crates.sh | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 ci/detect-changed-manifests.sh create mode 100755 ci/tag-new-crates.sh diff --git a/ci/detect-changed-manifests.sh b/ci/detect-changed-manifests.sh new file mode 100755 index 00000000000..61b6e22ca99 --- /dev/null +++ b/ci/detect-changed-manifests.sh @@ -0,0 +1,23 @@ +# Source this file. +# +# Detects any changed Cargo manifests. + +detect_changed_manifests() { + local changed_manifests=() + local cargo_toml_files=$(find . -name "Cargo.toml") + + for file in $cargo_toml_files; do + # Get the current version from the Cargo.toml. + local current_version=$(grep -E '^version\s*=' "$file" | sed -E 's/version\s*=\s*"(.*)"/\1/') + + # Get the previous version from the last committed Cargo.toml. + local previous_version=$(git show HEAD~1:"$file" | grep -E '^version\s*=' | sed -E 's/version\s*=\s*"(.*)"/\1/' 2>/dev/null) + + # Compare the versions and add the path to the list if they are different. + if [ "$current_version" != "$previous_version" ]; then + changed_manifests+=("$file") + fi + done + + echo "${changed_manifests[@]}" +} diff --git a/ci/tag-new-crates.sh b/ci/tag-new-crates.sh new file mode 100755 index 00000000000..ee80611fec5 --- /dev/null +++ b/ci/tag-new-crates.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e + +source ci/detect-changed-manifests.sh + +changed_manifests=$(detect_changed_manifests) + +if [ -n "$changed_manifests" ]; then + for manifest_path in $changed_manifests; do + # Read the package name and version from its Cargo.toml. + package_name=$(grep '^name\s*=' "$manifest_path" | awk -F'\"' '{print $2}') + new_version=$(grep '^version\s*=' "$manifest_path" | awk -F'\"' '{print $2}') + + # Create a new git tag. + tag_name="${package_name}-v${new_version}" + git tag "$tag_name" + echo "Created tag: $tag_name" + done +else + echo "No versions changed." +fi