Skip to content

Commit 01b3f1e

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

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ 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_SHA : ${{ github.event.pull_request.base.sha }}
50+
COMMIT_SHA: ${{ github.sha }}
51+
steps:
52+
- uses: actions/checkout@v3
53+
with:
54+
fetch-depth: 0 # make `git diff` work
55+
- run: rustup update stable && rustup default stable
56+
- run: ci/validate-version-bump.sh
57+
4658
# Ensure Cargo.lock is up-to-date
4759
lockfile:
4860
runs-on: ubuntu-latest
@@ -213,6 +225,7 @@ jobs:
213225
name: bors build finished
214226
needs:
215227
- build_std
228+
- check-version-bump
216229
- docs
217230
- lockfile
218231
- resolver
@@ -229,6 +242,7 @@ jobs:
229242
name: bors build finished
230243
needs:
231244
- build_std
245+
- check-version-bump
232246
- docs
233247
- lockfile
234248
- resolver

ci/validate-version-bump.sh

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

0 commit comments

Comments
 (0)