2019-12-12 11:31:35 +08:00
|
|
|
name: gofmt
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
pull_request:
|
2020-03-03 05:21:19 +08:00
|
|
|
paths:
|
|
|
|
- '.github/workflows/gofmt.yml'
|
|
|
|
- '**.go'
|
2019-12-12 11:31:35 +08:00
|
|
|
jobs:
|
|
|
|
|
|
|
|
gofmt:
|
|
|
|
name: Run gofmt
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
|
2023-05-04 23:35:03 +08:00
|
|
|
- name: Set up Go 1.20
|
2021-10-22 05:24:11 +08:00
|
|
|
uses: actions/setup-go@v2
|
2019-12-12 11:31:35 +08:00
|
|
|
with:
|
2023-05-04 23:35:03 +08:00
|
|
|
go-version: "1.20"
|
2019-12-12 11:31:35 +08:00
|
|
|
id: go
|
|
|
|
|
|
|
|
- name: Check out code into the Go module directory
|
2021-10-22 05:24:11 +08:00
|
|
|
uses: actions/checkout@v2
|
2019-12-12 11:31:35 +08:00
|
|
|
|
2021-10-22 05:24:11 +08:00
|
|
|
- uses: actions/cache@v2
|
2020-07-01 06:53:30 +08:00
|
|
|
with:
|
|
|
|
path: ~/go/pkg/mod
|
2023-05-04 23:35:03 +08:00
|
|
|
key: ${{ runner.os }}-gofmt1.20-${{ hashFiles('**/go.sum') }}
|
2020-07-01 06:53:30 +08:00
|
|
|
restore-keys: |
|
2023-05-04 23:35:03 +08:00
|
|
|
${{ runner.os }}-gofmt1.20-
|
2020-07-01 06:53:30 +08:00
|
|
|
|
|
|
|
- name: Install goimports
|
|
|
|
run: |
|
2023-05-04 23:35:03 +08:00
|
|
|
go install golang.org/x/tools/cmd/goimports@latest
|
2020-07-01 06:53:30 +08:00
|
|
|
|
2019-12-12 11:31:35 +08:00
|
|
|
- name: gofmt
|
|
|
|
run: |
|
2023-05-04 23:35:03 +08:00
|
|
|
if [ "$(find . -iname '*.go' | grep -v '\.pb\.go$' | xargs goimports -l)" ]
|
2019-12-12 11:31:35 +08:00
|
|
|
then
|
2023-05-04 23:35:03 +08:00
|
|
|
find . -iname '*.go' | grep -v '\.pb\.go$' | xargs goimports -d
|
2019-12-12 11:31:35 +08:00
|
|
|
exit 1
|
|
|
|
fi
|