Merge pull request #12 from muxiaoxiong/main #49
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 VitePress site to Pages | |
on: | |
# 在推送到 main 分支时触发 | |
push: | |
branches: | |
- main | |
# 允许手动触发工作流 | |
workflow_dispatch: | |
# 设置 GITHUB_TOKEN 的权限,允许部署到 gh-pages 分支 | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
# 只允许一个并发部署,跳过正在运行和最新队列之间的运行队列 | |
# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成 | |
concurrency: | |
group: pages | |
cancel-in-progress: false | |
jobs: | |
# 构建和部署工作 | |
build-and-deploy: | |
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: 18 | |
cache: npm | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests python-dotenv | |
- name: Install Node dependencies | |
run: npm ci | |
- name: Check if data exists | |
id: check-data | |
run: | | |
if [ -f "docs/public/data/members.json" ]; then | |
echo "data-exists=true" >> $GITHUB_OUTPUT | |
echo "✅ 使用现有数据文件" | |
else | |
echo "data-exists=false" >> $GITHUB_OUTPUT | |
echo "⚠️ 数据文件不存在,将拉取新数据" | |
fi | |
- name: Fetch latest member data (only if no data exists) | |
if: steps.check-data.outputs.data-exists == 'false' | |
run: python scripts/fetch_members/fetch_members.py | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITHUB_ORG: datawhalechina | |
continue-on-error: true | |
- name: Clean build cache | |
run: | | |
rm -rf docs/.vitepress/.temp | |
rm -rf docs/.vitepress/cache | |
rm -rf docs/.vitepress/dist | |
- name: Build with VitePress (with timeout protection) | |
timeout-minutes: 10 | |
run: | | |
echo "开始构建 (最大10分钟超时)..." | |
npm run docs:build | |
env: | |
NODE_ENV: production | |
- name: Deploy to gh-pages | |
uses: peaceiris/actions-gh-pages@v3 | |
if: github.ref == 'refs/heads/main' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: docs/.vitepress/dist | |
publish_branch: gh-pages | |
force_orphan: true | |
user_name: 'github-actions[bot]' | |
user_email: 'github-actions[bot]@users.noreply.github.com' | |
commit_message: 'Deploy to gh-pages from ${{ github.sha }}' |