diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /src/tools/cargo/ci/validate-version-bump.sh | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz rustc-837b550238aa671a591ccf282dddeab29cadb206.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/cargo/ci/validate-version-bump.sh')
-rwxr-xr-x | src/tools/cargo/ci/validate-version-bump.sh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/tools/cargo/ci/validate-version-bump.sh b/src/tools/cargo/ci/validate-version-bump.sh new file mode 100755 index 000000000..9b54fdaaf --- /dev/null +++ b/src/tools/cargo/ci/validate-version-bump.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# This script checks if a crate needs a version bump. +# +# At the time of writing, it doesn't check what kind of bump is required. +# In the future, we could take SemVer compatibliity into account, like +# integrating `cargo-semver-checks` of else +# +# Inputs: +# BASE_SHA The commit SHA of the branch where the PR wants to merge into. +# HEAD_SHA The commit SHA that triggered the workflow. + +set -euo pipefail + +# When `BASE_SHA` is missing, we assume it is from bors merge commit, +# so hope `HEAD~` to find the previous commit on master branch. +base_sha=$(git rev-parse "${BASE_SHA:-HEAD~1}") +head_sha=$(git rev-parse "${HEAD_SHA:-HEAD}") + +echo "Base branch is $base_sha" +echo "Current head is $head_sha" + +# Gets crate names of members that has been changed from $bash_sha to $head_sha. +changed_crates=$( + git diff --name-only "$base_sha" "$head_sha" -- crates/ credential/ benches/ \ + | cut -d'/' -f2 \ + | sort -u +) + +if [ -z "$changed_crates" ] +then + echo "No file changed in member crates." + exit 0 +fi + +# Checks publish status for only crates with code changes. +publish_status_table=$( + echo "$changed_crates" \ + | xargs printf -- '--package %s\n' \ + | xargs cargo unpublished +) + +# "yes" -> code changed but no version difference -> need a bump +# Prints 2nd column (sep by space), which is the name of the crate. +crates_need_bump=$( + echo "$publish_status_table" \ + | { grep '| yes ' || true; } \ + | awk '{print $2}' +) + +if [ -z "$crates_need_bump" ] +then + echo "No version bump needed for member crates." + exit 0 +fi + +echo "Detected changes in these crates but no version bump found:" +echo "$crates_need_bump" +echo +echo "Please bump at least one patch version for each corresponding Cargo.toml:" +echo 'Run "cargo unpublished" to read the publish status table for details.' +exit 1 |