Skip to content

Commit 916f7e3

Browse files
committed
Make sure dependabot PRs update guests cargo.lock
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 8010a70 commit 916f7e3

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# This workflow automatically updates the Cargo.lock files in guest crates when
2+
# Dependabot updates dependencies. Without this, Dependabot PRs only update the
3+
# root Cargo.lock, leaving the guest crate Cargo.lock files stale.
4+
#
5+
# See: https://docs.github.com/en/code-security/tutorials/secure-your-dependencies/automating-dependabot-with-github-actions
6+
7+
name: Update Guest Cargo.lock for Dependabot PRs
8+
9+
on:
10+
pull_request:
11+
branches: [main]
12+
paths:
13+
- 'Cargo.toml'
14+
- 'Cargo.lock'
15+
- 'src/hyperlight_*/Cargo.toml'
16+
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
21+
env:
22+
CARGO_TERM_COLOR: always
23+
24+
jobs:
25+
update-guest-locks:
26+
# Only run for Dependabot PRs - check the PR author, not the actor
27+
if: github.event.pull_request.user.login == 'dependabot[bot]'
28+
runs-on: [self-hosted, Linux, X64, "1ES.Pool=hld-kvm-amd"]
29+
timeout-minutes: 15
30+
steps:
31+
# Fetch metadata about the Dependabot PR
32+
- name: Dependabot metadata
33+
id: metadata
34+
uses: dependabot/fetch-metadata@v2
35+
with:
36+
github-token: "${{ secrets.GITHUB_TOKEN }}"
37+
38+
# Only proceed for cargo ecosystem updates
39+
- name: Check if cargo update
40+
id: check-ecosystem
41+
run: |
42+
if [ "${{ steps.metadata.outputs.package-ecosystem }}" = "cargo" ]; then
43+
echo "is_cargo=true" >> "$GITHUB_OUTPUT"
44+
else
45+
echo "is_cargo=false" >> "$GITHUB_OUTPUT"
46+
echo "Skipping non-cargo dependency update"
47+
fi
48+
49+
# Get GitHub App token for pushing commits back to the PR
50+
# Uses the same app as auto-merge-dependabot.yml
51+
- name: Get GitHub App token
52+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
53+
uses: actions/create-github-app-token@v2
54+
id: get-app-token
55+
with:
56+
app-id: ${{ secrets.DEPENDABOT_APP_ID }}
57+
private-key: ${{ secrets.DEPENDABOT_APP_KEY }}
58+
permission-contents: write
59+
60+
- name: Checkout PR branch
61+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
62+
uses: actions/checkout@v6
63+
with:
64+
token: ${{ steps.get-app-token.outputs.token }}
65+
ref: ${{ github.head_ref }}
66+
fetch-depth: 0
67+
68+
- name: Setup Rust toolchain
69+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
70+
uses: hyperlight-dev/ci-setup-workflow@v1.8.0
71+
with:
72+
rust-toolchain: "1.89"
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
76+
- name: Fix cargo home permissions
77+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
78+
run: |
79+
sudo chown -R $(id -u):$(id -g) /opt/cargo || true
80+
81+
- name: Update simpleguest Cargo.lock
82+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
83+
working-directory: src/tests/rust_guests/simpleguest
84+
run: cargo fetch
85+
86+
- name: Update dummyguest Cargo.lock
87+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
88+
working-directory: src/tests/rust_guests/dummyguest
89+
run: cargo fetch
90+
91+
- name: Update witguest Cargo.lock
92+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
93+
working-directory: src/tests/rust_guests/witguest
94+
run: cargo fetch
95+
96+
- name: Configure git for commits
97+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
98+
run: |
99+
git config user.name "github-actions[bot]"
100+
git config user.email "github-actions[bot]@users.noreply.github.com"
101+
102+
- name: Check for changes and commit
103+
if: steps.check-ecosystem.outputs.is_cargo == 'true'
104+
id: commit
105+
env:
106+
DEPENDENCY_NAMES: ${{ steps.metadata.outputs.dependency-names }}
107+
run: |
108+
# Check if there are any changes to the guest Cargo.lock files
109+
if git diff --quiet src/tests/rust_guests/*/Cargo.lock; then
110+
echo "No changes to guest Cargo.lock files"
111+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
112+
else
113+
echo "Guest Cargo.lock files have changed, committing..."
114+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
115+
116+
# Stage only the guest Cargo.lock changes
117+
git add src/tests/rust_guests/*/Cargo.lock
118+
119+
# Commit with DCO sign-off
120+
git commit --signoff -m "chore: update guest Cargo.lock files" \
121+
-m "Automatically updated by dependabot-update-guest-locks workflow." \
122+
-m "Triggered by: ${DEPENDENCY_NAMES}"
123+
fi
124+
125+
- name: Push changes
126+
if: steps.check-ecosystem.outputs.is_cargo == 'true' && steps.commit.outputs.has_changes == 'true'
127+
run: |
128+
git push origin HEAD:${{ github.head_ref }}

0 commit comments

Comments
 (0)