Skip to content
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
57 changes: 0 additions & 57 deletions .github/workflows/pages.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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@v6

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Build GAP website
run: npm run build

- name: Save PR metadata
run: echo "${{ github.event.pull_request.number }}" > _site/pr-number

- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: preview-build
path: _site
include-hidden-files: true
retention-days: 3
101 changes: 101 additions & 0 deletions .github/workflows/preview-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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@v6
with:
sparse-checkout: |
wrangler.jsonc

- name: Download build artifact
uses: actions/download-artifact@v8
with:
name: preview-build
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: _site

- name: Read PR number
id: pr
run: |
PR_NUM=$(cat _site/pr-number 2>/dev/null)
# Guard against injection (this value flows into API calls and shell commands)
if ! [[ "$PR_NUM" =~ ^[0-9]+$ ]]; then
echo "::error::Invalid or missing .pr-number from artifact"
exit 1
fi
echo "number=$PR_NUM" >> "$GITHUB_OUTPUT"

- name: Deploy preview to Cloudflare Workers
id: deploy
uses: cloudflare/wrangler-action@v4
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: versions upload --preview-alias "pr-${{ steps.pr.outputs.number }}" --message "PR #${{ steps.pr.outputs.number }} preview"

- name: Hide old deploy preview comments
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.pr.outputs.number }}
});
await Promise.all(
comments
.filter(c => c.body.includes('<!-- deploy-preview -->'))
.map(c => github.graphql(`
mutation($id: ID!) {
minimizeComment(input: { subjectId: $id, classifier: OUTDATED }) {
minimizedComment { isMinimized }
}
}
`, { id: c.node_id }))
);

- name: Comment on PR (success)
uses: actions/github-script@v7
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@v7
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```'
});
8 changes: 8 additions & 0 deletions wrangler.jsonc
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"
}
}