Merge pull request #4 from moluopro/main #4
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: Build Docs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| paths: | |
| - "**" | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: vitepress-docs-deploy | |
| cancel-in-progress: true | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Install deps | |
| run: pnpm install | |
| - name: Build VitePress | |
| run: pnpm docs:build | |
| - name: Deploy to docs branch | |
| env: | |
| DOCS_BRANCH: docs | |
| DIST_DIR: .vitepress/dist | |
| run: | | |
| set -e | |
| # 配置提交者信息(使用 Actions bot) | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # 确保产物目录存在 | |
| test -d "$DIST_DIR" | |
| # 准备一个临时目录作为分支目录 | |
| rm -rf .deploy_docs_branch | |
| mkdir -p .deploy_docs_branch | |
| # 尝试检出 docs 分支;不存在则新建 orphan 分支 | |
| if git ls-remote --exit-code --heads origin "$DOCS_BRANCH" >/dev/null 2>&1; then | |
| git worktree add .deploy_docs_branch "$DOCS_BRANCH" | |
| else | |
| git worktree add --detach .deploy_docs_branch | |
| cd .deploy_docs_branch | |
| git checkout --orphan "$DOCS_BRANCH" | |
| # 清空 index | |
| git rm -rf . >/dev/null 2>&1 || true | |
| cd .. | |
| fi | |
| # 进入 worktree,清空旧内容(保留 .git 由 worktree 管) | |
| cd .deploy_docs_branch | |
| find . -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} + | |
| # 拷贝构建产物到分支根目录 | |
| cp -R "../$DIST_DIR"/. . | |
| # 提交并强推(覆盖历史内容) | |
| git add -A | |
| git commit -m "docs: deploy vitepress to $DOCS_BRANCH [skip ci]" || echo "No changes to commit" | |
| git push origin "$DOCS_BRANCH" --force | |
| cd .. | |
| git worktree remove .deploy_docs_branch --force | |
| curl -v http://godothub.com:8000/konado/build-docs |