Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(security): PR Previews from Forks #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions .github/workflows/build-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Build Preview Deployment"

on:
pull_request:
types: [opened, synchronize]

jobs:
build-preview:
runs-on: "ubuntu-latest"
name: "Build Preview Site and Upload Build Artifact"
steps:
- name: "checkout"
uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: "setup pnpm"
uses: "pnpm/action-setup@v4"
- name: "setup node"
uses: "actions/setup-node@v4"
with:
cache: "pnpm"
node-version: 20
- name: "install dependencies"
run: "pnpm install"
- name: "build"
run: "pnpm run build"
# Uploads the build directory as a workflow artifact
- name: "upload build artifact"
uses: "actions/upload-artifact@v4"
with:
name: "preview-build"
path: "build"
39 changes: 0 additions & 39 deletions .github/workflows/deploy-pr.yaml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Upload Preview Deployment"
on:
workflow_run:
workflows: ["Build Preview Deployment"]
types:
- completed

permissions:
actions: read
deployments: write
contents: read
pull-requests: write

jobs:
deploy-preview:
runs-on: "ubuntu-latest"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: "Deploy Preview to Cloudflare Pages"
steps:
# Downloads the build directory from the previous workflow
- name: "download build artifact"
uses: "actions/download-artifact@v4"
id: "preview-build-artifact"
with:
name: "preview-build"
path: "build"
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}

- name: "publish (push)"
uses: "AdrianGonz97/refined-cf-pages-action@v1"
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
projectName: "papermc-website"
deploymentName: "Preview"
directory: ${{ steps.preview-build-artifact.outputs.download-path }}