|
1 | | -name: PR Preview Check and Trigger |
| 1 | +name: PR Preview Check |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
5 | 5 |
|
6 | 6 | jobs: |
7 | | - # For PRs from the main repo - direct call to the shared workflow |
8 | | - trigger-main-repo-preview: |
9 | | - name: Trigger Preview (Main Repo) |
10 | | - uses: ./.github/workflows/cloudflare-preview.yml |
| 7 | + # Deploy main repo PRs directly |
| 8 | + deploy-for-main: |
| 9 | + name: Trigger Preview Build and Deploy (Main Repo) |
| 10 | + runs-on: ubuntu-latest |
11 | 11 | if: github.event.pull_request.head.repo.fork == false |
12 | | - with: |
13 | | - pr_number: ${{ github.event.pull_request.number }} |
14 | | - pr_head_sha: ${{ github.event.pull_request.head.sha }} |
15 | | - pr_checkout_repository: ${{ github.repository }} |
16 | | - secrets: |
17 | | - cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
18 | | - cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
19 | | - matzbot_github_token: ${{ secrets.MATZBOT_GITHUB_TOKEN }} |
| 12 | + steps: |
| 13 | + - name: Trigger preview deployment |
| 14 | + uses: actions/github-script@v7 |
| 15 | + with: |
| 16 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 17 | + script: | |
| 18 | + await github.rest.repos.createDispatchEvent({ |
| 19 | + owner: context.repo.owner, |
| 20 | + repo: context.repo.repo, |
| 21 | + event_type: 'pr-preview-deploy', |
| 22 | + client_payload: { |
| 23 | + pr_number: '${{ github.event.pull_request.number }}', |
| 24 | + pr_head_sha: '${{ github.event.pull_request.head.sha }}', |
| 25 | + pr_checkout_repository: '${{ github.repository }}', |
| 26 | + is_fork: 'false' |
| 27 | + } |
| 28 | + }); |
| 29 | + console.log('Triggered main repo preview deployment'); |
20 | 30 |
|
21 | | - # For fork PRs - this job requires approval |
22 | | - wait-for-approval: |
23 | | - name: Wait for Approval (Fork PR) |
| 31 | + # Approval gate for fork PRs |
| 32 | + approve-for-fork: |
| 33 | + name: Approve Fork PR |
24 | 34 | runs-on: ubuntu-latest |
25 | 35 | if: github.event.pull_request.head.repo.fork == true |
26 | 36 | environment: fork-preview-protection |
27 | | - # This job only serves as an approval gate - it doesn't do anything else |
28 | 37 | steps: |
29 | | - - run: echo "Approval granted. Proceeding with preview deployment for commit ${{ github.event.pull_request.head.sha }}." |
30 | | - |
31 | | - # Once approval is granted, call the shared workflow |
32 | | - trigger-fork-preview: |
33 | | - name: Trigger Preview (Fork - After Approval) |
34 | | - needs: wait-for-approval |
35 | | - uses: ./.github/workflows/cloudflare-preview.yml |
36 | | - if: github.event.pull_request.head.repo.fork == true |
37 | | - with: |
38 | | - pr_number: ${{ github.event.pull_request.number }} |
39 | | - pr_head_sha: ${{ github.event.pull_request.head.sha }} |
40 | | - pr_checkout_repository: ${{ github.event.pull_request.head.repo.full_name }} |
41 | | - secrets: |
42 | | - cloudflare_api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
43 | | - cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
44 | | - matzbot_github_token: ${{ secrets.MATZBOT_GITHUB_TOKEN }} |
| 38 | + - run: echo "Fork PR ${{ github.event.pull_request.number }} approved for preview deployment" |
0 commit comments