-
Notifications
You must be signed in to change notification settings - Fork 455
53 lines (49 loc) · 1.78 KB
/
pr-preview-check.yml
File metadata and controls
53 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: PR Preview Check
on:
pull_request:
jobs:
# Deploy main repo PRs directly
deploy-for-main:
name: Trigger Preview Build and Deploy (Main Repo)
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.fork == false
permissions:
contents: write
steps:
- name: Trigger preview deployment
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.repos.createDispatchEvent({
owner: context.repo.owner,
repo: context.repo.repo,
event_type: 'pr-preview-deploy',
client_payload: {
pr_number: '${{ github.event.pull_request.number }}',
pr_head_sha: '${{ github.event.pull_request.head.sha }}',
pr_checkout_repository: '${{ github.repository }}',
is_fork: 'false'
}
});
console.log('Triggered main repo preview deployment');
# Approval gate for fork PRs
approve-for-fork:
name: Approve Fork PR
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.fork == true
environment: fork-preview-protection
steps:
- name: Save PR information
run: |
echo "Fork PR #${{ github.event.pull_request.number }} approved for preview deployment"
mkdir -p ./pr
echo "${{ github.event.pull_request.number }}" > ./pr/pr_number
echo "${{ github.event.pull_request.head.sha }}" > ./pr/pr_head_sha
echo "${{ github.event.pull_request.head.repo.full_name }}" > ./pr/pr_checkout_repository
- name: Upload PR information
uses: actions/upload-artifact@v7
with:
name: pr
path: pr/
retention-days: 1