-
Notifications
You must be signed in to change notification settings - Fork 1.2k
205 lines (169 loc) · 7.31 KB
/
Copy pathrun-integration-tests.yml
File metadata and controls
205 lines (169 loc) · 7.31 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
name: Run Integration Tests
on:
pull_request:
types: [opened, synchronize, reopened, edited]
jobs:
should-run:
name: Check if integration tests should run
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.test-parameters.outputs.skip }}
dialects: ${{ steps.test-parameters.outputs.dialects }}
integration_tests_sha: ${{ steps.test-parameters.outputs.integration_tests_sha }}
steps:
- name: Print debugging info
run: |
cat <<'EOF'
Github event name: ${{ github.event_name }}
Github event ${{ toJSON(github.event) }}
Github event comment body: ${{ github.event.comment.body }}
Github event pr body: ${{ github.event.pull_request.body }}
Generic Number: ${{ github.event.number }}
PR number: ${{ github.event.pull_request.number }}
Issue number: ${{ github.event.issue.number }}
SHA: ${{ github.sha }}
Head Ref ${{ github.head_ref }}
Ref Name: ${{ github.ref_name }}
EOF
- name: Checkout Code
uses: actions/checkout@v5
with:
# we need to checkout all refs so we can run `git diff`
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Check if integration tests should be run
id: test-parameters
run: |
python .github/scripts/get_integration_test_params.py
# Read the submodule commit SHA so the run-integration-tests job can
# resolve the correct ref in the remote repo
SUBMODULE_SHA=$(git ls-tree HEAD sqlglot-integration-tests | awk '{print $3}')
echo "integration_tests_sha=${SUBMODULE_SHA:-}" >> $GITHUB_OUTPUT
echo "Integration tests submodule SHA: ${SUBMODULE_SHA:-not found}"
run-integration-tests:
name: Run Integration Tests
runs-on: ubuntu-latest
needs: should-run
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Acquire credentials
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.INTEGRATION_TEST_CLIENT_ID }}
private-key: ${{ secrets.INTEGRATION_TEST_PRIVATE_KEY }}
owner: fivetran
repositories: sqlglot-integration-tests
- name: Run integration tests
id: run-remote
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -e
CORRELATION_ID=$(python -c 'import uuid;print(uuid.uuid4())')
REMOTE_REPO="fivetran/sqlglot-integration-tests"
echo "Triggering remote workflow"
# Resolve the integration tests ref: use a matching branch if its tip
# matches the submodule SHA, otherwise fall back to main
INTEGRATION_REF="main"
SUBMODULE_SHA="${{ needs.should-run.outputs.integration_tests_sha }}"
BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
if [ -n "$SUBMODULE_SHA" ] && [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "main" ]; then
BRANCH_TIP=$(gh api "repos/$REMOTE_REPO/branches/$BRANCH_NAME" --jq '.commit.sha' 2>/dev/null || echo "")
if [ "$BRANCH_TIP" = "$SUBMODULE_SHA" ]; then
INTEGRATION_REF="$BRANCH_NAME"
echo "Branch '$BRANCH_NAME' tip matches submodule SHA ($SUBMODULE_SHA)"
elif [ -n "$BRANCH_TIP" ]; then
echo "Branch '$BRANCH_NAME' exists but tip ($BRANCH_TIP) doesn't match submodule SHA ($SUBMODULE_SHA), using main"
else
echo "No branch '$BRANCH_NAME' in $REMOTE_REPO, using main"
fi
fi
echo "Using integration tests ref: $INTEGRATION_REF"
gh workflow run run-tests.yml \
--repo $REMOTE_REPO \
--ref "$INTEGRATION_REF" \
-f sqlglot_ref=${{ github.sha }} \
-f sqlglot_pr_number=${{ github.event.number || github.event.issue.number }} \
-f sqlglot_branch_name=${{ github.head_ref || github.ref_name }} \
-f correlation_id="$CORRELATION_ID" \
-f dialects="${{ needs.should-run.outputs.dialects }}"
echo "Triggered workflow using correlation id: $CORRELATION_ID"
# poll for run id
RUN_ID=""
ATTEMPTS=0
while [ "$RUN_ID" == "" ]; do
sleep 5
ATTEMPTS=$((ATTEMPTS + 1))
if [ $ATTEMPTS -gt 10 ]; then
echo "Timed out waiting for matching run to start"
exit 1
fi
echo "Checking for run"
RUN_ID=$(gh run list \
--repo $REMOTE_REPO \
--event workflow_dispatch \
--workflow run-tests.yml \
--user sqlglot-integration-tests \
--json displayTitle,databaseId \
--limit 20 \
-q '.[] | select(.displayTitle | contains("Correlation ID: '"$CORRELATION_ID"'")) | .databaseId')
done
echo "Using Run ID: ${RUN_ID}"
echo "remote_run_id=$RUN_ID" >> $GITHUB_OUTPUT
echo "Waiting for completion"
gh run watch $RUN_ID \
--repo fivetran/sqlglot-integration-tests \
--interval 10 \
--compact \
--exit-status
# Fail the workflow on this side if the remote workflow fails
exit $?
- name: Fetch outputs
if: ${{ !cancelled() && steps.run-remote.outputs.remote_run_id }}
id: fetch-outputs
uses: actions/download-artifact@v5
with:
github-token: ${{ steps.app-token.outputs.token }}
repository: fivetran/sqlglot-integration-tests
run-id: ${{ steps.run-remote.outputs.remote_run_id }}
name: summary
- name: Write summary as comment
uses: actions/github-script@v8
if: ${{ !cancelled() && (github.event_name == 'pull_request' || github.event.issue.pull_request) }}
with:
script: |
// summary.json is downloaded from the remote workflow in the previous step
const summary = require("./summary.json");
// Add a unique identifier to find this comment later
const commentIdentifier = "<!-- integration-test-summary -->";
const body = `${commentIdentifier}\n${summary.msg}`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existingComment = comments.find(comment =>
comment.body.includes(commentIdentifier)
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}