Skip to content

Build and Deploy to GitHub Pages #117

Build and Deploy to GitHub Pages

Build and Deploy to GitHub Pages #117

Workflow file for this run

name: Build and Deploy to GitHub Pages
on:
push:
branches: [ main ]
workflow_dispatch:
repository_dispatch:
types: [submodule-update]
schedule:
- cron: '0 2 * * *'
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 repository
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Update submodule and generate directories
run: |
echo "🔄 更新 submodule..."
git submodule update --init --recursive --remote
echo "📋 检查子模块状态..."
git submodule status
echo "🚀 生成目录数据..."
npm run generate
echo "📊 检查生成的文件..."
ls -la public/directories.json
- name: Commit generated files and submodule updates
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
# 检查是否有变化
if [ -n "$(git status --porcelain)" ]; then
echo "📝 发现文件变化,提交更新..."
git add .
git commit -m "🤖 自动更新子模块和目录数据 [skip ci]"
git push
echo "✅ 已提交生成的文件和子模块更新"
else
echo "ℹ️ 没有文件变化,跳过提交"
fi
- name: Build application
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './dist'
- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v4