Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:

jobs:
build-and-test:
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.head_ref == 'trunk'
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || (github.head_ref == 'trunk' && github.event.pull_request.head.repo.full_name == github.repository && github.base_ref == 'main')
name: Build & Test
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
contract:
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.head_ref == 'trunk'
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || (github.head_ref == 'trunk' && github.event.pull_request.head.repo.full_name == github.repository && github.base_ref == 'main')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/trunk-guard.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
name: Trunk guard

# Only the `trunk` branch may merge into main. Feature branches merge into
# `trunk` (via the merge train); CI runs only on the trunk -> main PR.
# Only this repository's `trunk` branch may merge into main. Feature branches
# merge into `trunk`; CI runs only on the trunk -> main PR.
# pull_request_target loads this workflow from the base branch, so a PR cannot
# edit the guard to pass itself. It never checks out PR code.
on:
pull_request:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened, edited]

permissions: {}

jobs:
only-trunk-merges-to-main:
if: github.head_ref != 'trunk'
if: github.head_ref != 'trunk' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- run: |
echo "::error::Only the 'trunk' branch may merge into main. Retarget this PR to 'trunk'."
echo "::error::Only this repository's 'trunk' branch may merge into main. Retarget this PR to 'trunk'."
exit 1
Loading