Daily Data Update #41
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: Daily Data Update | |
on: | |
# 每日 22:00 UTC 自动运行(北京时间凌晨 6:00) | |
schedule: | |
- cron: '0 22 * * *' | |
# 允许手动触发 | |
workflow_dispatch: | |
# 设置权限 | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
jobs: | |
update-data-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 | |
- 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.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: Fetch latest member data | |
run: python scripts/fetch_members/fetch_members.py | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITHUB_ORG: datawhalechina | |
- name: Check for data changes | |
id: check-changes | |
run: | | |
git add -A | |
if git diff --cached --quiet; then | |
echo "No changes in member data or avatars" | |
echo "changes=false" >> $GITHUB_OUTPUT | |
else | |
echo "Member data or avatars have changed" | |
echo "changes=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit updated data | |
if: steps.check-changes.outputs.changes == 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add docs/public/data/members.json docs/public/data/commits_weekly.json docs/public/avatars/ | |
git commit -m "🤖 Auto-update member data and avatars - $(date -u '+%Y-%m-%d %H:%M:%S UTC')" | |
git push | |
- name: Build with VitePress | |
if: steps.check-changes.outputs.changes == 'true' | |
run: npm run docs:build | |
env: | |
NODE_ENV: production | |
- name: Deploy to gh-pages | |
if: steps.check-changes.outputs.changes == 'true' | |
uses: peaceiris/actions-gh-pages@v3 | |
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: 'Auto-update and deploy from daily data sync - ${{ github.sha }}' | |
- name: Create summary | |
run: | | |
echo "## 📊 Daily Data Update Summary" >> $GITHUB_STEP_SUMMARY | |
echo "- **Date**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY | |
if [ "${{ steps.check-changes.outputs.changes }}" == "true" ]; then | |
echo "- **Status**: ✅ Data updated and site redeployed" >> $GITHUB_STEP_SUMMARY | |
echo "- **Changes**: Member data has been updated" >> $GITHUB_STEP_SUMMARY | |
else | |
echo "- **Status**: ℹ️ No changes detected" >> $GITHUB_STEP_SUMMARY | |
echo "- **Changes**: Member data is up to date" >> $GITHUB_STEP_SUMMARY | |
fi |