Daily Report & Deploy #30
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 Report & Deploy | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # 每天 UTC 00:00 | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: pages | |
| cancel-in-progress: false | |
| env: | |
| PYTHON_VERSION: '3.11' | |
| NODE_VERSION: '20' | |
| jobs: | |
| # Job 1: 生成报告(仅定时或手动触发) | |
| generate-report: | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: 📅 Get date | |
| id: date | |
| run: | | |
| echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT | |
| echo "year=$(date +%Y)" >> $GITHUB_OUTPUT | |
| echo "month=$(date +%m)" >> $GITHUB_OUTPUT | |
| - name: 🐍 Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: 📦 Install Python dependencies | |
| run: pip install -r requirements.txt | |
| - name: 🚀 Generate report | |
| env: | |
| LLM_API_KEY: ${{ secrets.LLM_API_KEY }} | |
| LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }} | |
| LLM_MODEL: ${{ secrets.LLM_MODEL }} | |
| GITHUB_API_TOKEN: ${{ secrets.GITHUB_API_TOKEN }} | |
| run: python main.py --local --no-push | |
| - name: 📁 Move output to reports | |
| run: | | |
| DATE=${{ steps.date.outputs.date }} | |
| YEAR=${{ steps.date.outputs.year }} | |
| MONTH=${{ steps.date.outputs.month }} | |
| mkdir -p reports/$YEAR/$MONTH data/$YEAR/$MONTH | |
| cp output/$DATE.md reports/$YEAR/$MONTH/ 2>/dev/null || true | |
| cp output/$DATE.json data/$YEAR/$MONTH/ 2>/dev/null || true | |
| - name: 📤 Commit and push | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add reports/ data/ | |
| git diff --staged --quiet || git commit -m "📈 Add report for ${{ steps.date.outputs.date }}" | |
| git push | |
| # Job 2: 构建部署网站 | |
| build-deploy: | |
| runs-on: ubuntu-latest | |
| needs: [generate-report] | |
| if: always() && (needs.generate-report.result == 'success' || needs.generate-report.result == 'skipped') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: 🔄 Pull latest changes | |
| run: git pull origin main | |
| - name: 🟢 Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| - name: 📦 Install dependencies | |
| run: npm install | |
| - name: 🔧 Generate sidebar | |
| run: npm run generate-sidebar | |
| - name: 🏗️ Build | |
| run: npm run build | |
| - name: 📤 Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: build | |
| # Job 3: 部署到 GitHub Pages | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build-deploy | |
| steps: | |
| - name: 🚀 Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |