Repository navigation
62 lines (54 loc) · 1.49 KB
/
Copy pathformat.yml
File metadata and controls
62 lines (54 loc) · 1.49 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
name: Format code
on:
push:
branches: ['main', 'dev']
pull_request:
workflow_dispatch:
permissions:
contents: write
jobs:
format:
name: Format with gofumpt
if: github.event_name != 'pull_request' && github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: Apply formatting and push changes
run: |
go install mvdan.cc/gofumpt@v0.10.0
gofumpt -w .
if [ -z "$(git status --porcelain)" ]; then
echo "No formatting changes necessary."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: format code"
git push
check:
name: Check gofumpt
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
- name: Check formatting
run: |
go install mvdan.cc/gofumpt@v0.10.0
unformatted=$(gofumpt -l .)
if [ -n "$unformatted" ]; then
echo "$unformatted"
exit 1
fi