-
Notifications
You must be signed in to change notification settings - Fork 40
45 lines (45 loc) · 1.47 KB
/
autoformat.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
name: Code Formatter
on:
pull_request:
types:
- labeled
jobs:
autoformat:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'autoformat')
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.14'
- name: Install goimports
run: go get golang.org/x/tools/cmd/goimports
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
- run: goimports -w .
- run: go mod tidy
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.FORMAT_TOKEN }}
run: |
git config user.name yoshi-automation
git config user.email [email protected]
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git add .
if [ -n "$(git status --porcelain)" ]; then
git commit --author "yoshi-automation <[email protected]>" --message "Run goimports and go mod tidy"
git push
fi
- name: Remove autoformat label
uses: actions/github-script@v2
with:
github-token: ${{secrets.FORMAT_TOKEN}}
script: |
github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'autoformat'
})