forked from go-swagger/go-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
358 lines (316 loc) · 10.4 KB
/
test.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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
name: Run CI
env:
GOCOVMODE: atomic
on:
push:
tags:
- v*
branches:
- master
pull_request:
permissions:
contents: write
pull-requests: read
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --verbose
only-new-issues: true
skip-cache: true
version: latest
build:
# description: |
# Make sure we build and run elementary operations.
# And that, at this moment, it still runs with go 1.19.
# The full test suite warrants support for the 2 latest go minor releases.
needs: [lint]
strategy:
matrix:
go: ['1.19','oldstable','stable']
os: [ubuntu-latest, macos-latest, windows-latest, macos-13]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
check-latest: true
cache: true
- name: Build binary
run: |
go install ./cmd/swagger
- name: Run validation tests
run: |
swagger validate fixtures/bugs/2493/fixture-2492.json
swagger validate fixtures/bugs/2493/fixture-2493.json
swagger validate fixtures/bugs/2493/fixture-2492.yaml
swagger validate fixtures/bugs/2493/fixture-2493.yaml
test:
# description: |
# Run unit tests on the 2 most recent go releases and 3 popular platforms.
needs: [lint]
strategy:
matrix:
go: ['oldstable','stable']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
check-latest: true
cache: true
- name: Install Tools
run: |
go install gotest.tools/gotestsum@latest
- name: Run unit tests with code coverage
run: >
gotestsum --
-p 1
-timeout=20m
-coverprofile='coverage-${{ matrix.os }}-${{ matrix.go }}.txt'
-covermode=atomic
-coverpkg=$(go list)/...
./...
- name: Publish To Codecov
uses: codecov/codecov-action@v3
with:
files: 'coverage-${{ matrix.os }}-${{ matrix.go }}.txt'
flags: 'unit-${{ matrix.go }}'
os: '${{ matrix.os }}'
fail_ci_if_error: true
verbose: true
codegen_test:
# description: |
# Exercise go-swagger from the command line, with a bunch of specs
# and several options (flatten/expand spec).
#
# The test matrix applies to linux only. OS-specific quirks should
# be covered by unit tests.
needs: [lint]
strategy:
matrix:
go: ['oldstable','stable']
os: [ubuntu-latest]
include:
- fixture: codegen-fixtures # <- complex API specs to torture the code generator
args: "-skip-models -skip-full-flatten"
- fixture: canary-fixtures # <- popular real-life API specs
args: "-skip-models -skip-full-flatten -skip-expand"
runs-on: ${{ matrix.os }}
env:
GOCOVERDIR: /tmp/cov
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
check-latest: true
cache: true
- name: Install Tools
run: |
go get gotest.tools/icmd@latest
mkdir /tmp/cov
- name: Build binary with test coverage instrumentation
run: >
./hack/build-docker.sh --github-action
-cover
-covermode=atomic
-coverpkg=$(go list)/...
- name: Run codegen tests
run: >
go test -v -timeout 30m -parallel 3
hack/codegen_nonreg_test.go
-args -fixture-file "${{ matrix.fixture }}.yaml" $${{ matrix.args }}
- name: Construct coverage reports from integration tests
run: >
go tool covdata textfmt
-i "${GOCOVERDIR}"
-o "codegen-coverage-${{ matrix.os }}-${{ matrix.go }}-${{ matrix.fixture }}.txt"
- name: Publish To Codecov
uses: codecov/codecov-action@v3
with:
files: 'codegen-coverage-${{ matrix.os }}-${{ matrix.go }}-${{ matrix.fixture }}.txt'
flags: 'codegen-${{ matrix.go }}-${{ matrix.fixture }}'
os: '${{ matrix.os }}'
fail_ci_if_error: true
verbose: true
docker_dev:
needs: [lint, build, test, codegen_test]
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
quay.io/goswagger/swagger
ghcr.io/go-swagger/go-swagger
tags: |
type=ref,event=branch
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Quay Registry
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASS }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
build-args: |
commit_hash=${{ github.sha }}
tag_name=dev
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
publish_release:
needs: [lint, build, test, codegen_test]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 'stable'
check-latest: true
cache: true
- name: Install Tools
run: |
go install github.com/aktau/github-release@latest
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
- name: Build release
run: |
set -x
rm -rf dist
mkdir -p dist/bin
mkdir -p dist/build
build_binary() {
LDFLAGS="-s -w -X github.com/$GITHUB_REPOSITORY/cmd/swagger/commands.Commit=${GITHUB_SHA}"
LDFLAGS="$LDFLAGS -X github.com/$GITHUB_REPOSITORY/cmd/swagger/commands.Version=${GITHUB_REF_NAME-dev}"
out="swagger_$1_$2"
if [[ $1 == "windows" ]]; then
out="${out}.exe"
fi
GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "./dist/bin/$out" ./cmd/swagger
}
go mod download
build_binary linux amd64
build_binary linux arm64
build_binary linux arm
build_binary linux ppc64le
build_binary darwin amd64
build_binary darwin arm64
build_binary windows amd64
build_binary windows arm64
nfpm p -p deb -t dist/build
nfpm p -p rpm -t dist/build
pushd dist/bin || exit 1
sha1sum * > sha1sum.txt
sha256sum * > sha256sum.txt
popd || exit 1
- name: Push RPM
id: push_rpm
uses: cloudsmith-io/action@master
with:
api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
command: "push"
format: "rpm"
owner: "go-swagger"
repo: "go-swagger"
distro: "fedora"
release: "any-version"
file: "dist/build/swagger-*.x86_64.rpm"
- name: Push Deb
id: push
uses: cloudsmith-io/action@master
with:
api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
command: "push"
format: "deb"
owner: "go-swagger"
repo: "go-swagger"
distro: "debian"
release: "any-version"
file: "dist/build/swagger_*_amd64.deb"
- name: Publish Binaries
uses: fnkr/github-action-ghr@v1
env:
GHR_PATH: dist/bin/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
needs: [lint, build, test, codegen_test]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
quay.io/goswagger/swagger
ghcr.io/go-swagger/go-swagger
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Quay Registry
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASS }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
build-args: |
commit_hash=${{ github.sha }}
tag_name=${{ github.ref_name }}
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}