Skip to content

Commit da05690

Browse files
committed
Make PR
1 parent 2ed43fd commit da05690

2 files changed

Lines changed: 79 additions & 22 deletions

File tree

.github/actions/check-vm/action.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,3 @@ runs:
185185
with:
186186
name: bindings-${{ inputs.platform }}
187187
path: ${{ inputs.working-directory }}/${{ inputs.platform }}.rs
188-
189-
- if: ${{ always() && inputs.generate-bindings == 'true' }}
190-
shell: bash
191-
env:
192-
WD: ${{ inputs.working-directory }}
193-
PLATFORM: ${{ inputs.platform }}
194-
run: |
195-
# Check if generated bindings differ from committed bindings
196-
if [ -f "$WD/$PLATFORM.rs" ]; then
197-
if ! diff "$WD/src/bindings/$PLATFORM.rs" "$WD/$PLATFORM.rs"; then
198-
echo "::error::Generated bindings for $PLATFORM differ from committed version. Update src/bindings/$PLATFORM.rs with the artifact contents."
199-
exit 1
200-
fi
201-
fi

.github/workflows/check-mtu.yml

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: CI MTU
22
on:
33
workflow_dispatch:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "mtu/**"
8+
- ".github/workflows/check-mtu.yml"
9+
- ".github/actions/check-vm/**"
410
pull_request:
511
branches: ["main"]
612

@@ -46,14 +52,6 @@ jobs:
4652
with:
4753
name: bindings-${{ matrix.os }}
4854
path: ${{ matrix.os }}.rs
49-
- name: Check bindings match committed
50-
env:
51-
OS: ${{ matrix.os }}
52-
run: |
53-
if ! diff "mtu/src/bindings/$OS.rs" "$OS.rs"; then
54-
echo "::error::Generated bindings for $OS differ from committed version. Update mtu/src/bindings/$OS.rs with the artifact contents."
55-
exit 1
56-
fi
5755

5856
check-android:
5957
name: Check Android
@@ -89,3 +87,76 @@ jobs:
8987
codecov-token: ${{ secrets.CODECOV_TOKEN }}
9088
generate-bindings: true
9189

90+
check-bindings:
91+
name: Check bindings
92+
needs: [generate-bindings, check-vm]
93+
if: always() && !cancelled()
94+
runs-on: ubuntu-24.04
95+
permissions:
96+
pull-requests: write # to create PRs for binding updates
97+
contents: write # to push branches for binding updates
98+
steps:
99+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
100+
with:
101+
persist-credentials: true # zizmor: ignore[artipacked] We need to push branches.
102+
103+
- name: Download all binding artifacts
104+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
105+
with:
106+
path: artifacts
107+
pattern: bindings-*
108+
109+
- name: Check for binding changes
110+
id: check
111+
run: |
112+
CHANGED=""
113+
for dir in artifacts/bindings-*; do
114+
[ -d "$dir" ] || continue
115+
PLATFORM=$(basename "$dir" | sed 's/bindings-//')
116+
FILE="$dir/$PLATFORM.rs"
117+
[ -f "$FILE" ] || continue
118+
119+
if ! diff -q "mtu/src/bindings/$PLATFORM.rs" "$FILE" > /dev/null 2>&1; then
120+
echo "Bindings for $PLATFORM differ:"
121+
diff "mtu/src/bindings/$PLATFORM.rs" "$FILE" || true
122+
cp "$FILE" "mtu/src/bindings/$PLATFORM.rs"
123+
CHANGED="$CHANGED $PLATFORM"
124+
fi
125+
done
126+
127+
if [ -z "$CHANGED" ]; then
128+
echo "No binding changes detected."
129+
echo "changed=false" >> "$GITHUB_OUTPUT"
130+
else
131+
echo "changed=true" >> "$GITHUB_OUTPUT"
132+
echo "platforms=$CHANGED" >> "$GITHUB_OUTPUT"
133+
fi
134+
135+
- name: Create PR for binding updates
136+
if: steps.check.outputs.changed == 'true' && github.event_name == 'push'
137+
env:
138+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
SHA: ${{ github.sha }}
140+
PLATFORMS: ${{ steps.check.outputs.platforms }}
141+
run: |
142+
git config --global user.name "github-actions[bot]"
143+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
144+
echo "$TOKEN" | gh auth login --with-token
145+
SHA_SHORT=$(echo "$SHA" | cut -c1-7)
146+
BRANCH="chore-update-mtu-bindings-$SHA_SHORT"
147+
MESSAGE="chore: Update MTU bindings
148+
149+
Automated update of platform-specific bindings generated by bindgen.
150+
151+
Updated platforms:$PLATFORMS"
152+
git checkout -b "$BRANCH"
153+
git add mtu/src/bindings
154+
git commit -m "$MESSAGE"
155+
git push --set-upstream origin "$BRANCH"
156+
gh pr create --fill-verbose
157+
158+
- name: Fail if bindings changed on PR
159+
if: steps.check.outputs.changed == 'true' && github.event_name == 'pull_request'
160+
run: |
161+
echo "::error::Generated bindings differ from committed versions. See job output for details."
162+
exit 1

0 commit comments

Comments
 (0)