|
| 1 | +name: Buildifier |
| 2 | + |
| 3 | +# Runs buildifier over all Starlark/BUILD files on a daily schedule and opens a |
| 4 | +# PR only if the formatter produced changes. Mirrors the ktfmt format cron: it |
| 5 | +# force-pushes a dedicated, bot-owned branch so re-runs reuse one PR instead of |
| 6 | +# accumulating stale branches, and it never touches master directly. |
| 7 | +# |
| 8 | +# Pinned to the repo's .bazelversion (no USE_BAZEL_VERSION) and run with |
| 9 | +# --lockfile_mode=off so MODULE.bazel.lock is never rewritten — that keeps the |
| 10 | +# generated PR limited to formatting-only changes. |
| 11 | +on: |
| 12 | + schedule: |
| 13 | + # 12:30 UTC daily (between the ktfmt format and coverage-badge crons). |
| 14 | + - cron: '30 12 * * *' |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +jobs: |
| 18 | + buildifier: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + steps: |
| 24 | + - name: Setup Java JDK |
| 25 | + uses: actions/setup-java@v4 |
| 26 | + with: |
| 27 | + distribution: 'temurin' |
| 28 | + java-version: '21' |
| 29 | + - name: Setup Go environment |
| 30 | + uses: actions/setup-go@v5 |
| 31 | + with: |
| 32 | + go-version: ^1.17 |
| 33 | + id: go |
| 34 | + - name: Setup Bazelisk |
| 35 | + run: go install github.com/bazelbuild/bazelisk@latest && export PATH=$PATH:$(go env GOPATH)/bin |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + - name: Run buildifier |
| 38 | + run: ~/go/bin/bazelisk run //cli/format:buildifier --enable_bzlmod=true --enable_workspace=false --lockfile_mode=off |
| 39 | + - name: Open PR if formatting changed |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + run: | |
| 43 | + if [ -z "$(git status --porcelain)" ]; then |
| 44 | + echo "No buildifier changes; nothing to do." |
| 45 | + exit 0 |
| 46 | + fi |
| 47 | + BRANCH="ci/buildifier-format" |
| 48 | + git config user.name "github-actions[bot]" |
| 49 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 50 | + git checkout -B "$BRANCH" |
| 51 | + git add -A |
| 52 | + git commit -m "ci: apply buildifier formatting" |
| 53 | + # Force-push the dedicated, bot-owned branch so re-runs reuse one PR |
| 54 | + # instead of accumulating stale branches. This never touches master. |
| 55 | + git push --force origin "$BRANCH" |
| 56 | + if gh pr view "$BRANCH" --json state --jq '.state' 2>/dev/null | grep -q OPEN; then |
| 57 | + echo "PR already open for $BRANCH; it now points at the latest formatting." |
| 58 | + else |
| 59 | + gh pr create \ |
| 60 | + --base master \ |
| 61 | + --head "$BRANCH" \ |
| 62 | + --title "ci: apply buildifier formatting" \ |
| 63 | + --body "Automated buildifier run via \`bazel run //cli/format:buildifier\`. This PR contains formatting-only changes to BUILD/Starlark files." |
| 64 | + fi |
0 commit comments