Skip to content

Commit d33eb04

Browse files
Improve fork safety: consolidate approval and add pull_request trigger (#919)
* Improve fork safety: consolidate approval and add pull_request trigger - Add pull_request trigger for internal PRs (non-forks) to test workflow changes immediately - Keep pull_request_target for fork PRs that need access to secrets - Move approval step to test-all-warehouses.yml (runs once instead of per-platform) - Remove per-platform approval from test-warehouse.yml to reduce spam Fixes ELE-5221 Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> * Fix: use !cancelled() and check fork-status result before running tests Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> * Remove redundant comment on test job condition Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> * Refactor: move should_skip logic inside PR event check block Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Itamar Hartstein <haritamar@gmail.com>
1 parent a24aa38 commit d33eb04

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

.github/workflows/test-all-warehouses.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Test all warehouse platforms
22
on:
3+
# For internal PRs (non-forks) - no approval needed, can test workflow changes immediately
4+
pull_request:
5+
branches: ["master"]
6+
# For fork PRs - requires approval before running (has access to secrets)
37
pull_request_target:
48
branches: ["master"]
59
# Allows you to run this workflow manually from the Actions tab
@@ -31,7 +35,52 @@ on:
3135
required: false
3236

3337
jobs:
38+
# Determine if this is a fork PR and skip if wrong trigger is used
39+
check-fork-status:
40+
runs-on: ubuntu-latest
41+
outputs:
42+
is_fork: ${{ steps.check.outputs.is_fork }}
43+
should_skip: ${{ steps.check.outputs.should_skip }}
44+
steps:
45+
- name: Check if PR is from fork
46+
id: check
47+
run: |
48+
IS_FORK="false"
49+
SHOULD_SKIP="false"
50+
51+
if [[ "${{ github.event_name }}" == "pull_request" || "${{ github.event_name }}" == "pull_request_target" ]]; then
52+
if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then
53+
IS_FORK="true"
54+
fi
55+
56+
# Skip if: pull_request from fork (should use pull_request_target) OR pull_request_target from non-fork (should use pull_request)
57+
if [[ "${{ github.event_name }}" == "pull_request" && "$IS_FORK" == "true" ]]; then
58+
SHOULD_SKIP="true"
59+
elif [[ "${{ github.event_name }}" == "pull_request_target" && "$IS_FORK" == "false" ]]; then
60+
SHOULD_SKIP="true"
61+
fi
62+
fi
63+
64+
echo "is_fork=$IS_FORK" >> $GITHUB_OUTPUT
65+
echo "should_skip=$SHOULD_SKIP" >> $GITHUB_OUTPUT
66+
67+
# Approval gate for fork PRs (only runs once for all platforms)
68+
approve-fork:
69+
runs-on: ubuntu-latest
70+
needs: [check-fork-status]
71+
if: needs.check-fork-status.outputs.should_skip != 'true' && needs.check-fork-status.outputs.is_fork == 'true'
72+
environment: elementary_test_env
73+
steps:
74+
- name: Approved
75+
run: echo "Fork PR approved for testing"
76+
3477
test:
78+
needs: [check-fork-status, approve-fork]
79+
if: |
80+
! cancelled() &&
81+
needs.check-fork-status.result == 'success' &&
82+
needs.check-fork-status.outputs.should_skip != 'true' &&
83+
(needs.check-fork-status.outputs.is_fork != 'true' || needs.approve-fork.result == 'success')
3584
strategy:
3685
fail-fast: false
3786
matrix:
@@ -66,7 +115,7 @@ jobs:
66115
warehouse-type: ${{ matrix.warehouse-type }}
67116
dbt-version: ${{ matrix.dbt-version }}
68117
elementary-ref: ${{ inputs.elementary-ref }}
69-
dbt-data-reliability-ref: ${{ inputs.dbt-data-reliability-ref || (github.event_name == 'pull_request_target' && github.event.pull_request.head.sha) || '' }}
118+
dbt-data-reliability-ref: ${{ inputs.dbt-data-reliability-ref || ((github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && github.event.pull_request.head.sha) || '' }}
70119
secrets: inherit
71120

72121
notify_failures:

.github/workflows/test-warehouse.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,8 @@ env:
5252
TESTS_DIR: ${{ github.workspace }}/dbt-data-reliability/integration_tests
5353

5454
jobs:
55-
# PRs from forks require approval
56-
check-if-requires-approval:
57-
runs-on: ubuntu-latest
58-
outputs:
59-
requires_approval: ${{ steps.set-output.outputs.requires_approval }}
60-
steps:
61-
- name: Set requires approval output
62-
id: set-output
63-
run: |
64-
if [[ "${{ github.event_name }}" =~ ^pull_request && "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then
65-
echo "requires_approval=true" >> $GITHUB_OUTPUT
66-
else
67-
echo "requires_approval=false" >> $GITHUB_OUTPUT
68-
fi
69-
7055
test:
7156
runs-on: ubuntu-latest
72-
needs: [check-if-requires-approval]
73-
environment: ${{ (needs.check-if-requires-approval.outputs.requires_approval == 'true' && 'elementary_test_env') || '' }}
7457
concurrency:
7558
# This is what eventually defines the schema name in the data platform.
7659
group: tests_${{ inputs.warehouse-type }}_dbt_${{ inputs.dbt-version }}_${{ github.head_ref || github.ref_name }}

0 commit comments

Comments
 (0)