Skip to content

Commit 6145d0c

Browse files
committed
Auto merge of #12395 - weihanglo:cargo-semver-checks, r=epage
ci: rewrite bump check and respect semver ### What does this PR try to resolve? This ports `ci/validate-version-bump.sh` and #12200 to the new xtask `bump-check`. It also adds the ability to set the correct baseline revision when checking version bump. That is, it fixes #12347. In addition, this integrates the community tool `cargo-semver-checks`. SemVer violation can now be detected earlier. ### How should we test and review this PR? This PR extracts the registry query part from `xtask-unpublished` and removes other pars. I don't feel like we need it in the short term. For how it works, please the check doc comment in each function. One concern is that this check is still a required job for bors. I believe `@obi1kenobi` is quite responsive and willing to help if there is something wrong. So, waiting for an upstream fix won't be a problem for cargo. Also as a good citizen in the community, we can always contribute back. (Take it easy `@obi1kenobi,` don't be stressed out 🙂) <!-- homu-ignore:end -->
2 parents baebd2b + 8d31d62 commit 6145d0c

File tree

8 files changed

+439
-253
lines changed

8 files changed

+439
-253
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[alias]
22
build-man = "run --package xtask-build-man --"
33
stale-label = "run --package xtask-stale-label --"
4-
unpublished = "run --package xtask-unpublished --"
4+
bump-check = "run --package xtask-bump-check --"

.github/workflows/main.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ jobs:
9191
steps:
9292
- uses: actions/checkout@v3
9393
with:
94-
fetch-depth: 0 # make `git diff` work
94+
fetch-depth: 0
9595
- run: rustup update stable && rustup default stable
96+
- name: Install cargo-semver-checks
97+
run: |
98+
mkdir installed-bins
99+
curl -Lf https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.22.1/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz \
100+
| tar -xz --directory=./installed-bins
101+
echo `pwd`/installed-bins >> $GITHUB_PATH
96102
- run: ci/validate-version-bump.sh
97103

98104
test:

Cargo.lock

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ci/validate-version-bump.sh

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,7 @@ set -euo pipefail
1616
base_sha=$(git rev-parse "${BASE_SHA:-HEAD~1}")
1717
head_sha=$(git rev-parse "${HEAD_SHA:-HEAD}")
1818

19-
echo "Base branch is $base_sha"
20-
echo "Current head is $head_sha"
19+
echo "Base revision is $base_sha"
20+
echo "Head revision is $head_sha"
2121

22-
# Gets crate names of members that has been changed from $bash_sha to $head_sha.
23-
changed_crates=$(
24-
git diff --name-only "$base_sha" "$head_sha" -- crates/ credential/ benches/ \
25-
| cut -d'/' -f2 \
26-
| sort -u
27-
)
28-
29-
if [ -z "$changed_crates" ]
30-
then
31-
echo "No file changed in member crates."
32-
exit 0
33-
fi
34-
35-
# Checks publish status for only crates with code changes.
36-
publish_status_table=$(
37-
echo "$changed_crates" \
38-
| xargs printf -- '--package %s\n' \
39-
| xargs cargo unpublished
40-
)
41-
42-
# "yes" -> code changed but no version difference -> need a bump
43-
# Prints 2nd column (sep by space), which is the name of the crate.
44-
crates_need_bump=$(
45-
echo "$publish_status_table" \
46-
| { grep '| yes ' || true; } \
47-
| awk '{print $2}'
48-
)
49-
50-
if [ -z "$crates_need_bump" ]
51-
then
52-
echo "No version bump needed for member crates."
53-
exit 0
54-
fi
55-
56-
echo "Detected changes in these crates but no version bump found:"
57-
echo "$crates_need_bump"
58-
echo
59-
echo "Please bump at least one patch version for each corresponding Cargo.toml:"
60-
echo 'Run "cargo unpublished" to read the publish status table for details.'
61-
exit 1
22+
cargo bump-check --base-rev "$base_sha" --head-rev "$head_sha"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
[package]
2-
name = "xtask-unpublished"
2+
name = "xtask-bump-check"
33
version = "0.0.0"
44
edition.workspace = true
55
publish = false
66

77
[dependencies]
88
anyhow.workspace = true
99
cargo.workspace = true
10+
cargo-util.workspace = true
1011
clap.workspace = true
1112
env_logger.workspace = true
13+
git2.workspace = true
1214
log.workspace = true

0 commit comments

Comments
 (0)