-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Migrate docs site from Netlify to Cloudflare Workers #14025
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
78e04a7
Migrate from Netlify to Cloudflare Workers
matthewp 6458343
Fix CI: approve workerd build script for pnpm
matthewp ea63f3a
Merge main into migrate-cloudflare
matthewp f305b5c
Allow workerd build script in pnpm-workspace.yaml
matthewp 06e03b3
Trigger CI
matthewp 37ec087
Increase Node.js heap size for Workers Builds
matthewp 9b54083
Remove build command from wrangler config
matthewp 2625f78
Add GitHub Actions deploy workflow with preview URLs
matthewp 1705840
Trigger CI
matthewp 116d5df
Fix preview URL domain
matthewp 929a755
Trigger CI
matthewp d2566f6
Trigger CI
matthewp 1e22831
Use GITHUB_HEAD_REF for preview site URL
matthewp 5bfb1e5
Cache Astro build artifacts between CI runs
matthewp 15d051b
Add deployment status to PR comment
matthewp a7db42e
Comment out 404 redirect unsupported by Cloudflare
matthewp ec11967
Fix worker name to 'docs'
matthewp b083fba
Cache OG images between builds
matthewp 02b725c
Trigger CI to test OG cache
matthewp 5dc8b2f
Review cleanup: remove deploy script, observability; add localized 40…
matthewp 7bf0eeb
Fix ESLint: declare Worker globals
matthewp 17ccfb0
Add ASSETS binding for Worker to fetch static assets
matthewp fef98c4
Use cloudflare/wrangler-action and add Worker docs
matthewp ff7a091
Disallow workerd build script
matthewp 30b4701
Skip deploy and PR comments for fork PRs
matthewp dd50071
Deploy previews for fork PRs via workflow_run
matthewp 22242e3
Address review feedback on deploy workflows
matthewp 1162f5a
Support deploying version branches (v4, v5, v6)
matthewp b78e7f2
Add v7 to version branch deploy list
matthewp 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,143 @@ | ||
| name: Deploy Preview | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Deploy"] | ||
| types: [completed] | ||
|
|
||
| permissions: {} | ||
|
|
||
| # Cancel older preview runs for the same branch so a stale deploy doesn't | ||
| # overwrite the comment from a newer one. | ||
| concurrency: | ||
| group: preview-${{ github.event.workflow_run.head_branch }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| deploy-preview: | ||
| if: >- | ||
| github.event.workflow_run.event == 'pull_request' && | ||
| github.event.workflow_run.conclusion == 'success' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| permissions: | ||
| pull-requests: write | ||
| steps: | ||
| - name: Download PR metadata | ||
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | ||
| with: | ||
| name: pr-metadata | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ github.token }} | ||
| path: pr-metadata | ||
|
|
||
| - name: Read PR metadata | ||
| id: metadata | ||
| run: | | ||
| echo "pr_number=$(cat pr-metadata/pr_number)" >> "$GITHUB_OUTPUT" | ||
| echo "preview_alias=$(cat pr-metadata/preview_alias)" >> "$GITHUB_OUTPUT" | ||
| echo "preview_url=$(cat pr-metadata/preview_url)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Comment deployment in progress | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const prNumber = parseInt('${{ steps.metadata.outputs.pr_number }}', 10); | ||
| const previewUrl = '${{ steps.metadata.outputs.preview_url }}'; | ||
| const commitSHA = '${{ github.event.workflow_run.head_sha }}'; | ||
| const runUrl = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; | ||
| const body = `**Preview deployment**\n\n` | ||
| + `🔄 Deployment in progress...\n\n` | ||
| + `- **Latest commit:** ${commitSHA}\n` | ||
| + `- **Preview:** ${previewUrl}\n` | ||
| + `- **Workflow run:** [View logs](${runUrl})`; | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| }); | ||
| const existing = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.includes('**Preview deployment**')); | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body, | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body, | ||
| }); | ||
| } | ||
|
|
||
| - name: Download build output | ||
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | ||
| with: | ||
| name: build-output | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ github.token }} | ||
|
|
||
| - name: Deploy preview | ||
| uses: cloudflare/wrangler-action@9acf94ace14e7dc412b076f2c5c20b8ce93c79cd # v3.15.0 | ||
| with: | ||
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
| command: versions upload --preview-alias "${{ steps.metadata.outputs.preview_alias }}" | ||
|
|
||
| - name: Comment deployment complete | ||
| if: success() | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const prNumber = parseInt('${{ steps.metadata.outputs.pr_number }}', 10); | ||
| const previewUrl = '${{ steps.metadata.outputs.preview_url }}'; | ||
| const commitSHA = '${{ github.event.workflow_run.head_sha }}'; | ||
| const runUrl = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; | ||
| const body = `**Preview deployment**\n\n` | ||
| + `✅ Deployment complete!\n\n` | ||
| + `- **Latest commit:** ${commitSHA}\n` | ||
| + `- **Preview:** ${previewUrl}\n` | ||
| + `- **Workflow run:** [View logs](${runUrl})`; | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| }); | ||
| const existing = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.includes('**Preview deployment**')); | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body, | ||
| }); | ||
| } | ||
|
|
||
| - name: Comment deployment failed | ||
| if: failure() | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const prNumber = parseInt('${{ steps.metadata.outputs.pr_number }}', 10); | ||
| const commitSHA = '${{ github.event.workflow_run.head_sha }}'; | ||
| const runUrl = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; | ||
| const body = `**Preview deployment**\n\n` | ||
| + `❌ Deployment failed!\n\n` | ||
| + `- **Latest commit:** ${commitSHA}\n` | ||
| + `- **Workflow run:** [View logs](${runUrl})`; | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| }); | ||
| const existing = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.includes('**Preview deployment**')); | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body, | ||
| }); | ||
| } | ||
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,83 @@ | ||
| name: Deploy | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, v4, v5, v6, v7] | ||
| pull_request: | ||
|
|
||
| # Automatically cancel in-progress actions on the same branch | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: {} | ||
|
|
||
| env: | ||
| NODE_OPTIONS: "--max_old_space_size=8192" | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
|
|
||
| - name: Install Tools & Dependencies | ||
| uses: ./.github/actions/install | ||
|
|
||
| - name: Cache Astro build | ||
| uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | ||
| with: | ||
| path: | | ||
| node_modules/.astro | ||
| node_modules/.astro-og-canvas | ||
| key: astro-build-${{ hashFiles('src/**') }} | ||
| restore-keys: | | ||
| astro-build- | ||
|
|
||
| - name: Build | ||
| run: pnpm build | ||
|
|
||
| - name: Deploy | ||
| if: >- | ||
| github.ref == 'refs/heads/main' || | ||
| github.ref == 'refs/heads/v4' || | ||
| github.ref == 'refs/heads/v5' || | ||
| github.ref == 'refs/heads/v6' || | ||
| github.ref == 'refs/heads/v7' | ||
| uses: cloudflare/wrangler-action@9acf94ace14e7dc412b076f2c5c20b8ce93c79cd # v3.15.0 | ||
| with: | ||
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
| command: deploy | ||
|
|
||
| - name: Upload build output | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: build-output | ||
| path: | | ||
| dist/ | ||
| worker.js | ||
| wrangler.jsonc | ||
|
|
||
| - name: Save PR metadata | ||
| if: github.event_name == 'pull_request' | ||
| run: | | ||
| mkdir -p pr-metadata | ||
| echo "${{ github.event.pull_request.number }}" > pr-metadata/pr_number | ||
| BRANCH="${{ github.head_ref }}" | ||
| # Sanitize branch name into a valid subdomain: lowercase, replace non-alphanumeric chars with hyphens, strip leading/trailing hyphens. | ||
| # Used as the subdomain for the preview URL, e.g. "my-branch.previews.docs.astro.build". | ||
| ALIAS=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/^-//' | sed 's/-$//') | ||
|
delucis marked this conversation as resolved.
|
||
| echo "$ALIAS" > pr-metadata/preview_alias | ||
| echo "https://${ALIAS}.previews.docs.astro.build" > pr-metadata/preview_url | ||
|
|
||
| - name: Upload PR metadata | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: pr-metadata | ||
| path: pr-metadata/ | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.