Skip to content

Commit dfbe1b6

Browse files
committed
docs: Fork pull requests with workflow_run
1 parent 85cc190 commit dfbe1b6

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,44 @@ jobs:
134134
github-environment: ${{ vars.CLOUDFLARE_PROJECT_NAME }} ${{ (github.ref == 'refs/heads/main' && '(Production)') || '(Preview)' }}
135135
```
136136

137+
### Fork pull requests with `workflow_run`
138+
139+
When pull requests come from forks, the initial `pull_request` workflow may not have access to secrets. Use a second workflow triggered by `workflow_run` to deploy from the original repository context after approval.
140+
141+
```yaml
142+
name: Deploy PR Preview (Fork Safe)
143+
on:
144+
workflow_run:
145+
workflows: ['CI']
146+
types: [completed]
147+
148+
jobs:
149+
deploy:
150+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
151+
permissions:
152+
contents: read
153+
deployments: write
154+
pull-requests: write
155+
runs-on: ubuntu-latest
156+
steps:
157+
- uses: actions/checkout@v4
158+
with:
159+
repository: ${{ github.event.workflow_run.head_repository.full_name }}
160+
ref: ${{ github.event.workflow_run.head_sha }}
161+
162+
- name: Deploy to Cloudflare Pages
163+
uses: andykenward/github-actions-cloudflare-pages@v3.0.0
164+
with:
165+
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
166+
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
167+
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
168+
directory: dist
169+
github-token: ${{ secrets.GITHUB_TOKEN }}
170+
github-environment: preview
171+
```
172+
173+
This action supports the `workflow_run` event and will use the `workflow_run` head commit SHA and branch for deployment metadata and PR comments.
174+
137175
## Comment Example
138176

139177
![pull request comment example](./docs/comment.png)

0 commit comments

Comments
 (0)