Hachi Blog
2026-01-28

CloudflarePagesへのデプロイ by GitHub Actions

#python #gemini #github #mupy

CloudflarePagesへデプロイするので、いくつか修正します。 CloudflarePagesへは、GitHubActions経由でデプロイします。

  • 出力フォルダをoutput/からdist/へ変更
  • URL内のposts/を削除
  • 404ページの追加
  • CloudflarePagesへのデプロイのため、GitHub Actionsの追加

出力フォルダをoutput/からdist/へ変更

もともとoutput/を利用していたが、標準のdist/(distribution)に修正します。

$ gemini

> 出力先のoutput/をdist/に修正してください

URL内のposts/を削除

今のURLは、example.com/posts/xxxだったが、postsが余計だったので修正。

$ gemini

> 出力先の `output/posts/xxx`  `dist/xxx` に修正してください

404ページを追加

404ページがなかったので追加します。

$ gemini

> 404ページを追加して

GitHub Actionsの追加

Cloudflare Pagesにデプロイすることにしたので、GitHubActions用のファイルを追加

$ gemini

> GithubActionsでCloudflarePagesにデプロイするコードを追加して。

Cloudflare側の設定や、GitHubへのSecrets登録は割愛。

name: Deploy to Cloudflare Pages

on:
  push:
    branches: [ "main" ] # メインブランチにpushされたら実行

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11' # 利用しているバージョンに合わせて変更

      - name: Install dependencies
        run: |
          pip install -r requirements.txt

      - name: Build SSG
        run: |
          python main.py

      - name: Publish to Cloudflare Pages
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy dist --project-name=mupy
          # 「dist」はSSGがHTMLを出力するディレクトリ名に変更してください
          # 「YOUR_PROJECT_NAME」はCloudflare Pages上のプロジェクト名

【おまけ】GEMINI.mdの追加

機能要件、作業内容を毎回指示するのがめんどくさくなってきたので、GEMINI.mdを追加しました。 GEMINI.mdは、GeminiCLIが勝手に読んでくれる設定ファイルで、コーディング等の基本ルールを記載しておきます。

ルールは単純で、機能要件と作業手順を先に検討してファイルを更新、これだけです。

## basic rule

- If the requested content requires code modifications, you must first modify the following two files and have them reviewed.
  - `./doc/requirements.md` : New features/requirements should be added
  - `./docs/development_plan.md` : The work history should be added
- use `.venv` for running `python` and `pip` command.

## Context Files

- `./doc/requirements.md` (product requirements)
- `./docs/development_plan.md` (work history)