Skip to content

Commit 460fad7

Browse files
authored
Merge pull request #210 from dbt-labs/tb/refactor-ci-label-check
Refactoring CI label check
2 parents 1645dbc + 0861750 commit 460fad7

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- cron: '0 2 * * 0'
1010

1111
env:
12+
CI_LABEL: "ci-ok"
1213
DBT_BASE_URL: ${{ secrets.DBT_BASE_URL }}
1314
DBT_API_KEY: ${{ secrets.DBT_API_KEY }}
1415
DBT_JOB_ID: ${{ secrets.DBT_JOB_ID }}
@@ -19,11 +20,30 @@ env:
1920
permissions: write-all
2021

2122
jobs:
23+
check-run-approval:
24+
# Gate fork PRs behind the CI_LABEL
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: "Strip label on synchronize/reopen for labeled fork PRs"
28+
if: ${{ github.event_name == 'pull_request_target' && (github.event.action == 'synchronize' || github.event.action == 'reopened') && github.event.pull_request.head.repo.full_name != github.repository && contains(github.event.pull_request.labels.*.name, env.CI_LABEL) }}
29+
run: |
30+
echo "Synchronizing PR, removing '${{ env.CI_LABEL }}' label"
31+
gh pr edit ${{ github.event.pull_request.number }} --remove-label ${{ env.CI_LABEL }} --repo ${{ github.repository }}
32+
msg="All pull request updates require re-approval of CI. No CI will be run."
33+
echo "::error::$msg"
34+
exit 1
35+
env:
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: "Require '${{ env.CI_LABEL }}' label on fork PRs"
39+
if: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && !contains(github.event.pull_request.labels.*.name, env.CI_LABEL) }}
40+
run: |
41+
msg="Pull request is from a public fork but does not have the '${{ env.CI_LABEL }}' label. No CI will be run."
42+
echo "::error::$msg"
43+
exit 1
44+
2245
test:
23-
if: |
24-
github.event_name == 'schedule' ||
25-
github.event.pull_request.head.repo.full_name == github.repository ||
26-
contains(github.event.pull_request.labels.*.name, 'ci-ok')
46+
needs: check-run-approval
2747
runs-on: ubuntu-latest
2848

2949
strategy:

0 commit comments

Comments
 (0)