Skip to content

Commit 86b7e6a

Browse files
committed
ci: use cargo-semver-checks to detect semver violations
1 parent 7c82ff2 commit 86b7e6a

File tree

2 files changed

+10
-46
lines changed

2 files changed

+10
-46
lines changed

.github/workflows/main.yml

+7-1
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:

ci/validate-version-bump.sh

+3-45
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#!/bin/bash
2-
# This script checks if a crate needs a version bump.
3-
#
4-
# At the time of writing, it doesn't check what kind of bump is required.
5-
# In the future, we could take SemVer compatibliity into account, like
6-
# integrating `cargo-semver-checks` of else
2+
# Use `cargo-semver-checks` to detect if a crate needs a version bump due to
3+
# SemVer violation.
74
#
85
# Inputs:
96
# BASE_SHA The commit SHA of the branch where the PR wants to merge into.
@@ -19,43 +16,4 @@ head_sha=$(git rev-parse "${HEAD_SHA:-HEAD}")
1916
echo "Base branch is $base_sha"
2017
echo "Current head is $head_sha"
2118

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
19+
cargo semver-checks --workspace --baseline-rev "$base_sha"

0 commit comments

Comments
 (0)