Skip to content

docs: optimize documentation and update release workflow #19

docs: optimize documentation and update release workflow

docs: optimize documentation and update release workflow #19

Workflow file for this run

# Ultra-Optimized GitHub Pages Deployment

Check failure on line 1 in .github/workflows/pages.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/pages.yml

Invalid workflow file

(Line: 165, Col: 13): Unrecognized named-value: 'env'. Located at position 1 within expression: env.DEPLOY_TARGET == 'production' && 'github-pages' || 'github-pages-staging'
# 业界最佳实践:SWC编译、双层缓存、并行构建、Lighthouse CI、安全加固
name: 🚀 Deploy Pages
on:
push:
branches: [master, main]
paths-ignore:
- '**.md'
- 'docs/**'
- '.github/workflows/release.yml'
pull_request:
branches: [master, main]
paths-ignore:
- '**.md'
- 'docs/**'
workflow_dispatch:
inputs:
deploy_target:
description: 'Deploy target'
required: true
default: 'production'
type: choice
options: [production, staging]
# 最小权限原则
permissions:
contents: read
pages: write
id-token: write
pull-requests: write
# 并发控制
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: '20.11.0'
DEPLOY_TARGET: ${{ github.event.inputs.deploy_target || 'production' }}
jobs:
# ========== 变更检测 ==========
changes:
name: 🔍 Detect Changes
runs-on: ubuntu-latest
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
frontend:
- 'src/**'
- 'public/**'
- 'index.html'
- 'package*.json'
- 'vite.config.ts'
- 'tsconfig*.json'
- 'tailwind.config.*'
# ========== 构建优化 ==========
build:
name: 🏗️ Build & Optimize
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
# 双层缓存策略
- name: Cache dependencies
uses: actions/cache@v4
id: cache-npm
with:
path: |
~/.npm
node_modules/.cache
.turbo
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
${{ runner.os }}-npm-
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
- name: Install dependencies
run: npm ci --prefer-offline --no-audit --no-fund
# 并行质量检查
- name: Type check
run: npm run typecheck
- name: Lint
run: npm run lint
- name: Test
run: npm run test:run
env:
CI: true
# 生产构建(使用 SWC)
- name: Build
run: npm run build:pages
env:
NODE_ENV: production
VITE_COMMIT_SHA: ${{ github.sha }}
VITE_REF_NAME: ${{ github.ref_name }}
# 安全扫描
- name: Security audit
run: |
npm audit --audit-level=moderate || true
if grep -r "sk-" dist/ 2>/dev/null; then
echo "❌ Secret found in build!"
exit 1
fi
# 上传到 Pages
- name: Upload to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: ./dist
retention-days: 1
# ========== Lighthouse 性能测试 ==========
lighthouse:
name: 🧪 Lighthouse CI
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: github-pages
path: dist
- name: Run Lighthouse CI
uses: treosh/lighthouse-ci-action@v11
with:
configPath: './lighthouserc.json'
uploadArtifacts: true
temporaryPublicStorage: true
# ========== 部署 ==========
deploy:
name: 🌍 Deploy
runs-on: ubuntu-latest
needs: [build, lighthouse]
if: success()
environment:
name: ${{ env.DEPLOY_TARGET == 'production' && 'github-pages' || 'github-pages-staging' }}
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# ========== 健康检查 ==========
healthcheck:
name: ✓ Health Check
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Wait for deployment
run: sleep 15
- name: Check site health
run: |
URL="https://lessup.github.io/meta-human/"
for i in {1..5}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
if [ "$STATUS" = "200" ]; then
echo "✅ Site is healthy (HTTP $STATUS)"
exit 0
fi
sleep 5
done
echo "❌ Health check failed"
exit 1