Skip to content

Commit f9f15b2

Browse files
fix(security): PR Previews from Forks (#458)
* apply fix * Update build-preview.yaml * Update deploy-preview.yaml --------- Co-authored-by: Riley Park <[email protected]>
1 parent f4b929e commit f9f15b2

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

.github/workflows/deploy-pr.yaml renamed to .github/workflows/build-preview.yaml

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
name: "Deploy to Cloudflare Pages (Preview)"
1+
name: "Build Preview Deployment"
22

3-
on: [pull_request_target]
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
46

57
jobs:
6-
deploy:
8+
build-preview:
79
runs-on: "ubuntu-latest"
8-
permissions:
9-
contents: read
10-
deployments: write
11-
pull-requests: write
10+
name: "Build Preview Site and Upload Build Artifact"
1211
steps:
1312
- name: "checkout"
1413
uses: "actions/checkout@v4"
@@ -34,13 +33,8 @@ jobs:
3433
run: |
3534
cp _headers build/
3635
cp _redirects build/
37-
- name: "publish (push)"
38-
id: "cloudflare-publish"
39-
uses: "AdrianGonz97/refined-cf-pages-action@v1"
36+
- name: "upload build artifact"
37+
uses: "actions/upload-artifact@v4"
4038
with:
41-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
42-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
43-
projectName: "papermc-docs"
44-
deploymentName: "Preview"
45-
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
46-
directory: "build"
39+
name: "preview-build"
40+
path: "build"

.github/workflows/deploy-preview.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Publish Preview Deployment"
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build Preview Deployment"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
actions: read
11+
contents: read
12+
deployments: write
13+
pull-requests: write
14+
15+
jobs:
16+
deploy-preview:
17+
runs-on: "ubuntu-latest"
18+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
19+
name: "Deploy Preview to Cloudflare Pages"
20+
steps:
21+
- name: "Download build artifact"
22+
uses: "actions/download-artifact@v4"
23+
id: "preview-build-artifact"
24+
with:
25+
name: "preview-build"
26+
path: "build"
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
run-id: ${{ github.event.workflow_run.id }}
29+
- name: "Deploy to Cloudflare Pages"
30+
uses: "AdrianGonz97/refined-cf-pages-action@v1"
31+
with:
32+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
33+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
34+
githubToken: ${{ secrets.GITHUB_TOKEN }}
35+
projectName: "papermc-docs"
36+
deploymentName: "Preview"
37+
directory: ${{ steps.preview-build-artifact.outputs.download-path }}

0 commit comments

Comments
 (0)