-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (118 loc) · 3.8 KB
/
go.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Golang CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [opened, synchronize]
#defaults:
# run:
# shell: bash
# working-directory: src
jobs:
avoid_reduncy:
name: Cancel Previous Pipelines
runs-on: ubuntu-latest
steps:
- name: Cancel Workflow
uses: styfle/[email protected]
lint:
name: Lint with Go ${{ matrix.go-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
working-directory: ./src
artifact-path: ${{ github.workspace }}/src
strategy:
matrix:
os:
# - ubuntu-18.04
# - ubuntu-20.04
- ubuntu-latest
# - windows-latest
# - macos-latest
go-version:
# Latest n versions
# - 1.15
- 1.16
# - 1.17
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: Verify Go
run: go version
- name: Install dependencies
run: |
go get -v -u golang.org/x/tools/cmd/goimports
- name: Checkout code
uses: actions/checkout@v4
- name: Restore cache
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check code formats (gofmt)
id: check-gofmt
run: |
FILES=$(gofmt -l -s .)
FILES_COUNT=$(gofmt -l -s . | wc -l)
if [ "$FILES_COUNT" -gt 0 ]; then
echo -e "::warning::There are $FILES_COUNT files to be reformatted:\n\n$FILES\n\n"
gofmt -d -s -e . > ${{ env.working-directory }}/gofmt-${{ matrix.go-version }}-${{ matrix.os }}.diff
fi
echo -e "::set-output name=files::$FILES" > /dev/null
echo "::set-output name=count::$FILES_COUNT"
- name: Save gofmt artifact
# if: ${{ toJSON(job.steps.check-gofmt.outputs.count) > 0 }}
uses: actions/upload-artifact@v3
with:
name: gofmt-outputs-${{ matrix.go-version }}-${{ matrix.os }}
path: |
${{ env.artifact-path }}
!**/goimports-*.diff
if-no-files-found: warn
retention-days: 5
- name: Check code formats (goimports)
id: check-goimports
run: |
FILES=$(goimports -l .)
FILES_COUNT=$(goimports -l . | wc -l)
if [ "$FILES_COUNT" -gt 0 ]; then
echo -en "::warning::There are $FILES_COUNT files with import changes:\n\n$FILES\n\n"
goimports -d . > ${{ env.working-directory }}/goimports-${{ matrix.go-version }}-${{ matrix.os }}.diff
fi
echo -e "::set-output name=files::$FILES" > /dev/null
echo "::set-output name=count::$FILES_COUNT"
- name: Save goimports artifact
# if: ${{ toJSON(job.steps.check-goimports.outputs.count) > 0 }}
uses: actions/upload-artifact@v3
with:
name: goimports-outputs-${{ matrix.go-version }}-${{ matrix.os }}
path: |
${{ env.artifact-path }}
!**/gofmt-*.diff
if-no-files-found: warn
retention-days: 5
# - name: Fix code formats
# run: find . -name '*.go' | while read -r file; do gofmt -s -w "$$file"; goimports -w "$$file"; done
# if: startsWith(matrix.os, 'ubuntu-')
# - name: Ensure code formats
# run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
# if: startsWith(matrix.os, 'ubuntu-')
# - name: Build
# run: go build -v ./...
# - name: Test
# run: go test -v -race ./...