This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
334 lines (295 loc) · 10.4 KB
/
test_integration_cli.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
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
name: CLI integration tests
on:
pull_request:
types: [assigned, opened, synchronize, reopened]
paths:
- "projects/adapter/**"
- ".github/actions/setup-local-fal/**"
- ".github/workflows/test_integration_cli.yml"
push:
branches: [main]
paths:
- "projects/adapter/**"
schedule:
# every monday
- cron: "0 0 * * 1"
workflow_dispatch:
inputs:
adapter:
description: dbt Adapter to test with
required: false
default: "<ALL>"
type: choice
options:
- "<ALL>"
- postgres
- bigquery
- snowflake
- redshift
- duckdb
- athena
- fal
python:
description: Python version to test with
required: false
default: "3.8"
type: choice
options:
- "<ALL>"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
dbt:
description: dbt version to test with
required: false
default: "latest"
type: choice
options:
- "<ALL>"
- "latest"
- "1.5.*"
jobs:
matrix-adapter:
runs-on: ubuntu-latest
outputs:
list: ${{ steps.matrix-step.outputs.list }}
steps:
- id: matrix-step
shell: python
run: |
OPTIONS = [
'postgres',
'bigquery',
'snowflake',
'fal'
]
EXTRA_OPTIONS = [
'redshift',
'duckdb',
'athena',
]
OUTPUT = OPTIONS
if '${{ github.event_name }}' == 'pull_request':
import re
PR_TITLE = '${{ github.event.pull_request.title }}'.lower()
PR_BRANCH = '${{ github.head_ref }}'.lower()
PR_DESCRIPTION = '''${{ github.event.pull_request.body }}'''.lower()
PR_DESCRIPTION = re.sub("<!--.*?-->", "", PR_DESCRIPTION, flags=re.DOTALL)
# Only test adapters mentioned in the pull request title or branch.
# We always test postgres and fal adapter as a sanity check.
OUTPUT = [
a for a in OPTIONS + EXTRA_OPTIONS
if a == 'postgres' or a == 'fal' or
a in PR_TITLE or
a in PR_BRANCH or
a in PR_DESCRIPTION
]
elif '${{ github.event_name }}' == 'push':
OUTPUT = ['postgres']
elif '${{ github.event_name }}' == 'workflow_dispatch':
INPUT_CHOICE = '${{ github.event.inputs.adapter }}'
if INPUT_CHOICE == '<ALL>':
OUTPUT = OPTIONS + EXTRA_OPTIONS
else:
OUTPUT = [INPUT_CHOICE]
import json
print("::set-output name=list::" + json.dumps(OUTPUT))
matrix-python:
runs-on: ubuntu-latest
outputs:
list: ${{ steps.matrix-step.outputs.list }}
steps:
- id: matrix-step
shell: python
run: |
OPTIONS = [
"3.8",
"3.9",
"3.10",
"3.11",
]
OUTPUT = ["3.8"]
if '${{ github.event_name }}' == 'pull_request':
import re
PR_TITLE = '${{ github.event.pull_request.title }}'.lower()
PR_BRANCH = '${{ github.head_ref }}'.lower()
PR_DESCRIPTION = '''${{ github.event.pull_request.body }}'''.lower()
PR_DESCRIPTION = re.sub("<!--.*?-->", "", PR_DESCRIPTION, flags=re.DOTALL)
# Test version mentioned in the pull request title or branch.
OUTPUT = [
v for v in OPTIONS
if v in PR_TITLE or
v in PR_BRANCH or
v in PR_DESCRIPTION
]
if not OUTPUT:
# If none were found in PR info
OUTPUT=["3.8"]
elif '${{ github.event_name }}' in ('schedule', 'push'):
OUTPUT=OPTIONS
elif '${{ github.event_name }}' == 'workflow_dispatch':
INPUT_CHOICE = '${{ github.event.inputs.python }}'
if INPUT_CHOICE == '<ALL>':
OUTPUT = OPTIONS
else:
OUTPUT = [INPUT_CHOICE]
import json
print("::set-output name=list::" + json.dumps(OUTPUT))
matrix-dbt:
runs-on: ubuntu-latest
outputs:
list: ${{ steps.matrix-step.outputs.list }}
steps:
- id: matrix-step
shell: python
run: |
OPTIONS = [
"1.5.*",
]
OUTPUT = OPTIONS
if '${{ github.event_name }}' == 'workflow_dispatch':
INPUT_CHOICE = '${{ github.event.inputs.dbt }}'
if INPUT_CHOICE == '<ALL>':
OUTPUT = OPTIONS + EXTRA_OPTIONS
else:
OUTPUT = [INPUT_CHOICE]
import json
print("::set-output name=list::" + json.dumps(OUTPUT))
run:
needs:
- matrix-adapter
- matrix-dbt
- matrix-python
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
profile: ${{ fromJSON(needs.matrix-adapter.outputs.list) }}
dbt: ${{ fromJSON(needs.matrix-dbt.outputs.list) }}
python: ${{ fromJSON(needs.matrix-python.outputs.list) }}
# Run only the latest commit pushed to PR
concurrency:
group: "${{ github.head_ref || github.run_id }}-${{ github.workflow }}-${{ matrix.profile }}-${{ matrix.dbt }}-${{ matrix.python }}"
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- name: Setup local fal
uses: ./.github/actions/setup-local-fal
with:
python: ${{ matrix.python }}
dbt: ${{ matrix.dbt }}
adapter: ${{ matrix.profile }}
- name: Start Docker database
working-directory: projects/adapter/cli_tests
# TODO: make redshift use a real connection
if: contains(fromJSON('["redshift", "postgres", "fal"]'), matrix.profile)
run: docker-compose up -d
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
# TODO: make redshift use a real connection
if: contains(fromJSON('["redshift", "athena"]'), matrix.profile)
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Install conda
uses: s-weigand/setup-conda@v1
with:
activate-conda: false
python-version: ${{ matrix.python }}
# PyJokes is available on conda-forge
conda-channels: anaconda, conda-forge
- name: Setup behave
working-directory: projects/adapter/cli_tests
run: pip install behave ipython
- name: Run tests
id: test_run
working-directory: projects/adapter/cli_tests
env:
FAL_STATS_ENABLED: false
# BigQuery
KEYFILE: ${{ secrets.GCP_SA_KEY }}
GCLOUD_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
BQ_DATASET: ${{ secrets.BQ_DATASET }}
# Redshift
# TODO: change to {{ secrets.* }} when testing with real Redshift
RS_DB_NAME: test
RS_SCHEMA: dbt_fal
RS_HOST: localhost
RS_PASSWORD: pass
RS_PORT: 5432
RS_USER: pguser
# Snowflake
SF_ACCOUNT: ${{ secrets.SF_ACCOUNT }}
SF_USER: ${{ secrets.SF_USER }}
SF_PASSWORD: ${{ secrets.SF_PASSWORD }}
SF_ROLE: ${{ secrets.SF_ROLE }}
SF_DATABASE: ${{ secrets.SF_DATABASE }}
SF_WAREHOUSE: ${{ secrets.SF_WAREHOUSE }}
SF_SCHEMA: ${{ secrets.SF_SCHEMA }}
# Duckdb
DB_PATH: ${{ github.workspace }}/duck.db
# Athena
ATHENA_S3_STAGING_DIR: ${{ secrets.ATHENA_S3_STAGING_DIR }}
ATHENA_REGION: ${{ secrets.ATHENA_REGION }}
ATHENA_WORK_GROUP: ${{ secrets.ATHENA_WORK_GROUP }}
ATHENA_PROFILE: ${{ secrets.ATHENA_PROFILE }}
ATHENA_DATABASE: ${{ secrets.ATHENA_DATABASE }}
ATHENA_SCHEMA: ${{ secrets.ATHENA_SCHEMA }}
run: |
# Database and schema setup for sources
if [[ '${{ matrix.profile }}' == "bigquery" ]]
then
export DBT_DATABASE="$GCLOUD_PROJECT" DBT_SCHEMA="$BQ_DATASET"
fi
if [[ '${{ matrix.profile }}' == "redshift" ]]
then
export DBT_DATABASE="$RS_DB_NAME" DBT_SCHEMA="$RS_SCHEMA"
fi
if [[ '${{ matrix.profile }}' == "snowflake" ]]
then
export DBT_DATABASE="$SF_DATABASE" DBT_SCHEMA="$SF_SCHEMA"
fi
if [[ '${{ matrix.profile }}' == "duckdb" ]]
then
# TODO: which to use for sources? Example:
# database: "{{ env_var('DBT_DATABASE', 'test') }}"
# schema: "{{ env_var('DBT_SCHEMA', 'dbt_fal') }}"
export DBT_DATABASE="" DBT_SCHEMA=""
fi
if [[ '${{ matrix.profile }}' == "athena" ]]
then
export DBT_DATABASE="$ATHENA_DATABASE" DBT_SCHEMA="$ATHENA_SCHEMA"
fi
if [[ '${{ matrix.profile }}' == "bigquery" ]]
then
echo $KEYFILE > $HOME/keyfile.json
ls -la $HOME/keyfile.json
export KEYFILE_DIR=$HOME
echo 'keyfile is ready'
fi
# Could not get the real job_id easily from context
UUID=$(uuidgen | head -c8)
export DB_NAMESPACE="${{ github.run_id }}_${UUID}"
BEHAVE_TAGS="--tags=-TODO-${{ matrix.profile }}"
if [[ '${{ matrix.profile }}' != 'postgres' ]] && [[ '${{ matrix.profile }}' != 'fal' ]]
then
# 'broken_profile' tests only works for postgres and postgres+fal right now
BEHAVE_TAGS="$BEHAVE_TAGS --tags=-broken_profile"
fi
behave $BEHAVE_TAGS -fplain -D profile=${{ matrix.profile }}
- name: Send custom JSON data to Slack workflow
if: false
# if: (failure() || cancelled()) && github.event_name == 'schedule'
id: slack
uses: slackapi/[email protected]
with:
# For posting a rich message using Block Kit
payload: |
{
"text": "Integration tests failed for dbt-${{ matrix.profile }}@${{ matrix.dbt }} (Python ${{ matrix.python }})\nhttps://github.com/fal-ai/fal/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK