From 20ee9f708fd1df0d729c89dffaebf4f166931d1b Mon Sep 17 00:00:00 2001 From: Zachary Deziel Date: Fri, 27 Oct 2023 15:08:47 -0700 Subject: [PATCH 1/4] Add restriction to only run for PRs with main as the target. The intent is to facilitate the integration of external forks opening PRs. --- .github/workflows/preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 6796c1c..c674eb6 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -2,6 +2,8 @@ name: Deploy PR previews on: pull_request: + branches: + - main types: - opened - reopened From 7d85fbfa31936eae516b697233099d48d846c957 Mon Sep 17 00:00:00 2001 From: Zachary Deziel Date: Fri, 27 Oct 2023 15:40:18 -0700 Subject: [PATCH 2/4] Add check to CI enforce a branch restriction on PRs from non-staging to main --- .github/workflows/ci.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da8be8c..5fb149e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,13 +11,25 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Fail if target is not staging (for PRs only) + if: github.event_name == 'pull_request' + run: | + if [[ "${{ github.event.pull_request.base.ref }}" != "main" || "${{ github.event.pull_request.head.ref }}" == "staging" ]]; then + echo "Target branch is acceptable." + else + echo "Only PRs from staging can target main." + exit 1 + fi + + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python 3.11 uses: actions/setup-python@v2 with: python-version: 3.11 - - name: run pre-commit + - name: Run pre-commit run: | python -m pip install pre-commit pre-commit run --all-files From 497765f19829390869fd030ab2e88f9d9ecc47b9 Mon Sep 17 00:00:00 2001 From: Zachary Deziel Date: Fri, 27 Oct 2023 16:28:16 -0700 Subject: [PATCH 3/4] Separated check on PR for non-staging branch to another job --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fb149e..e3663c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,19 @@ on: pull_request: jobs: + pr-target-test: + runs-on: ubuntu-latest + steps: + - name: Fail if target is not staging (for PRs only) + if: github.event_name == 'pull_request' + run: | + if [[ "${{ github.event.pull_request.base.ref }}" != "main" || "${{ github.event.pull_request.head.ref }}" == "staging" ]]; then + echo "Target branch is acceptable." + else + echo "Only PRs from staging can target main." + exit 1 + fi + tests: runs-on: ubuntu-latest steps: From fa302b13fcca6cf7e5fb52a3b9ecb1120ef8c1a2 Mon Sep 17 00:00:00 2001 From: Zachary Deziel Date: Fri, 27 Oct 2023 16:50:41 -0700 Subject: [PATCH 4/4] Remove duplicate lines --- .github/workflows/ci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3663c2..9169419 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,15 +24,6 @@ jobs: tests: runs-on: ubuntu-latest steps: - - name: Fail if target is not staging (for PRs only) - if: github.event_name == 'pull_request' - run: | - if [[ "${{ github.event.pull_request.base.ref }}" != "main" || "${{ github.event.pull_request.head.ref }}" == "staging" ]]; then - echo "Target branch is acceptable." - else - echo "Only PRs from staging can target main." - exit 1 - fi - name: Checkout code uses: actions/checkout@v2