|
| 1 | +name: Auto-generate and commit BPF files |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write # Required for creating PRs |
| 9 | + |
| 10 | +jobs: |
| 11 | + generate-and-commit: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: "Checkout repo" |
| 16 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 17 | + with: |
| 18 | + persist-credentials: false |
| 19 | + - name: "Checkout PR using GH" |
| 20 | + env: |
| 21 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + run: gh pr checkout ${{ github.event.pull_request.number }} |
| 23 | + - name: Run docker-generate |
| 24 | + run: make docker-generate |
| 25 | + |
| 26 | + - name: Add generated files |
| 27 | + run: | |
| 28 | + find . -name "*_bpfel*" -not -path "**/vendor/*" | xargs git add -f |
| 29 | +
|
| 30 | + - name: "Create/update PR" |
| 31 | + id: git-check |
| 32 | + env: |
| 33 | + GITHUB_TOKEN: ${secrets.GITHUB_TOKEN} |
| 34 | + run: | |
| 35 | + if git diff --staged --quiet; then |
| 36 | + echo "No changes to commit" |
| 37 | + echo "changes=false" >> $GITHUB_OUTPUT |
| 38 | + else |
| 39 | + echo "Changes detected" |
| 40 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: "Create/update PR" |
| 44 | + if: steps.git-check.outputs.changes == 'true' |
| 45 | + env: |
| 46 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + run: | |
| 48 | + git commit -m "Auto-generate BPF files" |
| 49 | + branch="${GITHUB_HEAD_REF}" |
| 50 | + git push --force-with-lease origin HEAD:$branch |
0 commit comments