-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (160 loc) · 4.35 KB
/
code-check-and-tests.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Code Check and Acceptance Tests
on:
pull_request:
paths:
- '.github/workflows/code-check-and-tests.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
- 'Makefile'
- '.golangci.yml'
push:
branches:
- "main"
permissions:
contents: read
jobs:
# Ensure the project can build first
build:
name: Build
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- name: Get dependencies
run: |
go mod tidy
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference after 'go mod tidy'. Run 'go mod tidy' command and commit."; exit 1)
- name: Build
run: |
make install
fmt:
name: go fmt
needs: [build]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: |
if [ "$(go fmt ./... | wc -l)" -gt 0 ]; then
echo "::error::'go fmt' found required formatting changes. Run 'make fmt' on your branch."
exit 1;
fi
vet:
name: go vet
needs: [build]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: go vet ./...
lint:
name: golangcli-lint
needs: [build]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: make golangcilint
generate:
name: go generate
needs: [build]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
# Use git add -N . to ensure that new files are listed in the git diff check
- run: |
go generate ./...
git add -N .
git diff --exit-code || \
(echo; echo "Unexpected difference after code generation. Run 'make generate' command and commit."; exit 1)
importfmt:
name: importfmt
needs: [build]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: make importfmtlint
tfproviderlint:
name: tfproviderlintx
needs: [fmt, vet, lint, generate, importfmt]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: make tfproviderlint
tflint:
name: tflint
needs: [fmt, vet, lint, generate, importfmt]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: make tflint
terrafmt:
name: terrafmt
needs: [fmt, vet, lint, generate, importfmt]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: |
find ./internal/acctest -type f -name '*_test.go' \
| sort -u \
| xargs -I {} go run github.com/katbyte/terrafmt diff -f --check --fmtcompat {} ; if [ $$? -ne 0 ]; then \
echo ""; \
echo "terrafmt found bad formatting of HCL embedded in the test scripts. Please run "; \
echo "\"make terrafmtlint\" before submitting the code for review."; \
exit 1; \
fi
acceptance:
name: Acceptance Tests
needs: [fmt, vet, lint, generate, importfmt, tfproviderlint, tflint, terrafmt]
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.5.*'
terraform_wrapper: false
- run:
make testacc
env:
TF_ACC: '1'
CONFIG: ${{ secrets.Config }}