-
Notifications
You must be signed in to change notification settings - Fork 7
Enable deploy previews via cloudflare #40
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
Open
magicmark
wants to merge
14
commits into
main
Choose a base branch
from
magicmark-patch-6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
70e6b96
fix cloudflare pages(?)
magicmark e6f6f97
Update compatibility date in wrangler.jsonc
magicmark a218994
Add unprivileged build workflow for PR deploy previews
magicmark 0f39113
Add deploy preview workflow (workflow_run triggered)
magicmark 59c2191
Fix deploy preview workflows: fork PR support, action versions, permi…
magicmark 939c1d4
Update preview workflows from gaps-website-test-1, remove pages.yml
magicmark fff39a1
Update preview-deploy.yml
magicmark e841560
Harden deploy preview workflows
magicmark 18c0148
Address Benjie's review feedback
magicmark 0966b6f
fix: paginate comments and filter by bot author
magicmark e680187
chore: add --no-bundle to wrangler versions upload
magicmark 17b1a4f
Address Benjie's review feedback (#56)
magicmark b7d8fa1
Bump actions to latest versions
magicmark 941093b
Fix wrangler command split across multiple lines
magicmark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Minimizes previous deploy-preview comments so only the latest is visible. | ||
| // Called from preview-deploy.yml via actions/github-script. | ||
|
|
||
| export default async function run({ github, context, prNumber }) { | ||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| }); | ||
|
|
||
| await Promise.all( | ||
| comments | ||
| .filter( | ||
| (c) => | ||
| c.user.login === "github-actions[bot]" && | ||
| c.body.includes("<!-- deploy-preview -->") | ||
| ) | ||
| .map((c) => | ||
| github.graphql( | ||
| ` | ||
| mutation($id: ID!) { | ||
| minimizeComment(input: { subjectId: $id, classifier: OUTDATED }) { | ||
| minimizedComment { isMinimized } | ||
| } | ||
| } | ||
| `, | ||
| { id: c.node_id } | ||
| ) | ||
| ) | ||
| ); | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Build Preview | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: preview-build-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build site | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 | ||
| with: | ||
| node-version: "24" | ||
| cache: "npm" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Build GAP website | ||
| run: npm run build | ||
|
|
||
| - name: Upload build artifact | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | ||
| with: | ||
| name: preview-build | ||
| path: _site | ||
| include-hidden-files: true | ||
| retention-days: 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| name: Deploy Preview | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Build Preview"] | ||
| types: [completed] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy preview to Cloudflare | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} | ||
|
|
||
| steps: | ||
| - name: Checkout wrangler config | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | ||
| with: | ||
| ref: main | ||
| sparse-checkout: | | ||
| wrangler.jsonc | ||
| .github/scripts | ||
|
|
||
| # Security: actions/download-artifact handles zip extraction safely | ||
| # (immune to zip-slip), and the artifact only contains static HTML/CSS/JS | ||
| # built by the unprivileged preview-build workflow. | ||
| - name: Download build artifact | ||
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 | ||
| with: | ||
| name: preview-build | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| path: _site | ||
|
magicmark marked this conversation as resolved.
|
||
|
|
||
| - name: Get PR number | ||
| id: pr | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| PR_NUM=$(gh pr list --repo "${{ github.repository }}" \ | ||
| --head "${{ github.event.workflow_run.head_branch }}" \ | ||
| --json number --jq '.[0].number') | ||
| if ! [[ "$PR_NUM" =~ ^[0-9]+$ ]]; then | ||
| echo "::error::Could not determine PR number" | ||
| exit 1 | ||
| fi | ||
| echo "number=$PR_NUM" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Security: Wrangler is configured for static asset serving only (see | ||
| # wrangler.jsonc). The uploaded content is pre-built HTML/CSS/JS with no | ||
| # server-side execution capability. | ||
| - name: Deploy preview to Cloudflare Workers | ||
| id: deploy | ||
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4 | ||
| with: | ||
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | ||
| command: versions upload --no-bundle --preview-alias "pr-${{ steps.pr.outputs.number }}" --message "PR #${{ steps.pr.outputs.number }} preview (${{ github.event.workflow_run.head_sha }})" | ||
|
|
||
| - name: Hide old deploy preview comments | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | ||
| with: | ||
| script: | | ||
|
magicmark marked this conversation as resolved.
|
||
| const { default: run } = await import('${{ github.workspace }}/.github/scripts/hide-old-deploy-comments.mjs'); | ||
| await run({ github, context, prNumber: ${{ steps.pr.outputs.number }} }); | ||
|
|
||
| - name: Comment on PR (success) | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | ||
| with: | ||
| script: | | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: ${{ steps.pr.outputs.number }}, | ||
| body: [ | ||
| '<!-- deploy-preview -->', | ||
| '### 🚀 Deploy Preview', | ||
| '', | ||
| '- **This commit:** ${{ steps.deploy.outputs.deployment-url }}', | ||
| '- **This PR** <sub>(kept up to date)</sub>: https://pr-${{ steps.pr.outputs.number }}-gaps.graphql-foundation.workers.dev' | ||
| ].join('\n') | ||
| }); | ||
|
|
||
| - name: Comment on PR (failure) | ||
| if: failure() | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | ||
| with: | ||
| script: | | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: ${{ steps.pr.outputs.number }}, | ||
| body: 'Deploy preview failed.\n\n```\ngh run view ${{ github.run_id }} --repo ${{ github.repository }} --log-failed\n```' | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "$schema": "node_modules/wrangler/config-schema.json", | ||
| "name": "gaps", | ||
| "compatibility_date": "2026-05-23", | ||
| "assets": { | ||
| "directory": "./_site" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.