-
Notifications
You must be signed in to change notification settings - Fork 82
64 lines (62 loc) · 2.6 KB
/
Copy pathbuildifier.yaml
File metadata and controls
64 lines (62 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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