Skip to content

Commit

Permalink
add tag-new-crates.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Jul 10, 2024
1 parent 92e965b commit 22cc68e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ci/detect-changed-manifests.sh
Original file line number Diff line number Diff line change
@@ -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[@]}"
}
22 changes: 22 additions & 0 deletions ci/tag-new-crates.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 22cc68e

Please sign in to comment.