如何将Hugo静态网页部署到Cloudflare的workers

February 17, 2021

步骤

For self

To set name = "blog" in wrangler.toml:

wrangler init --site blog
# add `account_id` and bucket = "public"

deploy.yml in ``.github/workflows`

name: Deploy to CF Workers

on:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v2
      - name: Install Hugo
        run: sudo snap install hugo

      - name: Build hugo minify gc
        run: hugo --minify --gc

      - name: Publish
        uses: cloudflare/wrangler-action@1.3.0
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          preCommands: echo "*** pre command ***"
          postCommands: |
            echo "*** post commands ***"
            wrangler publish
            echo "******"

For record


      - name: Creatte wrangler.toml with name=blog and bucket=public
        run: |
          wrangler init --site blog
          sed -i 's/bucket = ""/bucket = "public"/g' wrangler.toml
          sed -i 's/account_id = ""/account_id = "'$CF_API_TOKEN'"/g' wrangler.toml
          echo wrangler.toml

      - name: config wrangler # run: CF_API_TOKEN=${{ secrets.CF_API_TOKEN }} wrangler publish

References