-
Notifications
You must be signed in to change notification settings - Fork 239
111 lines (106 loc) · 3.21 KB
/
pr_push_checks_go.yaml
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
name: Go PR Checks
on:
- pull_request
concurrency:
group: pr-go-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
cache:
name: Setup cache
runs-on: ubuntu-latest
outputs:
go-changes: ${{ steps.changed-files.outputs.any_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed go files
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: |
*.go
*.mod
*.sum
**/*.go
**/*.mod
**/*.sum
- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$file was changed"
done
- name: Setup Go Cache
uses: actions/cache@v3
if: steps.changed-files.outputs.any_changed == 'true'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: porter-go-${{ hashFiles('**/go.sum') }}
restore-keys: porter-go-
- uses: actions/setup-go@v4
if: steps.changed-files.outputs.any_changed == 'true'
with:
cache: false
go-version-file: go.mod
- name: Download Go Modules
if: steps.changed-files.outputs.any_changed == 'true'
run: go mod download
testing_matrix:
name: Running Go Tests
runs-on: ${{ matrix.os }}
needs: cache
strategy:
matrix:
os: [ubuntu-latest]
folder: [cli, api, cmd, internal, provisioner]
steps:
- uses: actions/checkout@v3
- name: Setup Go Cache
uses: actions/cache/restore@v3
if: needs.cache.outputs.go-changes == 'true'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: porter-go-${{ hashFiles('**/go.sum') }}
- uses: actions/setup-go@v4
if: needs.cache.outputs.go-changes == 'true'
with:
cache: false
go-version-file: go.mod
- name: Download Go Modules
if: needs.cache.outputs.go-changes == 'true'
run: go mod download
- name: Run Go tests
if: needs.cache.outputs.go-changes == 'true'
run: go test ./${{ matrix.folder }}/...
linting:
name: Go Linter
runs-on: ubuntu-latest
needs: cache
steps:
- uses: actions/checkout@v3
- name: Setup Go Cache
uses: actions/cache/restore@v3
if: needs.cache.outputs.go-changes == 'true'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: porter-go-${{ hashFiles('**/go.sum') }}
- uses: actions/setup-go@v4
if: needs.cache.outputs.go-changes == 'true'
with:
cache: false
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
if: needs.cache.outputs.go-changes == 'true'
with:
version: latest
args: -c .github/golangci-lint.yaml --verbose
skip-pkg-cache: true
only-new-issues: true # this is needed until the following is merged: https://github.com/golangci/golangci-lint-action/issues/820