-
-
Notifications
You must be signed in to change notification settings - Fork 12
74 lines (65 loc) · 2.14 KB
/
format-tidy.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
name: Format & Tidy go.mod
on:
pull_request:
paths:
- '**.go'
- '**.mod'
- 'Makefile'
- '.github/workflows/format-tidy.yml'
branches:
- 'main'
jobs:
cleanup-runs:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.owner.login == github.repository_owner
steps:
- uses: rokroskar/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
format:
name: format
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.owner.login == github.repository_owner
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Format code
run:
make format
- name: Tidy go.mod
run:
make tidy
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v16
id: verify-changed-files
with:
files: |
**/*.go
*.mod
*.sum
- name: Commit formatting changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add cmd ${{ steps.verify-changed-files.outputs.changed_files }}
git commit -m "Formatted code."
- name: Push formatting changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT_TOKEN }}
branch: ${{ github.head_ref }}