mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 04:29:27 +08:00
109 lines
3.5 KiB
YAML
109 lines
3.5 KiB
YAML
name: Deploy Docs
|
|
|
|
# Publishes the Astro/Starlight docs site (`docs/`) to Cloudflare Workers Static Assets
|
|
# whenever a non-draft, non-prerelease GitHub Release is published (or on manual dispatch).
|
|
#
|
|
# One-time repository setup (Settings -> Environments -> `docs-production`):
|
|
# Protection rules: limit deployments to `main` and release tags (`v*`).
|
|
# Secrets:
|
|
# - CLOUDFLARE_API_TOKEN (Workers Scripts: Edit + Zone Custom Domains)
|
|
# - CLOUDFLARE_ACCOUNT_ID (Cloudflare account owning `deeptutor-docs`)
|
|
# Optional Environment Variable:
|
|
# - DOCS_SITE (defaults to `https://docs.deeptutor.info`;
|
|
# switch to `https://deeptutor.info` when migrating domains)
|
|
|
|
on:
|
|
release:
|
|
types: [published]
|
|
workflow_dispatch:
|
|
inputs:
|
|
ref:
|
|
description: "Git ref (branch or tag) to build and deploy (defaults to current branch)"
|
|
required: false
|
|
default: ""
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: docs-production-deploy
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
WRANGLER_VERSION: "4.100.0"
|
|
|
|
jobs:
|
|
deploy:
|
|
name: Build and deploy docs to Cloudflare Workers
|
|
if: >-
|
|
github.event_name == 'workflow_dispatch' ||
|
|
(github.event_name == 'release' &&
|
|
github.event.release.draft == false &&
|
|
github.event.release.prerelease == false)
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: docs-production
|
|
url: ${{ vars.DOCS_SITE || 'https://docs.deeptutor.info' }}
|
|
steps:
|
|
- name: Checkout target ref
|
|
uses: actions/checkout@v6
|
|
with:
|
|
ref: >-
|
|
${{
|
|
github.event_name == 'release' && github.event.release.tag_name ||
|
|
inputs.ref ||
|
|
github.ref
|
|
}}
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: "22"
|
|
cache: npm
|
|
cache-dependency-path: docs/package-lock.json
|
|
|
|
- name: Validate docs sources
|
|
run: python3 -X utf8 docs/scripts/check_docs.py
|
|
|
|
- name: Install docs dependencies
|
|
working-directory: docs
|
|
run: npm ci
|
|
|
|
- name: Build production docs site
|
|
working-directory: docs
|
|
env:
|
|
DOCS_SITE: ${{ vars.DOCS_SITE || 'https://docs.deeptutor.info' }}
|
|
DOCS_BASE: "/"
|
|
DOCS_NOINDEX: "0"
|
|
ASTRO_TELEMETRY_DISABLED: "1"
|
|
run: npm run build
|
|
|
|
- name: Validate built links
|
|
env:
|
|
DOCS_BASE: "/"
|
|
run: python3 -X utf8 docs/scripts/check_docs.py dist
|
|
|
|
- name: Deploy to Cloudflare Workers
|
|
working-directory: docs
|
|
env:
|
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
run: |
|
|
if [ -z "${CLOUDFLARE_API_TOKEN}" ] || [ -z "${CLOUDFLARE_ACCOUNT_ID}" ]; then
|
|
echo "::error::Missing CLOUDFLARE_API_TOKEN or CLOUDFLARE_ACCOUNT_ID in the docs-production GitHub Environment."
|
|
exit 1
|
|
fi
|
|
npx --yes --package="wrangler@${WRANGLER_VERSION}" \
|
|
wrangler deploy --config wrangler.toml
|
|
|
|
- name: Verify live site
|
|
env:
|
|
DOCS_SITE: ${{ vars.DOCS_SITE || 'https://docs.deeptutor.info' }}
|
|
run: |
|
|
for path in "/" "/zh-cn/"; do
|
|
url="${DOCS_SITE%/}${path}"
|
|
status=$(curl -fsS -o /dev/null -w "%{http_code}" "$url")
|
|
echo "GET $url -> HTTP $status"
|
|
test "$status" = "200"
|
|
done
|