|
| 1 | +name: Fork PR Connector Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - synchronize |
| 8 | + - reopened |
| 9 | + - ready_for_review |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + statuses: write |
| 14 | + pull-requests: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + check-fork-and-trigger-tests: |
| 18 | + name: Check Fork and Trigger Tests |
| 19 | + runs-on: ubuntu-24.04 |
| 20 | + if: github.event.pull_request.head.repo.full_name != github.repository |
| 21 | + steps: |
| 22 | + - name: Check if fork is from outside airbytehq org |
| 23 | + id: check-fork |
| 24 | + run: | |
| 25 | + FORK_REPO="${{ github.event.pull_request.head.repo.full_name }}" |
| 26 | + echo "fork-repo=$FORK_REPO" >> $GITHUB_OUTPUT |
| 27 | + |
| 28 | + if [[ "$FORK_REPO" == airbytehq/* ]]; then |
| 29 | + echo "is-external-fork=false" >> $GITHUB_OUTPUT |
| 30 | + echo "Fork is from airbytehq org, skipping" |
| 31 | + else |
| 32 | + echo "is-external-fork=true" >> $GITHUB_OUTPUT |
| 33 | + echo "Fork is external: $FORK_REPO" |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Get fork owner |
| 37 | + id: fork-owner |
| 38 | + if: steps.check-fork.outputs.is-external-fork == 'true' |
| 39 | + run: | |
| 40 | + FORK_OWNER=$(echo "${{ steps.check-fork.outputs.fork-repo }}" | cut -d'/' -f1) |
| 41 | + echo "owner=$FORK_OWNER" >> $GITHUB_OUTPUT |
| 42 | + echo "Fork owner: $FORK_OWNER" |
| 43 | +
|
| 44 | + - name: Attempt to get GitHub App token for fork |
| 45 | + id: get-app-token |
| 46 | + if: steps.check-fork.outputs.is-external-fork == 'true' |
| 47 | + continue-on-error: true |
| 48 | + uses: actions/create-github-app-token@v2 |
| 49 | + with: |
| 50 | + app-id: ${{ secrets.OCTAVIA_BOT_APP_ID }} |
| 51 | + private-key: ${{ secrets.OCTAVIA_BOT_PRIVATE_KEY }} |
| 52 | + owner: ${{ steps.fork-owner.outputs.owner }} |
| 53 | + |
| 54 | + - name: Post pending commit status |
| 55 | + if: steps.get-app-token.outcome == 'success' |
| 56 | + run: | |
| 57 | + curl -X POST \ |
| 58 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 59 | + -H "Accept: application/vnd.github+json" \ |
| 60 | + "${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }}" \ |
| 61 | + -d '{ |
| 62 | + "state": "pending", |
| 63 | + "context": "Fork Connector Tests", |
| 64 | + "description": "Running connector tests in fork with BYO secrets...", |
| 65 | + "target_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 66 | + }' |
| 67 | +
|
| 68 | + - name: Trigger connector tests in fork |
| 69 | + id: trigger-tests |
| 70 | + if: steps.get-app-token.outcome == 'success' |
| 71 | + uses: the-actions-org/workflow-dispatch@v4 |
| 72 | + with: |
| 73 | + token: ${{ steps.get-app-token.outputs.token }} |
| 74 | + repo: ${{ steps.check-fork.outputs.fork-repo }} |
| 75 | + workflow: connector-ci-checks.yml |
| 76 | + ref: ${{ github.event.pull_request.head.ref }} |
| 77 | + wait-for-completion: true |
| 78 | + wait-for-completion-timeout: 2h |
| 79 | + wait-for-completion-interval: 30s |
| 80 | + inputs: | |
| 81 | + { |
| 82 | + "repo": "${{ steps.check-fork.outputs.fork-repo }}", |
| 83 | + "gitref": "${{ github.event.pull_request.head.ref }}", |
| 84 | + "pr": "${{ github.event.pull_request.number }}" |
| 85 | + } |
| 86 | +
|
| 87 | + - name: Post success commit status |
| 88 | + if: steps.trigger-tests.outcome == 'success' && steps.trigger-tests.outputs.workflow-conclusion == 'success' |
| 89 | + run: | |
| 90 | + curl -X POST \ |
| 91 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 92 | + -H "Accept: application/vnd.github+json" \ |
| 93 | + "${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }}" \ |
| 94 | + -d '{ |
| 95 | + "state": "success", |
| 96 | + "context": "Fork Connector Tests", |
| 97 | + "description": "Connector tests passed in fork with BYO secrets", |
| 98 | + "target_url": "${{ steps.trigger-tests.outputs.workflow-url }}" |
| 99 | + }' |
| 100 | +
|
| 101 | + - name: Post failure commit status |
| 102 | + if: steps.get-app-token.outcome == 'success' && (steps.trigger-tests.outcome == 'failure' || steps.trigger-tests.outputs.workflow-conclusion != 'success') |
| 103 | + run: | |
| 104 | + curl -X POST \ |
| 105 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 106 | + -H "Accept: application/vnd.github+json" \ |
| 107 | + "${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }}" \ |
| 108 | + -d '{ |
| 109 | + "state": "failure", |
| 110 | + "context": "Fork Connector Tests", |
| 111 | + "description": "Connector tests failed in fork with BYO secrets", |
| 112 | + "target_url": "${{ steps.trigger-tests.outputs.workflow-url || format(''{0}/{1}/actions/runs/{2}'', github.server_url, github.repository, github.run_id) }}" |
| 113 | + }' |
| 114 | +
|
| 115 | + - name: Comment on PR with results |
| 116 | + if: steps.get-app-token.outcome == 'success' |
| 117 | + uses: peter-evans/create-or-update-comment@v4 |
| 118 | + with: |
| 119 | + issue-number: ${{ github.event.pull_request.number }} |
| 120 | + body: | |
| 121 | + ## Fork Connector Tests Results |
| 122 | + |
| 123 | + ${{ steps.trigger-tests.outputs.workflow-conclusion == 'success' && '✅ Tests passed' || '❌ Tests failed' }} |
| 124 | + |
| 125 | + The connector tests ran in your fork's repository context using your BYO secrets. |
| 126 | + |
| 127 | + [View test results](${{ steps.trigger-tests.outputs.workflow-url }}) |
| 128 | +
|
| 129 | + - name: Skip message for non-external forks |
| 130 | + if: steps.check-fork.outputs.is-external-fork != 'true' |
| 131 | + run: | |
| 132 | + echo "Skipping fork connector tests - PR is not from an external fork" |
| 133 | +
|
| 134 | + - name: Skip message for missing GitHub App |
| 135 | + if: steps.check-fork.outputs.is-external-fork == 'true' && steps.get-app-token.outcome != 'success' |
| 136 | + run: | |
| 137 | + echo "Skipping fork connector tests - GitHub App not installed on fork" |
| 138 | + echo "Fork owner '${{ steps.fork-owner.outputs.owner }}' needs to install the Airbyte GitHub App" |
0 commit comments