From 3ded9ca7e002cece4c9ed83c8732cd816e6b40b6 Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Tue, 13 Aug 2024 17:53:51 -0400 Subject: [PATCH 1/3] add `detect-changed-manifests` script --- ci/detect-changed-manifests.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 ci/detect-changed-manifests.sh diff --git a/ci/detect-changed-manifests.sh b/ci/detect-changed-manifests.sh new file mode 100755 index 00000000000..52c311f7fb5 --- /dev/null +++ b/ci/detect-changed-manifests.sh @@ -0,0 +1,25 @@ +# Source this file. +# +# Detects any manifests whose versions have changed. +# Does so by comparing the current version in the Cargo.toml with the previous +# version in the last commit. Intended for squash-merged PRs. + +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 manifest. + local current_version=$(grep -E '^version\s*=' "$file" | sed -E 's/version\s*=\s*"(.*)"/\1/') + + # Get the previous version from the last commit. + 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[@]}" +} \ No newline at end of file From 87e586a2cd5f737e441a79e6bdf00ac17f82707e Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Tue, 13 Aug 2024 17:54:01 -0400 Subject: [PATCH 2/3] add `tag-releases` script --- ci/tag-releases.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 ci/tag-releases.sh diff --git a/ci/tag-releases.sh b/ci/tag-releases.sh new file mode 100755 index 00000000000..faf552b47fb --- /dev/null +++ b/ci/tag-releases.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# +# Creates a new git tag for each package that has a new version. + +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 manifest. + 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 \ No newline at end of file From 44e0c737c0f39a473f6cdb853857aa76f123da3e Mon Sep 17 00:00:00 2001 From: Joe Caulfield Date: Tue, 13 Aug 2024 17:54:14 -0400 Subject: [PATCH 3/3] add `release` workflow --- .github/workflows/release.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..b6fc70ef7b4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,23 @@ +name: Release + +on push: + branches: + - master + paths-ignore: + - 'docs/**' + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Create tags + id: create_tags + run: | + ci/tag-new-crates.sh + git push --tags + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}