-
Notifications
You must be signed in to change notification settings - Fork 30
250 lines (199 loc) Β· 7.4 KB
/
tests.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
243
244
245
246
247
248
249
250
name: tests
on:
push:
branches: [master, main]
paths-ignore: ['**.md']
tags-ignore: ['**']
pull_request:
paths-ignore: ['**.md']
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
gitleaks:
name: π Check for GitLeaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}
- uses: gacts/gitleaks@v1
validate-openapi:
name: π§ͺ Validate OpenAPI schemas
runs-on: ubuntu-latest
container: stoplight/spectral:5.9
steps:
- uses: actions/checkout@v4
- run: spectral lint --verbose --fail-severity warn ./api/*.y*ml # Tool page: <https://github.com/stoplightio/spectral>
build-frontend:
name: π§ͺ Lint and build the frontend
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true'}
defaults: {run: {working-directory: ./web}}
steps:
- uses: actions/checkout@v4
- uses: gacts/setup-node-with-cache@v1
with: {node-version: 19}
- run: npm ci --no-audit --prefer-offline && npm run generate
env: {NPM_CONFIG_UPDATE_NOTIFIER: false}
- run: npm run lint
- run: npm run build
- uses: actions/upload-artifact@v3
with: {path: ./web/dist, name: frontend-dist, if-no-files-found: error, retention-days: 1}
golangci-lint:
name: π§ͺ Run GolangCI-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gacts/setup-go-with-cache@v1
with: {go-version: 1.19}
- run: |
mkdir ./web/dist && touch ./web/dist/index.html # is needed for go:embed
go install "github.com/deepmap/oapi-codegen/cmd/[email protected]"
go generate ./...
- uses: golangci/golangci-lint-action@v3
with: {skip-pkg-cache: true, skip-build-cache: true}
go-test:
name: π§ͺ Run unit-tests (Go)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 2} # Fixes codecov error 'Issue detecting commit SHA'
- uses: gacts/setup-go-with-cache@v1
with: {go-version-file: go.mod}
- run: |
mkdir ./web/dist && touch ./web/dist/index.html # is needed for go:embed
go install "github.com/deepmap/oapi-codegen/cmd/[email protected]"
go generate ./...
- run: go test -race -covermode=atomic -coverprofile /tmp/coverage.txt ./...
- uses: codecov/codecov-action@v3
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: /tmp/coverage.txt
build-app:
name: ποΈ Build the app (${{ matrix.os }} / ${{ matrix.arch }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [linux, windows, darwin] # linux, freebsd, darwin, windows
arch: [amd64] # amd64, 386
needs: [validate-openapi, golangci-lint, go-test, build-frontend]
steps:
- uses: actions/checkout@v4
- uses: gacts/setup-go-with-cache@v1
with: {go-version-file: go.mod}
- uses: actions/download-artifact@v3
with: {path: web/dist, name: frontend-dist}
- run: |
go install "github.com/deepmap/oapi-codegen/cmd/[email protected]"
go generate ./...
- {uses: gacts/github-slug@v1, id: slug}
- env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0
LDFLAGS: -s -w -X gh.tarampamp.am/webhook-tester/internal/version.version=${{ steps.slug.outputs.commit-hash-short }}
run: go build -trimpath -ldflags "$LDFLAGS" -o /tmp/webhook-tester ./cmd/webhook-tester/
- name: Try to execute
if: matrix.os == 'linux'
run: /tmp/webhook-tester --version && /tmp/webhook-tester -h
- uses: actions/upload-artifact@v3
with:
name: webhook-tester-${{ matrix.os }}-${{ matrix.arch }}
path: /tmp/webhook-tester
if-no-files-found: error
retention-days: 3
build-docker-image:
name: ποΈ Build the docker image
runs-on: ubuntu-latest
#needs: [validate-openapi, golangci-lint, go-test, build-frontend] # speed up tests pipeline
steps:
- uses: actions/checkout@v4
- {uses: gacts/github-slug@v1, id: slug}
- uses: docker/build-push-action@v5
with:
context: .
push: false
build-args: "APP_VERSION=${{ steps.slug.outputs.commit-hash-short }}"
tags: app:local
- run: docker run --rm app:local --version
- run: docker save app:local > ./docker-image.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with: {path: ./docker-image.tar, name: docker-image, retention-days: 1}
scan-docker-image:
name: π Scan the docker image
runs-on: ubuntu-latest
needs: [build-docker-image]
steps:
- uses: actions/checkout@v4 # is needed for `upload-sarif` action
- uses: actions/download-artifact@v3
with: {name: docker-image}
- uses: aquasecurity/[email protected]
with:
input: docker-image.tar
format: sarif
severity: MEDIUM,HIGH,CRITICAL
exit-code: 1
output: trivy-results.sarif
- uses: github/codeql-action/upload-sarif@v2
if: always()
continue-on-error: true
with: {sarif_file: trivy-results.sarif}
e2e-test-app:
name: π§ͺ End-to-End tests (${{ matrix.storage-driver }} storage, ${{ matrix.pubsub-driver }} pubsub)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
storage-driver: [memory, redis]
pubsub-driver: [memory, redis]
services:
redis:
image: redis:7-alpine
ports: ['6379:6379/tcp']
options: --health-cmd "redis-cli ping" --health-interval 3s --health-timeout 2s --health-retries 3
needs: [build-app]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with: {name: webhook-tester-linux-amd64}
- run: |
chmod +x ./webhook-tester
./webhook-tester serve --port 8081 \
--storage-driver "${{ matrix.storage-driver }}" \
--pubsub-driver "${{ matrix.pubsub-driver }}" \
--redis-dsn "redis://127.0.0.1:6379/0" &
- uses: gacts/install-hurl@v1
- run: hurl --color --test --fail-at-end --variable host=127.0.0.1 --variable port=8081 ./test/hurl/*/*.hurl
e2e-docker-image:
name: π§ͺ Docker image End-to-End tests
runs-on: ubuntu-latest
services:
redis:
image: redis:7-alpine
ports: ['6379:6379/tcp']
options: --health-cmd "redis-cli ping" --health-interval 3s --health-timeout 2s --health-retries 3
needs: [build-docker-image]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with: {name: docker-image}
- name: Load the image with the app
run: docker load < docker-image.tar
- name: Run docker image with app
run: |
docker run --rm -d \
--network host \
--name app \
-p "8081:8081/tcp" \
-e "STORAGE_DRIVER=redis" \
-e "PUBSUB_DRIVER=redis" \
-e "REDIS_DSN=redis://127.0.0.1:6379/0" \
-e "LISTEN_PORT=8081" \
app:local
- uses: gacts/install-hurl@v1
- run: hurl --color --test --fail-at-end --variable host=127.0.0.1 --variable port=8081 ./test/hurl/*/*.hurl
- if: always()
run: docker kill app