Skip to content

Commit 1c10be0

Browse files
andykenwardCopilot
andauthored
feat: event workflow_run support (#732)
* chore(deps-dev): upgrade typescript from 5.9.3 to 6.0.3 * chore: tsconfig add types Co-authored-by: Copilot <copilot@github.com> * feat: workflow_run support Co-authored-by: Copilot <copilot@github.com> * docs: Fork pull requests with `workflow_run` * chore: build * chore: changeset * feat: enhance workflow_run handling to validate pull requests by branch and SHA Co-authored-by: Copilot <copilot@github.com> * chore: changeset Co-authored-by: Copilot <copilot@github.com> * chore: build * ci: update action to support forks Co-authored-by: Copilot <copilot@github.com> * ci: fix github-environment --------- Co-authored-by: Copilot <copilot@github.com>
1 parent b88f2a3 commit 1c10be0

20 files changed

Lines changed: 710 additions & 119 deletions

File tree

.changeset/loud-signs-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"github-actions-cloudflare-pages": minor
3+
---
4+
5+
Added support for the GitHub workflow_run event to enable fork-safe preview deployments and pull request comments.

.github/workflows/deploy-main.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
name: deploy-main
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
10+
11+
jobs:
12+
cloudflare-pages-deploy:
13+
permissions:
14+
actions: read
15+
contents: read
16+
deployments: write
17+
pull-requests: write
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 5
20+
steps:
21+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
22+
- id: 'cloudflare-pages'
23+
uses: ./
24+
with:
25+
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
26+
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
27+
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
28+
directory: dist
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
github-environment: production
31+
working-directory: example
32+
- id: 'cloudflare-pages-delete'
33+
uses: ./delete
34+
with:
35+
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
# Only required for legacy action deployments.
38+
github-environment: production
39+
keep-latest: 2

.github/workflows/deploy.yml

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
name: deploy
44
on:
5-
pull_request:
6-
branches:
7-
- main
8-
push:
9-
branches:
10-
- main
5+
workflow_run:
6+
workflows:
7+
- test
8+
types:
9+
- completed
1110
workflow_dispatch:
1211
inputs:
1312
environment:
@@ -20,6 +19,7 @@ concurrency:
2019

2120
jobs:
2221
cloudflare-pages-deploy:
22+
if: ${{ github.event_name != 'workflow_run' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.head_branch != 'main') }}
2323
permissions:
2424
actions: read
2525
contents: read
@@ -28,7 +28,13 @@ jobs:
2828
runs-on: ubuntu-latest
2929
timeout-minutes: 5
3030
steps:
31-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
31+
- if: github.event_name == 'workflow_run'
32+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
33+
with:
34+
repository: ${{ github.event.workflow_run.head_repository.full_name }}
35+
ref: ${{ github.event.workflow_run.head_sha }}
36+
- if: github.event_name != 'workflow_run'
37+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
3238
- id: 'cloudflare-pages'
3339
uses: ./
3440
with:
@@ -39,13 +45,3 @@ jobs:
3945
github-token: ${{ secrets.GITHUB_TOKEN }}
4046
github-environment: ${{ inputs.environment || 'preview' }}
4147
working-directory: example
42-
- id: 'cloudflare-pages-delete'
43-
uses: ./delete
44-
# if main branch
45-
if: github.ref == 'refs/heads/main'
46-
with:
47-
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
48-
github-token: ${{ secrets.GITHUB_TOKEN }}
49-
# Only required for legacy action deployments.
50-
github-environment: ${{ inputs.environment || 'preview' }}
51-
keep-latest: 2

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)

__generated__/gql/gql.ts

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__generated__/gql/graphql.ts

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)