Skip to content

Commit 09a4bd8

Browse files
authored
Feat: Trigger integration tests (#6339)
* Feat: Trigger integration tests * Make integration tests their own worflow so they can be triggered independently
1 parent df13a65 commit 09a4bd8

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Run Integration Tests
2+
3+
on:
4+
issue_comment:
5+
types: [created, edited]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
run-integration-tests:
11+
name: Run Integration Tests
12+
runs-on: ubuntu-latest
13+
if: |
14+
(github.event_name == 'issue_comment' &&
15+
contains(github.event.comment.body, '/integration-test') &&
16+
github.event.issue.pull_request) ||
17+
(github.event_name == 'pull_request' &&
18+
contains(github.event.pull_request.body, '/integration-test'))
19+
steps:
20+
- name: Print debugging info
21+
run: |
22+
cat <<EOF
23+
Github event name: ${{ github.event_name }}
24+
25+
Github event ${{ toJSON(github.event) }}
26+
27+
Github event comment body: ${{ github.event.comment.body }}
28+
29+
Github event pr body: ${{ github.event.pull_request.body }}
30+
31+
Generic Number: ${{ github.event.number }}
32+
33+
PR number: ${{ github.event.pull_request.number }}
34+
35+
Issue number: ${{ github.event.issue.number }}
36+
37+
SHA: ${{ github.sha }}
38+
39+
Head Ref ${{ github.head_ref }}
40+
41+
Ref Name: ${{ github.ref_name }}
42+
EOF
43+
- name: Acquire credentials
44+
id: app-token
45+
uses: actions/create-github-app-token@v2
46+
with:
47+
app-id: ${{ vars.INTEGRATION_TEST_CLIENT_ID }}
48+
private-key: ${{ secrets.INTEGRATION_TEST_PRIVATE_KEY }}
49+
owner: fivetran
50+
repositories: sqlglot-integration-tests
51+
52+
- name: Run integration tests
53+
id: run-remote
54+
env:
55+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
56+
run: |
57+
set -e
58+
59+
gh workflow run run-tests.yml \
60+
--repo fivetran/sqlglot-integration-tests \
61+
--ref main \
62+
-f sqlglot_ref=${{ github.sha }} \
63+
-f sqlglot_pr_number=${{ github.event.number }} \
64+
-f sqlglot_branch_name=${{ github.head_ref || github.ref_name }}
65+
66+
echo "Triggered workflow"
67+
68+
# wait a bit for the run to start
69+
sleep 10
70+
71+
# there is a bit of a race condition here. this just grabs the latest
72+
# run and hopes it's the one we just triggered.
73+
# inexplicably, the `gh workflow run` API doesnt return the run id...
74+
RUN_ID=$(gh run list \
75+
--repo fivetran/sqlglot-integration-tests \
76+
--workflow run-tests.yml \
77+
--user sqlglot-integration-tests \
78+
--limit 1 \
79+
--json databaseId \
80+
--jq '.[0].databaseId')
81+
82+
echo "Using Run ID: ${RUN_ID}"
83+
echo "remote_run_id=$RUN_ID" >> $GITHUB_OUTPUT
84+
85+
echo "Waiting for completion"
86+
gh run watch $RUN_ID \
87+
--repo fivetran/sqlglot-integration-tests \
88+
--interval 10 \
89+
--compact \
90+
--exit-status
91+
92+
- name: Fetch outputs
93+
uses: actions/download-artifact@v5
94+
with:
95+
github-token: ${{ steps.app-token.outputs.token }}
96+
repository: fivetran/sqlglot-integration-tests
97+
run-id: ${{ steps.run-remote.outputs.remote_run_id }}
98+
name: summary
99+
100+
- name: Write summary as comment
101+
uses: actions/github-script@v8
102+
# only do this when on PR branches, main builds dont have anywhere to write comments
103+
if: ${{ github.event_name == 'pull_request' }}
104+
with:
105+
script: |
106+
// summary.json is downloaded from the remote workflow in the previous step
107+
const summary = require("./summary.json")
108+
109+
github.rest.issues.createComment({
110+
issue_number: context.issue.number,
111+
owner: context.repo.owner,
112+
repo: context.repo.repo,
113+
body: summary.msg
114+
})

0 commit comments

Comments
 (0)