-
Notifications
You must be signed in to change notification settings - Fork 1.2k
49 lines (41 loc) · 1.4 KB
/
buildifier.yaml
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
name: Buildifier
on:
pull_request:
branches: ["main"]
permissions:
contents: read
jobs:
autoformat:
name: Auto-format and Check
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Check out code
uses: actions/checkout@v4
- name: Install Dependencies
run: |
go install github.com/bazelbuild/buildtools/buildifier@3.2.0
- name: Run buildifier
shell: bash
run: |
buildifier -mode=fix $(find . -name 'BUILD*' -o -name 'WORKSPACE*' -o -name '*.bzl' -type f)
- name: Verify buildifier
shell: bash
run: |
# From: https://backreference.org/2009/12/23/how-to-match-newlines-in-sed/
# This is to leverage this workaround:
# https://github.com/actions/toolkit/issues/193#issuecomment-605394935
function urlencode() {
sed ':begin;$!N;s/\n/%0A/;tbegin'
}
if [[ $(git diff-index --name-only HEAD --) ]]; then
for x in $(git diff-index --name-only HEAD --); do
echo "::error file=$x::Please run buildifier.%0A$(git diff $x | urlencode)"
done
echo "${{ github.repository }} is out of style. Please run buildifier."
exit 1
fi
echo "${{ github.repository }} is formatted correctly."