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