Skip to content

Commit 57a6106

Browse files
committed
chore(ci): add bi-monthly cargo upgrade workflow
1 parent e27bad3 commit 57a6106

1 file changed

Lines changed: 147 additions & 0 deletions

File tree

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Upgrade Cargo Dependencies
2+
3+
on:
4+
schedule:
5+
# 5th and 20th at 9am Chicago time (15:00 UTC)
6+
- cron: '0 15 5,20 * *'
7+
workflow_dispatch: # Allow manual trigger
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
cargo-upgrade:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
19+
- name: Install Rust
20+
uses: dtolnay/rust-toolchain@master
21+
with:
22+
toolchain: "1.88"
23+
24+
- name: Install cargo-edit
25+
run: cargo install cargo-edit --locked
26+
27+
- name: Install cargo-audit
28+
run: cargo install cargo-audit --locked
29+
30+
- name: Install just
31+
uses: extractions/setup-just@v3
32+
33+
- name: Run cargo upgrade, test, and audit
34+
id: upgrade
35+
run: |
36+
set +e
37+
38+
updates_dir="${RUNNER_TEMP}"
39+
upgrade_output_path="${updates_dir}/cargo-upgrade-output.txt"
40+
upgrade_output_plain_path="${updates_dir}/cargo-upgrade-output-plain.txt"
41+
test_output_path="${updates_dir}/cargo-test-output.txt"
42+
test_output_plain_path="${updates_dir}/cargo-test-output-plain.txt"
43+
audit_output_path="${updates_dir}/cargo-audit-output.txt"
44+
audit_output_plain_path="${updates_dir}/cargo-audit-output-plain.txt"
45+
46+
cargo upgrade --workspace --incompatible 2>&1 | tee "${upgrade_output_path}"
47+
sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g' "${upgrade_output_path}" > "${upgrade_output_plain_path}"
48+
49+
if git diff --quiet; then
50+
echo "updates_available=false" >> $GITHUB_OUTPUT
51+
exit 0
52+
fi
53+
54+
echo "updates_available=true" >> $GITHUB_OUTPUT
55+
56+
just test-all-slow 2>&1 | tee "${test_output_path}"
57+
test_exit=$?
58+
sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g' "${test_output_path}" > "${test_output_plain_path}"
59+
60+
cargo audit 2>&1 | tee "${audit_output_path}"
61+
audit_exit=$?
62+
sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g' "${audit_output_path}" > "${audit_output_plain_path}"
63+
64+
echo "test_exit=${test_exit}" >> $GITHUB_OUTPUT
65+
echo "audit_exit=${audit_exit}" >> $GITHUB_OUTPUT
66+
echo "upgrade_output_plain_path=${upgrade_output_plain_path}" >> $GITHUB_OUTPUT
67+
echo "test_output_plain_path=${test_output_plain_path}" >> $GITHUB_OUTPUT
68+
echo "audit_output_plain_path=${audit_output_plain_path}" >> $GITHUB_OUTPUT
69+
exit 0
70+
71+
- name: Prepare PR body
72+
if: steps.upgrade.outputs.updates_available == 'true'
73+
id: pr
74+
run: |
75+
body_path="${RUNNER_TEMP}/cargo-upgrade.md"
76+
cat > "${body_path}" << 'HEADER'
77+
## Cargo dependency upgrades
78+
79+
This PR was automatically generated by the weekly cargo upgrade workflow.
80+
81+
### Changes
82+
HEADER
83+
echo '```diff' >> "${body_path}"
84+
git diff >> "${body_path}"
85+
echo '```' >> "${body_path}"
86+
cat >> "${body_path}" << EOF
87+
88+
### Cargo Upgrade Output
89+
90+
\`\`\`
91+
$(cat "${{ steps.upgrade.outputs.upgrade_output_plain_path }}")
92+
\`\`\`
93+
EOF
94+
test_status="passed"
95+
audit_status="passed"
96+
if [ "${{ steps.upgrade.outputs.test_exit }}" != "0" ]; then
97+
test_status="failed"
98+
fi
99+
if [ "${{ steps.upgrade.outputs.audit_exit }}" != "0" ]; then
100+
audit_status="failed"
101+
fi
102+
103+
cat >> "${body_path}" << EOF
104+
105+
### Test Result
106+
107+
Status: **${test_status}**
108+
109+
\`\`\`
110+
$(cat "${{ steps.upgrade.outputs.test_output_plain_path }}")
111+
\`\`\`
112+
113+
### Audit Result
114+
115+
Status: **${audit_status}**
116+
117+
\`\`\`
118+
$(cat "${{ steps.upgrade.outputs.audit_output_plain_path }}")
119+
\`\`\`
120+
EOF
121+
cat >> "${body_path}" << 'FOOTER'
122+
123+
### Testing
124+
125+
- [ ] CI passed
126+
127+
---
128+
*Generated by [cargo-upgrades workflow](https://github.com/${{ github.repository }}/actions/workflows/cargo-upgrades.yml)*
129+
FOOTER
130+
echo "body_path=${body_path}" >> $GITHUB_OUTPUT
131+
132+
- name: Create Pull Request
133+
if: steps.upgrade.outputs.updates_available == 'true'
134+
uses: peter-evans/create-pull-request@v8
135+
with:
136+
token: ${{ secrets.GITHUB_TOKEN }}
137+
title: "chore(deps): cargo upgrade"
138+
body-path: ${{ steps.pr.outputs.body_path }}
139+
branch: cargo-dependency-upgrades
140+
commit-message: "chore(deps): cargo upgrade"
141+
labels: dependencies,security
142+
delete-branch: true
143+
add-paths: |
144+
Cargo.lock
145+
Cargo.toml
146+
packages/core/Cargo.toml
147+
packages/cli-rust/Cargo.toml

0 commit comments

Comments
 (0)