Skip to content

Commit 83c307b

Browse files
committed
Add job to automatically update dependencies
This adds a job to automatically update cargo dependencies once a month. I've added this script instead of using Renovate because I couldn't get Renovate to update versions in `Cargo.toml`. I also wanted to batch transitive dependency updates all in one PR.
1 parent aa96e11 commit 83c307b

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Update dependencies
2+
on:
3+
schedule:
4+
- cron: '0 0 1 * *'
5+
workflow_dispatch:
6+
7+
jobs:
8+
update:
9+
name: Update dependencies
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v5
13+
- name: Install Rust
14+
run: bash ci/install-rust.sh stable x86_64-unknown-linux-gnu
15+
- name: Install cargo-edit
16+
run: cargo install cargo-edit --locked
17+
- name: Update dependencies
18+
run: ci/update-dependencies.sh
19+
env:
20+
GH_TOKEN: ${{ github.token }}

ci/update-dependencies.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# Updates all compatible Cargo dependencies.
3+
#
4+
# I wasn't able to get Renovate to update compatible dependencies in a way
5+
# that I like, so this script takes care of it. This uses `cargo upgrade` to
6+
# ensure that `Cargo.toml` also gets updated. This also makes sure that all
7+
# transitive dependencies are updated.
8+
9+
set -ex
10+
11+
git fetch origin update-dependencies
12+
if git checkout update-dependencies
13+
then
14+
git reset --hard origin/master
15+
else
16+
git checkout -b update-dependencies
17+
fi
18+
19+
cat > commit-message << 'EOF'
20+
Update cargo dependencies
21+
22+
```
23+
EOF
24+
cargo upgrade >> commit-message
25+
echo '```' >> commit-message
26+
if git diff --quiet
27+
then
28+
echo "No changes detected, exiting."
29+
exit 0
30+
fi
31+
# Also update any transitive dependencies.
32+
cargo update
33+
34+
git config user.name "github-actions[bot]"
35+
git config user.email "github-actions[bot]@users.noreply.github.com"
36+
37+
git add Cargo.toml Cargo.lock
38+
git commit -F commit-message
39+
40+
git push --force origin update-dependencies
41+
42+
gh pr create --fill \
43+
--head update-dependencies \
44+
--base master

triagebot.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# Allows @rustbot ready, review, author, or blocked
55
[shortcut]
66

7+
# Closes/reopens PRs created by the GitHub Actions bot so that checks will run.
8+
[bot-pull-requests]
9+
710
[relabel]
811
allow-unauthenticated = [
912
# For Issue areas

0 commit comments

Comments
 (0)