-
-
Notifications
You must be signed in to change notification settings - Fork 212
89 lines (86 loc) · 2.48 KB
/
format.yml
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Check/Format PR
on:
pull_request:
branches: [ main ]
concurrency:
group: format-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
format:
name: Format PR
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
ref: ${{ github.head_ref }}
- name: Setup Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install goimports
run: |
go mod download golang.org/x/tools
go install golang.org/x/tools/cmd/goimports
- name: Format repo
run: |
./format_repo.sh
env:
BRANCH_NAME: ${{ github.head_ref }}
CHANGE_TARGET: ${{ github.base_ref }}
- name: Changes detected
id: detect-changes
run: |
changes=$(git status --porcelain)
if [ ! -z "$changes" ]; then
echo "has-changes=true" >> $GITHUB_OUTPUT
fi
- uses: EndBug/[email protected]
if: ${{ steps.detect-changes.outputs.has-changes == 'true' }}
with:
message: "[ga-format-pr] Run ./format_repo.sh to fix formatting"
add: "."
cwd: "."
verify:
needs: format
name: Verify format
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Setup Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: go.mod
id: go
- name: Check all
id: check_format
run: |
./check_repo.sh
env:
BRANCH_NAME: ${{ github.head_ref }}
CHANGE_TARGET: ${{ github.base_ref }}
alt-verify:
if: github.event.pull_request.head.repo.full_name != github.repository
name: Verify format
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: go.mod
id: go
- name: Check all
id: check_format
run: |
./check_repo.sh
code=$(echo $?)
if [ "$code" != 0 ]; then
echo "Please run ./format_repo.sh to fix this pull request's formatting"
fi
env:
BRANCH_NAME: ${{ github.head_ref }}
CHANGE_TARGET: ${{ github.base_ref }}