初始化EmbedKit工作流系统 #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Documentation | |
| on: | |
| push: | |
| branches: [ master, main ] | |
| paths: | |
| - 'docs/**' | |
| - 'src/**/*.c' | |
| - 'src/**/*.h' | |
| - 'include/**/*.h' | |
| - '.github/workflows/docs.yml' | |
| - 'scripts/generate-sidebar.js' | |
| - 'scripts/update-docs-index.py' | |
| pull_request: | |
| branches: [ master, main ] | |
| paths: | |
| - 'docs/**' | |
| workflow_dispatch: | |
| schedule: | |
| # 每周日凌晨2点自动更新文档 | |
| - cron: '0 2 * * 0' | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # 获取完整历史记录 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.npm | |
| ~/.cache/pip | |
| key: ${{ runner.os }}-deps-${{ hashFiles('**/package-lock.json', '**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-deps- | |
| - name: Install dependencies | |
| run: | | |
| # 安装Node.js依赖 | |
| npm install -g docsify-cli | |
| npm install -g glob | |
| # 安装Python依赖 | |
| pip install -r requirements-docs.txt || true | |
| - name: Collect module READMEs | |
| run: | | |
| echo "🔄 收集模块README文件..." | |
| # 创建临时目录 | |
| mkdir -p docs/auto-generated | |
| # 收集所有模块的README | |
| for dir in src/*; do | |
| if [ -d "$dir" ]; then | |
| module_name=$(basename "$dir") | |
| if [ -f "$dir/README.md" ]; then | |
| echo " 📁 找到模块: $module_name" | |
| cp "$dir/README.md" "docs/auto-generated/${module_name}.md" | |
| fi | |
| fi | |
| done | |
| # 生成模块索引 | |
| echo "# 自动收集的模块文档" > docs/auto-generated/index.md | |
| echo "" >> docs/auto-generated/index.md | |
| echo "以下文档从源代码目录自动收集:" >> docs/auto-generated/index.md | |
| echo "" >> docs/auto-generated/index.md | |
| for file in docs/auto-generated/*.md; do | |
| if [ -f "$file" ] && [ "$(basename "$file")" != "index.md" ]; then | |
| module_name=$(basename "$file" .md) | |
| echo "- [$module_name](auto-generated/$module_name.md)" >> docs/auto-generated/index.md | |
| fi | |
| done | |
| - name: Generate documentation structure | |
| run: | | |
| echo "📝 生成文档结构..." | |
| # 运行侧边栏生成脚本 | |
| if [ -f "scripts/generate-sidebar.js" ]; then | |
| node scripts/generate-sidebar.js | |
| fi | |
| # 运行文档索引脚本 | |
| if [ -f "scripts/update-docs-index.py" ]; then | |
| python scripts/update-docs-index.py | |
| fi | |
| # 生成版本信息 | |
| echo '{"version": "'$(git describe --tags --always)'"}' > docs/package.json | |
| - name: Extract API documentation | |
| run: | | |
| echo "🔍 提取API文档..." | |
| # 使用doxygen或其他工具提取API文档 | |
| if command -v doxygen &> /dev/null; then | |
| if [ -f "Doxyfile" ]; then | |
| doxygen Doxyfile | |
| fi | |
| fi | |
| # 从头文件生成API文档 | |
| python scripts/extract-api-docs.py || true | |
| - name: Build documentation stats | |
| run: | | |
| echo "📊 生成文档统计..." | |
| # 统计文档信息 | |
| echo "## 文档统计" > docs/stats.md | |
| echo "" >> docs/stats.md | |
| echo "- 总文档数: $(find docs -name '*.md' | wc -l)" >> docs/stats.md | |
| echo "- 总代码行数: $(find src -name '*.c' -o -name '*.h' | xargs wc -l | tail -1 | awk '{print $1}')" >> docs/stats.md | |
| echo "- 模块数量: $(ls -d src/*/ 2>/dev/null | wc -l)" >> docs/stats.md | |
| echo "- 最后更新: $(date '+%Y-%m-%d %H:%M:%S')" >> docs/stats.md | |
| - name: Validate documentation | |
| run: | | |
| echo "✅ 验证文档完整性..." | |
| # 检查必要文件是否存在 | |
| required_files=("docs/index.html" "docs/_sidebar.md" "docs/README.md") | |
| for file in "${required_files[@]}"; do | |
| if [ ! -f "$file" ]; then | |
| echo "❌ 缺少必要文件: $file" | |
| exit 1 | |
| fi | |
| done | |
| # 检查死链接 | |
| python scripts/check-links.py || true | |
| - name: Optimize for production | |
| run: | | |
| echo "⚡ 优化生产环境..." | |
| # 压缩图片 | |
| if command -v optipng &> /dev/null; then | |
| find docs -name '*.png' -exec optipng -o5 {} \; | |
| fi | |
| # 生成搜索索引 | |
| echo "生成搜索索引..." | |
| # docsify会自动生成搜索索引 | |
| - name: Setup GitHub Pages | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') | |
| uses: actions/configure-pages@v3 | |
| - name: Upload artifact | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') | |
| uses: actions/upload-pages-artifact@v2 | |
| with: | |
| path: ./docs | |
| - name: Deploy to GitHub Pages | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') | |
| id: deployment | |
| uses: actions/deploy-pages@v2 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create deployment summary | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') | |
| run: | | |
| echo "## 📚 文档部署成功!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 访问地址" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🌐 [在线文档](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }})" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### 部署信息" >> $GITHUB_STEP_SUMMARY | |
| echo "- 📅 部署时间: $(date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_STEP_SUMMARY | |
| echo "- 🔖 提交: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- 👤 触发者: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- 📊 文档数量: $(find docs -name '*.md' | wc -l)" >> $GITHUB_STEP_SUMMARY | |
| - name: Notify deployment status | |
| if: always() | |
| run: | | |
| if [ "${{ job.status }}" == "success" ]; then | |
| echo "✅ 文档部署成功" | |
| else | |
| echo "❌ 文档部署失败" | |
| fi |