Repository navigation
337 lines (304 loc) · 15.7 KB
/
Copy pathconnector-tests-trigger.yml
File metadata and controls
337 lines (304 loc) · 15.7 KB
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
name: Connector Tests Trigger
on:
workflow_run:
workflows: ["Python Build", "Metadata Ingestion"]
types: [completed]
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
dispatch:
runs-on: ubuntu-24.04
if: |
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_repository.full_name == github.repository
permissions:
actions: read
contents: read
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.CONNECTOR_TESTS_APP_ID }}
private-key: ${{ secrets.CONNECTOR_TESTS_APP_PRIVATE_KEY }}
- name: Check BOTH workflows passed for this SHA
id: check-both
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
SHA="${{ github.event.workflow_run.head_sha }}"
REPO="${{ github.repository }}"
WB_JSON=$(gh api "/repos/${REPO}/actions/workflows/python-build-pages.yml/runs?head_sha=${SHA}&per_page=10")
WB=$(echo "$WB_JSON" | jq -r '[.workflow_runs[] | select(.conclusion == "success")][0].conclusion // empty')
WB_RUN_ID=$(echo "$WB_JSON" | jq -r '[.workflow_runs[] | select(.conclusion == "success")][0].id // empty')
MI_RUNS=$(gh api "/repos/${REPO}/actions/workflows/metadata-ingestion.yml/runs?head_sha=${SHA}&per_page=1")
MI=$(echo "$MI_RUNS" | jq -r '.workflow_runs[0].conclusion // empty')
MI_RUN_ID=$(echo "$MI_RUNS" | jq -r '.workflow_runs[0].id // empty')
echo "mi_run_id=${MI_RUN_ID}" >> "$GITHUB_OUTPUT"
echo "python_build_run_id=${WB_RUN_ID}" >> "$GITHUB_OUTPUT"
echo "Python Build: $WB (run ${WB_RUN_ID}), Metadata Ingestion: $MI"
if [ "$WB" = "success" ] && [ -n "$WB_RUN_ID" ] && [ "$MI" = "success" ]; then
echo "both_passed=true" >> "$GITHUB_OUTPUT"
else
echo "Not both passed yet (WB=$WB, MI=$MI) — other trigger will handle it. If one of the upstream job failed, then connector tests will not run for this SHA."
echo "both_passed=false" >> "$GITHUB_OUTPUT"
fi
- name: Download wheels URL artifact
if: steps.check-both.outputs.both_passed == 'true'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pypi-config
path: /tmp/pypi-config
run-id: ${{ steps.check-both.outputs.python_build_run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get Cloudflare URL
if: steps.check-both.outputs.both_passed == 'true'
id: cloudflare
run: |
SHA="${{ github.event.workflow_run.head_sha }}"
DEPLOY_URL=""
if [ -f /tmp/pypi-config/deployment-url.txt ]; then
DEPLOY_URL=$(tr -d '[:space:]' < /tmp/pypi-config/deployment-url.txt)
fi
case "$DEPLOY_URL" in
*wheels*) ;;
*)
echo "::error::pypi-config artifact for SHA ${SHA} did not contain a *.datahub-wheels.pages.dev URL (got '${DEPLOY_URL}'). Re-run the Python Build workflow."
exit 1
;;
esac
echo "url=${DEPLOY_URL}" >> "$GITHUB_OUTPUT"
echo "Cloudflare URL: ${DEPLOY_URL}"
- name: Get PR info
if: steps.check-both.outputs.both_passed == 'true'
id: pr-info
run: |
PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}"
if [ -z "$PR_NUMBER" ]; then
echo "No open PR found — skipping"
echo "has_pr=false" >> "$GITHUB_OUTPUT"
else
echo "has_pr=true" >> "$GITHUB_OUTPUT"
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "Found PR #${PR_NUMBER}"
fi
- name: Check for skip label
if: steps.check-both.outputs.both_passed == 'true' && steps.pr-info.outputs.has_pr == 'true'
id: check-skip
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APP_TOKEN: ${{ steps.app-token.outputs.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ steps.pr-info.outputs.pr_number }}
run: |
# Check if PR has the skip-connector-tests label
HAS_LABEL=$(gh api "/repos/${REPO}/pulls/${PR_NUMBER}" \
--jq '[.labels[].name] | any(. == "skip-connector-tests")' 2>/dev/null || echo "false")
if [ "$HAS_LABEL" != "true" ]; then
echo "skip=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Find who added the label via timeline API
ADDER=$(gh api --paginate "/repos/${REPO}/issues/${PR_NUMBER}/timeline" \
--jq '[.[] | select(.event == "labeled" and .label.name == "skip-connector-tests")] | last | .actor.login // empty')
if [ -z "$ADDER" ]; then
echo "::warning::skip-connector-tests label found but could not determine who added it — running tests"
echo "skip=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Check if the label adder is a member of the datahub-project org
MEMBER_STATUS=$(GH_TOKEN="$APP_TOKEN" gh api "/orgs/datahub-project/members/${ADDER}" \
--silent -i 2>&1 | head -1 | grep -o '[0-9]\{3\}' | head -1)
if [ "$MEMBER_STATUS" = "204" ]; then
echo "PR #${PR_NUMBER} has skip-connector-tests label added by ${ADDER} (org member) — skipping tests"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "::warning::skip-connector-tests label added by ${ADDER} who is not a datahub-project org member — ignoring label, running tests"
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Check if connector-relevant files changed
if: steps.check-both.outputs.both_passed == 'true' && steps.pr-info.outputs.has_pr == 'true' && steps.check-skip.outputs.skip != 'true'
id: path-check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ steps.pr-info.outputs.pr_number }}
run: |
changed_files=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}/files" \
--paginate --jq '.[].filename')
# Filter to only metadata-ingestion changes
mi_files=$(echo "$changed_files" | grep '^metadata-ingestion/' || true)
if [ -z "$mi_files" ]; then
echo "No metadata-ingestion changes — skipping connector tests"
echo "has_connector_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Strip out files that cannot affect connectors
connector_relevant_files=$(echo "$mi_files" | grep -v '^metadata-ingestion/tests/' | grep -v '\.md$' || true)
if [ -z "$connector_relevant_files" ]; then
echo "All metadata-ingestion changes are tests or docs only — skipping connector tests"
echo "has_connector_changes=false" >> "$GITHUB_OUTPUT"
else
echo "Connector-relevant changes detected:"
echo "$connector_relevant_files"
echo "has_connector_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Determine target connectors
if: >-
steps.check-both.outputs.both_passed == 'true' &&
steps.pr-info.outputs.has_pr == 'true' &&
steps.check-skip.outputs.skip != 'true' &&
steps.path-check.outputs.has_connector_changes != 'false'
id: connectors
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
MI_RUN_ID: ${{ steps.check-both.outputs.mi_run_id }}
run: |
if ! gh run download "$MI_RUN_ID" --repo "$REPO" --name "ci-decisions" --dir ci-decisions 2>/dev/null; then
echo "::warning::Could not download ci-decisions artifact — running all connector tests"
echo "connectors=" >> "$GITHUB_OUTPUT"
{
echo "### Connector Tests Decision"
echo "**Run all (fallback)** — ci-decisions artifact not found."
} >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
RUN_ALL=$(jq -r '.run_all_integration' ci-decisions/ci-decisions.json)
if [ "$RUN_ALL" = "true" ]; then
echo "run_all_integration=true — running all connector tests"
echo "connectors=" >> "$GITHUB_OUTPUT"
{
echo "### Connector Tests Decision"
echo "**Run all** — shared/non-connector files changed."
} >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
# Static mapping: datahub integration test dir name → connector-tests connector name
# Update this when acryldata/connector-tests adds or removes connectors
# TODO: Remove this mapping once both of the following are true:
# (i) ci-decisions.json surfaces the canonical connector name (not the test-dir name)
# (ii) acryldata/connector-tests organises its tests in directories using those same names
CONNECTORS=$(jq -r '.test_matrix[].connector' ci-decisions/ci-decisions.json 2>/dev/null | \
while IFS= read -r name; do
case "$name" in
athena) echo "athena" ;;
azure_data_factory) echo "azure_data_factory" ;;
bigquery_v2) echo "bigquery" ;;
fabric) echo "fabric_onelake" ;;
fivetran) echo "fivetran" ;;
looker) echo "looker" ;;
powerbi) echo "powerbi" ;;
redshift) echo "redshift" ;;
sigma) echo "sigma" ;;
snowflake) echo "snowflake" ;;
tableau) echo "tableau" ;;
unity) echo "databricks" ;;
esac
done | sort -u | paste -sd ',')
if [ -z "$CONNECTORS" ]; then
echo "No connector-tests connectors matched — skipping dispatch"
echo "connectors=" >> "$GITHUB_OUTPUT"
echo "skip=true" >> "$GITHUB_OUTPUT"
{
echo "### Connector Tests Decision"
echo "**Skipped** — changes do not affect any connector-tests connector."
} >> "$GITHUB_STEP_SUMMARY"
else
echo "Target connectors: $CONNECTORS"
echo "connectors=$CONNECTORS" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"
{
echo "### Connector Tests Decision"
echo "**Selective** — running: \`$CONNECTORS\`"
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Create skipped check run
if: >-
steps.check-both.outputs.both_passed == 'true' &&
steps.pr-info.outputs.has_pr == 'true' &&
(steps.check-skip.outputs.skip == 'true' || steps.path-check.outputs.has_connector_changes == 'false' || steps.connectors.outputs.skip == 'true')
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
if [ "${{ steps.check-skip.outputs.skip }}" = "true" ]; then
REASON="Skipped via skip-connector-tests label on the PR."
elif [ "${{ steps.connectors.outputs.skip }}" = "true" ]; then
REASON="Skipped — PR changes do not affect any connector tested by the connector-tests suite."
else
REASON="Skipped because PR changes are limited to tests or docs in metadata-ingestion."
fi
jq -nc \
--arg sha "$SHA" \
--arg completed_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--arg summary "$REASON" \
'{name: "connector-tests", head_sha: $sha, status: "completed", conclusion: "skipped", completed_at: $completed_at, output: {title: "Connector tests skipped", summary: $summary}}' \
| gh api "/repos/${REPO}/check-runs" --input -
echo "Created skipped check run — ${REASON}"
- name: Create pending check run
if: >-
steps.check-both.outputs.both_passed == 'true' &&
steps.pr-info.outputs.has_pr == 'true' &&
steps.check-skip.outputs.skip != 'true' &&
steps.path-check.outputs.has_connector_changes != 'false' &&
steps.connectors.outputs.skip != 'true'
id: check-run
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
CHECK_RUN_ID=$(jq -nc \
--arg sha "$SHA" \
--arg started_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'{name: "connector-tests", head_sha: $sha, status: "in_progress", started_at: $started_at, output: {title: "Connector tests in progress", summary: "Connector tests have been triggered and are running..."}}' \
| gh api "/repos/${REPO}/check-runs" --input - --jq '.id')
echo "check_run_id=${CHECK_RUN_ID}" >> "$GITHUB_OUTPUT"
echo "Created check run ${CHECK_RUN_ID}"
- name: Dispatch to connector-tests
if: >-
steps.check-both.outputs.both_passed == 'true' &&
steps.pr-info.outputs.has_pr == 'true' &&
steps.check-skip.outputs.skip != 'true' &&
steps.path-check.outputs.has_connector_changes != 'false' &&
steps.connectors.outputs.skip != 'true'
env:
# Fine-grained PAT scoped to acryldata/connector-tests with Contents: R/W.
# To rotate: generate a new token and update this repo secret.
GH_TOKEN: ${{ secrets.CONNECTOR_TESTS_DISPATCH_TOKEN }}
PR_NUMBER: ${{ steps.pr-info.outputs.pr_number }}
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
SOURCE_REPO: ${{ github.repository }}
WHEEL_URL: ${{ steps.cloudflare.outputs.url }}
CHECK_RUN_ID: ${{ steps.check-run.outputs.check_run_id }}
CONNECTORS: ${{ steps.connectors.outputs.connectors }}
run: |
jq -nc \
--arg event "oss-pr-connector-tests" \
--arg pr "$PR_NUMBER" \
--arg sha "$COMMIT_SHA" \
--arg repo "$SOURCE_REPO" \
--arg url "$WHEEL_URL" \
--arg check_run_id "$CHECK_RUN_ID" \
--arg connectors "$CONNECTORS" \
'{event_type: $event, client_payload: ({pr_number: $pr, sha: $sha, source_repo: $repo, wheel_url: $url, check_run_id: $check_run_id} + (if $connectors != "" then {connectors: $connectors} else {} end))}' \
| gh api "/repos/acryldata/connector-tests/dispatches" --input -
if [ -n "$CONNECTORS" ]; then
echo "Dispatched for PR #${PR_NUMBER} — connectors: ${CONNECTORS}"
else
echo "Dispatched for PR #${PR_NUMBER} — all connectors"
fi
- name: On failure — mark check run as failed
if: (failure() || cancelled()) && steps.check-run.outputs.check_run_id != ''
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
CHECK_RUN_ID: ${{ steps.check-run.outputs.check_run_id }}
REPO: ${{ github.repository }}
run: |
jq -nc \
--arg completed_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'{status: "completed", conclusion: "failure", completed_at: $completed_at, output: {title: "Failed to trigger connector tests", summary: "Infrastructure issue prevented connector tests from being dispatched."}}' \
| gh api "/repos/${REPO}/check-runs/${CHECK_RUN_ID}" -X PATCH --input -