Skip to content

Commit 7d9c599

Browse files
feat(ci): Add pull_request_target workflow for fork PR connector tests with BYO secrets
- Add workflow_dispatch trigger to connector-ci-checks.yml - Create fork-connector-tests.yml workflow that: - Detects PRs from external forks - Checks for GitHub App installation on fork - Triggers connector-ci-checks.yml in fork's context - Posts commit status with test results - Replaces push-based BYO secrets trigger This enables community contributors to run connector tests with their own secrets by installing the Airbyte GitHub App on their fork. Requested by AJ Steers (@aaronsteers) Co-Authored-By: AJ Steers <[email protected]>
1 parent 05f1ed7 commit 7d9c599

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

.github/workflows/connector-ci-checks.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ on:
88
- reopened
99
- ready_for_review
1010

11+
workflow_dispatch:
12+
inputs:
13+
repo:
14+
type: string
15+
required: false
16+
description: "The repository name"
17+
gitref:
18+
type: string
19+
required: false
20+
description: "The git reference (branch or tag)"
21+
comment-id:
22+
type: string
23+
required: false
24+
description: "The ID of the comment triggering the workflow. Unused as of now."
25+
pr:
26+
type: string
27+
required: false
28+
description: "The pull request number, if applicable. Unused as of now."
29+
1130
# Available as a reusable workflow
1231
# (https://docs.github.com/en/actions/sharing-automations/reusing-workflows)
1332
workflow_call:
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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

Comments
 (0)