|
1 | 1 | name: CI MTU |
2 | 2 | on: |
3 | 3 | workflow_dispatch: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + paths: |
| 7 | + - "mtu/**" |
| 8 | + - ".github/workflows/check-mtu.yml" |
| 9 | + - ".github/actions/check-vm/**" |
4 | 10 | pull_request: |
5 | 11 | branches: ["main"] |
6 | 12 |
|
|
46 | 52 | with: |
47 | 53 | name: bindings-${{ matrix.os }} |
48 | 54 | 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 |
57 | 55 |
|
58 | 56 | check-android: |
59 | 57 | name: Check Android |
|
89 | 87 | codecov-token: ${{ secrets.CODECOV_TOKEN }} |
90 | 88 | generate-bindings: true |
91 | 89 |
|
| 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