Skip to content

Commit 5a0e91b

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

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ 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+
if: github.event_name == 'pull_request'
49+
env:
50+
GH_TOKEN: ${{ github.token }}
51+
PULL_REQUEST_URL : ${{ github.event.pull_request.html_url }}
52+
steps:
53+
- uses: actions/checkout@v3
54+
- run: rustup update stable && rustup default stable
55+
- run: ci/validate-version-bump.sh
56+
4657
# Ensure Cargo.lock is up-to-date
4758
lockfile:
4859
runs-on: ubuntu-latest
@@ -213,6 +224,7 @@ jobs:
213224
name: bors build finished
214225
needs:
215226
- build_std
227+
- check-version-bump
216228
- docs
217229
- lockfile
218230
- resolver
@@ -229,6 +241,7 @@ jobs:
229241
name: bors build finished
230242
needs:
231243
- build_std
244+
- check-version-bump
232245
- docs
233246
- lockfile
234247
- resolver

ci/validate-version-bump.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
# PULL_REQUEST_URL A pull request url on GitHub.
10+
11+
set -euo pipefail
12+
13+
changed_crates=$(
14+
gh pr view $PULL_REQUEST_URL \
15+
--json files \
16+
-q '.files[].path | match("^(crates|credential|benches)/(.*?)/") | .captures[1].string' \
17+
| sort -u
18+
)
19+
20+
if [ -z "$changed_crates" ]
21+
then
22+
echo "No file changed in sub crates."
23+
exit 0
24+
fi
25+
26+
output=$(echo "$changed_crates" | xargs printf -- '--package %s\n' | xargs cargo unpublished --check-version-bump)
27+
28+
29+
if [ -z "$output" ]
30+
then
31+
echo "No version bump needed for sub crates."
32+
exit 0
33+
fi
34+
35+
echo "$output"
36+
37+
exit 1

0 commit comments

Comments
 (0)