Skip to content

Commit

Permalink
Auto merge of #12395 - weihanglo:cargo-semver-checks, r=<try>
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors committed Jul 26, 2023
2 parents c33b132 + 0beb3d8 commit aa5f096
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[alias]
build-man = "run --package xtask-build-man --"
stale-label = "run --package xtask-stale-label --"
unpublished = "run --package xtask-unpublished --"
bump-check = "run --package xtask-bump-check --"
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # make `git diff` work
fetch-depth: 0
- run: rustup update stable && rustup default stable
- name: Install cargo-semver-checks
run: |
mkdir installed-bins
curl -Lf https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.22.1/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz \
| tar -xz --directory=./installed-bins
echo `pwd`/installed-bins >> $GITHUB_PATH
- run: ci/validate-version-bump.sh

test:
Expand Down
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 2 additions & 40 deletions ci/validate-version-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,5 @@ 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
cargo bump-check --baseline-rev "$base_sha" --head-rev "$head_sha"
cargo semver-checks --workspace --baseline-rev "$base_sha"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "xtask-unpublished"
name = "xtask-bump-check"
version = "0.0.0"
edition.workspace = true
publish = false
Expand All @@ -9,4 +9,5 @@ anyhow.workspace = true
cargo.workspace = true
clap.workspace = true
env_logger.workspace = true
git2.workspace = true
log.workspace = true
File renamed without changes.
Loading

0 comments on commit aa5f096

Please sign in to comment.