-
Notifications
You must be signed in to change notification settings - Fork 2
242 lines (206 loc) · 6.17 KB
/
check.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: Checks
on:
pull_request:
push:
env:
DOCKER_BUILDKIT: '1'
GO_VERSION: '1.20'
GOLANGCI_LINT_VERSION: v1.51.1
# This workflow runs for not-yet-reviewed external contributions and so it
# intentionally has no write access and only limited read access to the
# repository.
permissions:
contents: read
# Annotations
# 2 warnings
# build
# Unexpected input(s) 'cache', valid inputs are ['go-version', 'check-latest', 'stable', 'token']
jobs:
lint:
name: "lint"
runs-on: ubuntu-22.04
steps:
- name: "Fetch source code"
uses: actions/checkout@v3
- name: Install Go toolchain
uses: actions/setup-go@v3
with:
go-version: ${{env.GO_VERSION}}
check-latest: true
cache: true
- name: "go fmt check"
shell: bash
run: |
files=$(go fmt ./...)
if [ -n "$files" ]; then
echo "The following file(s) do not conform to go fmt:"
echo "$files"
exit 1
fi
- name: "go vet"
shell: bash
run: |
go vet ./...
- name: "go.mod and go.sum consistency check"
shell: bash
run: |
go mod tidy
if [[ -n "$(git status --porcelain)" ]]; then
echo >&2 "ERROR: go.mod/go.sum are not up-to-date. Run 'go mod tidy' and then commit the updated files."
exit 1
fi
- name: "Download golang-lint"
shell: bash
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin ${{ env.GOLANGCI_LINT_VERSION }}
golangci-lint version
- name: "lint"
shell: bash
run: |
golangci-lint run -v
unit-tests:
name: "Unit Tests"
runs-on: ubuntu-22.04
steps:
- name: "Fetch source code"
uses: actions/checkout@v3
- name: Install Go toolchain
uses: actions/setup-go@v3
with:
go-version: ${{env.GO_VERSION}}
check-latest: true
cache: true
- name: "Unit tests"
shell: bash
run: |
go test ./...
build-test-config-matrix:
runs-on: ubuntu-22.04
steps:
- name: "Fetch source code"
uses: actions/checkout@v3
- id: set-matrix
shell: bash
run: |
cd test-configs
v=""
for f in config.*.hcl; do
if [[ -n "$v" ]]; then
v="${v}, \"${f}\""
else
v="\"${f}\""
fi
done
echo "$v"
echo "config_file_matrix=[$v]" >> $GITHUB_OUTPUT
outputs:
config_file_matrix: ${{ steps.set-matrix.outputs.config_file_matrix }}
build:
runs-on: ubuntu-22.04
steps:
- name: "Fetch source code"
uses: actions/checkout@v3
- name: Install Go toolchain
uses: actions/setup-go@v3
with:
go-version: ${{env.GO_VERSION}}
check-latest: true
cache: true
- name: compile binary
shell: bash
run: |
make
mv $(which devconsul) /usr/local/bin
mv ./bin/clustertool /usr/local/bin
devconsul help
clustertool catalog-sync -h
- name: upload devconsul binary
uses: actions/upload-artifact@v3
with:
name: devconsul
path: /usr/local/bin/devconsul
if-no-files-found: error
- name: upload clustertool binary
uses: actions/upload-artifact@v3
with:
name: clustertool
path: /usr/local/bin/clustertool
if-no-files-found: error
get-consul-binary:
runs-on: ubuntu-22.04
steps:
- name: fetch consul
shell: bash
run: |
docker pull hashicorp/consul:latest
docker tag hashicorp/consul:latest consul-dev:latest
docker rm -f consul-extract || true
docker create --name consul-extract consul-dev:latest
docker cp consul-extract:/bin/consul "/usr/local/bin/consul"
docker rm -f consul-extract || true
- name: upload binary
uses: actions/upload-artifact@v3
with:
name: consul
path: /usr/local/bin/consul
if-no-files-found: error
configuration-tests:
name: "Config File Tests"
runs-on: ubuntu-22.04
needs: [ build, get-consul-binary, build-test-config-matrix ]
strategy:
fail-fast: false
matrix:
config_file: ${{ fromJson(needs.build-test-config-matrix.outputs.config_file_matrix) }}
steps:
- name: "Fetch source code"
uses: actions/checkout@v3
- name: download devconsul binary
uses: actions/download-artifact@v3
with:
name: devconsul
path: /usr/local/bin/
- name: download clustertool binary
uses: actions/download-artifact@v3
with:
name: clustertool
path: ./bin/
- name: download consul binary
uses: actions/download-artifact@v3
with:
name: consul
path: /usr/local/bin/
- name: fix permissions
shell: bash
run: |
chmod 755 /usr/local/bin/devconsul /usr/local/bin/consul ./bin/clustertool
consul version
devconsul help
./bin/clustertool catalog-sync -h
- name: test container
timeout-minutes: 10
shell: bash
run: |
docker pull consul:latest
docker tag consul:latest consul-dev:latest
./test-configs/test.sh "${{matrix.config_file}}"
- name: capture failed container logs
if: failure()
shell: bash
run: |
cd test-configs
devconsul dump-logs || true
cp -a cache cache-output
devconsul down &>/dev/null || true
- uses: actions/upload-artifact@v3
if: failure()
with:
name: "docker-logs-${{matrix.config_file}}"
path: ./test-configs/logs
if-no-files-found: ignore
- uses: actions/upload-artifact@v3
if: failure()
with:
name: "run-cache-${{matrix.config_file}}"
path: ./test-configs/cache-output
if-no-files-found: ignore