forked from kamat/blog
55 lines
1.8 KiB
YAML
55 lines
1.8 KiB
YAML
name: Deploy to Cloudflare Pages (cobalt, wrangler)
|
|
|
|
on:
|
|
push:
|
|
branches: ["main", "master"]
|
|
workflow_dispatch: {}
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: node:20-bookworm
|
|
env:
|
|
CF_PAGES_PROJECT: ${{ vars.CF_PAGES_PROJECT }}
|
|
PROD_BRANCH: "main"
|
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
|
|
steps:
|
|
- name: Check Node runtime
|
|
run: node -v && node -e "console.log('crypto?', !!globalThis.crypto)"
|
|
|
|
- name: Checkout
|
|
uses: https://github.com/actions/checkout@v4
|
|
|
|
- name: Restore build tools
|
|
id: build-tools
|
|
uses: https://github.com/actions/cache@v4
|
|
with:
|
|
path: .ci/tools
|
|
key: blog-tools-linux-x64-cobalt-v0.20.4-wrangler-v3.90.0
|
|
|
|
- name: Install build tools
|
|
if: steps.build-tools.outputs.cache-hit != 'true'
|
|
run: |
|
|
mkdir -p .ci/tools/bin .ci/tools/wrangler
|
|
curl -fsSL https://github.com/cobalt-org/cobalt.rs/releases/download/v0.20.4/cobalt-v0.20.4-x86_64-unknown-linux-gnu.tar.gz \
|
|
| tar -xzf - -C .ci/tools/bin ./cobalt
|
|
npm install --prefix .ci/tools/wrangler --no-audit --no-fund --no-package-lock --no-save [email protected]
|
|
|
|
- name: Check build tools
|
|
run: |
|
|
.ci/tools/bin/cobalt --version
|
|
.ci/tools/wrangler/node_modules/.bin/wrangler --version
|
|
|
|
- name: Build site with cobalt
|
|
run: .ci/tools/bin/cobalt build # 出力: ./_site
|
|
|
|
- name: Deploy to Cloudflare Pages
|
|
run: |
|
|
branch="${GITHUB_REF_NAME:-${GITEA_REF_NAME:-$PROD_BRANCH}}"
|
|
.ci/tools/wrangler/node_modules/.bin/wrangler pages deploy _site \
|
|
--project-name "$CF_PAGES_PROJECT" \
|
|
--branch "$branch"
|