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
5 changes: 5 additions & 0 deletions .changeset/loud-signs-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"github-actions-cloudflare-pages": minor
---

Added support for the GitHub workflow_run event to enable fork-safe preview deployments and pull request comments.
39 changes: 39 additions & 0 deletions .github/workflows/deploy-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: deploy-main
on:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

jobs:
cloudflare-pages-deploy:
permissions:
actions: read
contents: read
deployments: write
pull-requests: write
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
- id: 'cloudflare-pages'
uses: ./
with:
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: dist
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: production
working-directory: example
- id: 'cloudflare-pages-delete'
uses: ./delete
with:
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
github-token: ${{ secrets.GITHUB_TOKEN }}
# Only required for legacy action deployments.
github-environment: production
keep-latest: 2
30 changes: 13 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

name: deploy
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_run:
workflows:
- test
types:
- completed
workflow_dispatch:
inputs:
environment:
Expand All @@ -20,6 +19,7 @@

jobs:
cloudflare-pages-deploy:
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') }}
permissions:
actions: read
contents: read
Expand All @@ -28,24 +28,20 @@
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
- if: github.event_name == 'workflow_run'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_sha }}
- if: github.event_name != 'workflow_run'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
- id: 'cloudflare-pages'
uses: ./
with:
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: dist
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: ${{ inputs.environment || 'preview' }}
working-directory: example

Check failure

Code scanning / CodeQL

Checkout of untrusted code in a privileged context Critical

Potential execution of untrusted code on a privileged workflow (
workflow_run
)
- id: 'cloudflare-pages-delete'
uses: ./delete
# if main branch
if: github.ref == 'refs/heads/main'
with:
cloudflare-api-token: ${{secrets.CLOUDFLARE_API_TOKEN}}
github-token: ${{ secrets.GITHUB_TOKEN }}
# Only required for legacy action deployments.
github-environment: ${{ inputs.environment || 'preview' }}
keep-latest: 2
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,44 @@ jobs:
github-environment: ${{ vars.CLOUDFLARE_PROJECT_NAME }} ${{ (github.ref == 'refs/heads/main' && '(Production)') || '(Preview)' }}
```

### Fork pull requests with `workflow_run`

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.

```yaml
name: Deploy PR Preview (Fork Safe)
on:
workflow_run:
workflows: ['CI']
types: [completed]

jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: read
deployments: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_sha }}

- name: Deploy to Cloudflare Pages
uses: andykenward/github-actions-cloudflare-pages@v3.0.0
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: dist
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: preview
```

This action supports the `workflow_run` event and will use the `workflow_run` head commit SHA and branch for deployment metadata and PR comments.

## Comment Example

![pull request comment example](./docs/comment.png)
Expand Down
12 changes: 12 additions & 0 deletions __generated__/gql/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions __generated__/gql/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading