Skip to content

Commit 78730a6

Browse files
committed
ci: checks if a crate needs a version bump
1 parent b483d37 commit 78730a6

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ jobs:
4343
- run: rustup update stable && rustup default stable
4444
- run: cargo stale-label
4545

46+
check-version-bump:
47+
runs-on: ubuntu-latest
48+
env:
49+
BASE_REF : ${{ github.base_ref }}
50+
steps:
51+
- uses: actions/checkout@v3
52+
- run: rustup update stable && rustup default stable
53+
- run: ci/validate-version-bump.sh
54+
4655
# Ensure Cargo.lock is up-to-date
4756
lockfile:
4857
runs-on: ubuntu-latest
@@ -213,6 +222,7 @@ jobs:
213222
name: bors build finished
214223
needs:
215224
- build_std
225+
- check-version-bump
216226
- docs
217227
- lockfile
218228
- resolver
@@ -229,6 +239,7 @@ jobs:
229239
name: bors build finished
230240
needs:
231241
- build_std
242+
- check-version-bump
232243
- docs
233244
- lockfile
234245
- resolver

ci/validate-version-bump.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/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
7+
#
8+
# Inputs:
9+
# BASE_REF The base branch of the pull request wanting to merge into.
10+
11+
set -euo pipefail
12+
13+
# When `BASE_REF` is missing, we assume it is from bors merge commit,
14+
# so `HEAD~` should find the previous commit on master branch.
15+
rev="${BASE_REF:-"HEAD~"}"
16+
17+
changed_crates=$(
18+
git diff --name-only "$rev" -- crates/ credential/ benches/ \
19+
| cut -d'/' -f2 \
20+
| sort -u
21+
)
22+
23+
if [ -z "$changed_crates" ]
24+
then
25+
echo "No file changed in sub crates."
26+
exit 0
27+
fi
28+
29+
output=$(
30+
echo "$changed_crates" \
31+
| xargs printf -- '--package %s\n' \
32+
| xargs cargo unpublished --check-version-bump
33+
)
34+
35+
if [ -z "$output" ]
36+
then
37+
echo "No version bump needed for sub crates."
38+
exit 0
39+
fi
40+
41+
echo "$output"
42+
exit 1

0 commit comments

Comments
 (0)