-
Notifications
You must be signed in to change notification settings - Fork 6
398 lines (398 loc) · 12.3 KB
/
ci-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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
name: Go Continuous Integration
on:
push:
branches:
- master
pull_request:
workflow_call:
jobs:
shim:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: 'npm'
- name: Install
run: |
npm i
npm run all
- name: verify no git diff
run: |
status=$(git status --porcelain)
if [ -n "$status" ]; then
echo "you need to run 'npm run all' and commit the changes"
echo "$status"
exit 1
fi
shim-e2e:
runs-on: ubuntu-latest
env:
ATLAS_ACTION_LOCAL: 0 # Disable local mode
steps:
- uses: actions/checkout@v3
- uses: ariga/setup-atlas@master
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- name: "Run Migrate Lint"
uses: ./migrate/lint
with:
dir: file://atlasaction/testdata/migrations
dev-url: sqlite://dev?mode=memory
dir-name: test-dir-sqlite
env:
GITHUB_TOKEN: ${{ github.token }}
- name: "Run Migrate Push"
uses: ./migrate/push
with:
dir: file://atlasaction/testdata/migrations
dev-url: sqlite://dev?mode=memory
dir-name: test-dir-sqlite
golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Run Go linters
uses: golangci/golangci-lint-action@v3
with:
args: --verbose --timeout=5m
skip-pkg-cache: true
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Run tests
run: go test -race ./...
migrate-test:
runs-on: ubuntu-latest
env:
ATLAS_ACTION_LOCAL: 1
steps:
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: go install ./cmd/atlas-action
env:
CGO_ENABLED: 0
- uses: ./migrate/apply
with:
dir: file://atlasaction/testdata/migrations
url: sqlite://file.db?mode=memory
- uses: ./migrate/push
id: push_action
with:
dir: file://atlasaction/testdata/migrations
dir-name: test-dir-sqlite
dev-url: sqlite://file.db?mode=memory
- name: "Verify migrate/push output"
shell: bash
run: |
# Verifies that the output we got is a URL as expected
[[ "${{ steps.push_action.outputs.url }}" =~ ^https://[a-zA-Z-]*\.atlasgo\.[a-zA-Z-]*/.*$ ]]
- id: lint_success
uses: ./migrate/lint
with:
working-directory: atlasaction/testdata
dev-url: sqlite://file.db?mode=memory
dir-name: test-dir-sqlite
env:
GITHUB_TOKEN: ${{ github.token }}
- id: lint_failure
uses: ./migrate/lint
continue-on-error: true
with:
dir: file://atlasaction/testdata/migrations_destructive
dev-url: sqlite://file.db?mode=memory
dir-name: test-dir-sqlite
env:
GITHUB_TOKEN: ${{ github.token }}
- id: check-lint-failure
if: steps.lint_failure.outcome == 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('lint did not when it was supposed to')
- name: "Verify migrate/lint output"
shell: bash
run: |
# Verifies that the output we got for lint tests are URLs as expected
[[ "${{ steps.lint_success.outputs.report-url }}" =~ ^https://[a-zA-Z-]*\.atlasgo\.[a-zA-Z-]*/.*$ ]]
[[ "${{ steps.lint_failure.outputs.report-url }}" =~ ^https://[a-zA-Z-]*\.atlasgo\.[a-zA-Z-]*/.*$ ]]
- id: test_success
uses: ./migrate/test
with:
dir: file://migrations
working-directory: atlasaction/testdata
dev-url: sqlite://file.db?mode=memory
run: "expected_success"
env:
GITHUB_TOKEN: ${{ github.token }}
- id: test_failure
uses: ./migrate/test
continue-on-error: true
with:
working-directory: atlasaction/testdata
dir: file://migrations
dev-url: sqlite://file.db?mode=memory
run: "expected_failure"
env:
GITHUB_TOKEN: ${{ github.token }}
- id: check-test-failure
if: steps.test_failure.outcome == 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('expected test to fail, but it did not')
schema-test:
runs-on: ubuntu-latest
env:
ATLAS_ACTION_LOCAL: 1
steps:
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: go install ./cmd/atlas-action
env:
CGO_ENABLED: 0
- id: test_success
uses: ./schema/test
with:
url: file://schema.hcl
working-directory: atlasaction/testdata
dev-url: sqlite://file.db?mode=memory
run: "expected_success"
env:
GITHUB_TOKEN: ${{ github.token }}
- id: test_failure
uses: ./schema/test
continue-on-error: true
with:
working-directory: atlasaction/testdata
url: file://schema.hcl
dev-url: sqlite://file.db?mode=memory
run: "expected_failure"
env:
GITHUB_TOKEN: ${{ github.token }}
- id: check-test-failure
if: steps.test_failure.outcome == 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('expected test to fail, but it did not')
migrate-down:
runs-on: ubuntu-latest
env:
ATLAS_ACTION_LOCAL: 1
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: go install ./cmd/atlas-action
env:
CGO_ENABLED: 0
- name: mock atlas
run: |
cp atlasaction/mock-atlas-down.sh $HOME/atlas
echo "$HOME" >> $GITHUB_PATH
- id: pending-approval
continue-on-error: true
uses: ./migrate/down
with:
dir: file://atlasaction/testdata/down
dev-url: sqlite://dev?mode=memory
env:
TEST_STDOUT: "{\"URL\":\"PENDING_URL\",\"Status\":\"PENDING_USER\"}"
TEST_EXIT_CODE: 1
- name: check-exit-code
if: steps.pending-approval.outcome == 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('expect to fail, but did not')
- id: pending-approval-wait
continue-on-error: true
uses: ./migrate/down
with:
dir: file://atlasaction/testdata/down
dev-url: sqlite://dev?mode=memory
wait-timeout: 5s
env:
TEST_STDOUT: "{\"URL\":\"PENDING_URL\",\"Status\":\"PENDING_USER\"}"
TEST_EXIT_CODE: 1
- name: check-exit-code-wait
if: steps.pending-approval-wait.outcome == 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('expect to fail, but did not')
- id: aborted
continue-on-error: true
uses: ./migrate/down
with:
dir: file://atlasaction/testdata/down
dev-url: sqlite://dev?mode=memory
env:
TEST_STDOUT: "{\"URL\":\"ABORTED_URL\",\"Status\":\"ABORTED\"}"
TEST_EXIT_CODE: 1
- name: check-exit-code
if: steps.aborted.outcome == 'success'
uses: actions/github-script@v3
with:
script: |
core.setFailed('expect to fail, but did not')
- id: approved
uses: ./migrate/down
with:
dir: file://atlasaction/testdata/down
dev-url: sqlite://dev?mode=memory
env:
TEST_STDOUT: "{\"Planned\":[{}],\"Reverted\":[{}],\"Status\":\"APPROVED\"}"
- id: applied
uses: ./migrate/down
with:
dir: file://atlasaction/testdata/down
dev-url: sqlite://dev?mode=memory
env:
TEST_STDOUT: "{\"Planned\":[{}],\"Reverted\":[{}],\"Status\":\"APPLIED\"}"
- name: verify output
run: |
[[ "${{ steps.pending-approval.outputs.url }}" = PENDING_URL ]]
[[ "${{ steps.pending-approval-wait.outputs.url }}" = PENDING_URL ]]
[[ "${{ steps.aborted.outputs.url }}" = ABORTED_URL ]]
[[ "${{ steps.approved.outputs.planned_count }}" = 1 ]]
[[ "${{ steps.approved.outputs.reverted_count }}" = 1 ]]
[[ "${{ steps.applied.outputs.planned_count }}" = 1 ]]
[[ "${{ steps.applied.outputs.reverted_count }}" = 1 ]]
schema-push:
runs-on: ubuntu-latest
env:
ATLAS_ACTION_LOCAL: 1
steps:
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: go install ./cmd/atlas-action
env:
CGO_ENABLED: 0
- id: sanity
uses: ./schema/push
with:
working-directory: atlasaction/testdata/schema-apply/legacy
env: test
schema-plan:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
env:
ATLAS_ACTION_LOCAL: 1
steps:
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: go install ./cmd/atlas-action
env:
CGO_ENABLED: 0
- id: sanity
uses: ./schema/plan
with:
working-directory: atlasaction/testdata/schema-apply/legacy
env: test
from: |-
env://url
env:
GITHUB_TOKEN: ${{ github.token }}
schema-plan-approve:
runs-on: ubuntu-latest
env:
ATLAS_ACTION_LOCAL: 1
if: ${{ github.event_name == 'push' }}
steps:
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: go install ./cmd/atlas-action
env:
CGO_ENABLED: 0
- id: sanity
uses: ./schema/plan/approve
with:
working-directory: atlasaction/testdata/schema-apply/legacy
env: test
from: |-
env://url
env:
GITHUB_TOKEN: ${{ github.token }}
schema-apply:
runs-on: ubuntu-latest
env:
ATLAS_ACTION_LOCAL: 1
strategy:
fail-fast: false
matrix:
test:
- directory: lint-review
- directory: on-the-fly
auto-approve: "true"
- directory: remote-repo
plan: "atlas://atlas-action/plans/20240910183610"
to: "atlas://atlas-action?tag=e2e"
- directory: local-plan
plan: "file://20240910173744.plan.hcl"
- directory: multiple-envs
plan: "file://20240910173744.plan.hcl"
- directory: legacy
atlas: 'v0.27.0'
auto-approve: "true"
steps:
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_TOKEN }}
version: ${{ matrix.test.atlas }}
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: go install ./cmd/atlas-action
env:
CGO_ENABLED: 0
- name: Apply changes
continue-on-error: true
uses: ./schema/apply
env:
GITHUB_TOKEN: ${{ github.token }}
with:
working-directory: atlasaction/testdata/schema-apply/${{ matrix.test.directory }}
env: test
plan: ${{ matrix.test.plan }}
to: ${{ matrix.test.to }}
auto-approve: ${{ matrix.test.auto-approve }}