Closed3

SvelteKitのアプリをCloudflare Pagesにデプロイする

3w36zj63w36zj6

GitHub Actions

API Tokenは以下のリンクから作成する。

https://dash.cloudflare.com/profile/api-tokens

CLOUDFLARE_ACCOUNT_IDCLOUDFLARE_API_TOKENをGitHubのSecretsに追加する。

.github/workflows/deploy-to-cloudflare-pages.yml
name: Deploy to Cloudflare Pages

on: [push]

jobs:
  publish:
    runs-on: ubuntu-22.04
    permissions:
      contents: read
      deployments: write
      statuses: write
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup Bun
        uses: oven-sh/setup-bun@v1
      - name: Install Dependencies
        run: bun install
      - name: Build
        run: bun run build
      - name: Publish to Cloudflare Pages
        id: cloudflare_pages_deploy
        uses: cloudflare/pages-action@v1
        with:
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          projectName: PROJECT_NAME # 作成したプロジェクト名を設定する
          directory: .svelte-kit/cloudflare/
          gitHubToken: ${{ secrets.GITHUB_TOKEN }}
      - name: Add publish URL as commit status
        uses: actions/github-script@v6
        with:
          script: |
            const sha = context.payload.pull_request?.head.sha ?? context.sha;
            await github.rest.repos.createCommitStatus({
              owner: context.repo.owner,
              repo: context.repo.repo,
              context: "Cloudflare Pages",
              description: "Cloudflare Pages deployment",
              state: "success",
              sha,
              target_url: "${{ steps.cloudflare_pages_deploy.outputs.url }}",

PRではPreview環境にデプロイされる。

このスクラップは2023/10/16にクローズされました