Buildifier #87
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Buildifier | |
| # Runs buildifier over all Starlark/BUILD files on a daily schedule and opens a | |
| # PR only if the formatter produced changes. Mirrors the ktfmt format cron: it | |
| # force-pushes a dedicated, bot-owned branch so re-runs reuse one PR instead of | |
| # accumulating stale branches, and it never touches master directly. | |
| # | |
| # Pinned to the repo's .bazelversion (no USE_BAZEL_VERSION) and run with | |
| # --lockfile_mode=off so MODULE.bazel.lock is never rewritten — that keeps the | |
| # generated PR limited to formatting-only changes. | |
| on: | |
| schedule: | |
| # 12:30 UTC daily (between the ktfmt format and coverage-badge crons). | |
| - cron: '30 12 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| buildifier: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Setup Java JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Setup Go environment | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ^1.17 | |
| id: go | |
| - name: Setup Bazelisk | |
| run: go install github.com/bazelbuild/bazelisk@latest && export PATH=$PATH:$(go env GOPATH)/bin | |
| - uses: actions/checkout@v4 | |
| - name: Run buildifier | |
| run: ~/go/bin/bazelisk run //cli/format:buildifier --enable_bzlmod=true --enable_workspace=false --lockfile_mode=off | |
| - name: Open PR if formatting changed | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ -z "$(git status --porcelain)" ]; then | |
| echo "No buildifier changes; nothing to do." | |
| exit 0 | |
| fi | |
| BRANCH="ci/buildifier-format" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git checkout -B "$BRANCH" | |
| git add -A | |
| git commit -m "ci: apply buildifier formatting" | |
| # Force-push the dedicated, bot-owned branch so re-runs reuse one PR | |
| # instead of accumulating stale branches. This never touches master. | |
| git push --force origin "$BRANCH" | |
| if gh pr view "$BRANCH" --json state --jq '.state' 2>/dev/null | grep -q OPEN; then | |
| echo "PR already open for $BRANCH; it now points at the latest formatting." | |
| else | |
| gh pr create \ | |
| --base master \ | |
| --head "$BRANCH" \ | |
| --title "ci: apply buildifier formatting" \ | |
| --body "Automated buildifier run via \`bazel run //cli/format:buildifier\`. This PR contains formatting-only changes to BUILD/Starlark files." | |
| fi |