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
|
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 }}
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
run-integration-tests:
name: Run Integration Tests
runs-on: ubuntu-latest
needs: should-run
if: needs.should-run.outputs.skip == 'false' && github.event.repository.fork != true
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"
gh workflow run run-tests.yml \
--repo $REMOTE_REPO \
--ref main \
-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
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
# only do this when on PR branches, main builds dont have anywhere to write comments
if: 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
});
}
|