|
1 | | -name: Daily GitHub Trending Report |
| 1 | +name: Daily Report & Deploy |
2 | 2 |
|
3 | 3 | on: |
4 | | - # Run daily at 00:00 UTC (08:00 Beijing Time) |
5 | 4 | schedule: |
6 | | - - cron: '0 0 * * *' |
7 | | - |
8 | | - # Allow manual trigger |
| 5 | + - cron: '0 0 * * *' # 每天 UTC 00:00 |
9 | 6 | workflow_dispatch: |
10 | | - inputs: |
11 | | - language: |
12 | | - description: 'Programming language filter (leave empty for all)' |
13 | | - required: false |
14 | | - default: '' |
15 | | - since: |
16 | | - description: 'Time range (daily, weekly, monthly)' |
17 | | - required: false |
18 | | - default: 'daily' |
19 | | - analysis_type: |
20 | | - description: 'Analysis type (comprehensive, brief, technical)' |
21 | | - required: false |
22 | | - default: 'comprehensive' |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pages: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: pages |
| 17 | + cancel-in-progress: false |
23 | 18 |
|
24 | 19 | env: |
25 | 20 | PYTHON_VERSION: '3.11' |
| 21 | + NODE_VERSION: '20' |
26 | 22 |
|
27 | 23 | jobs: |
| 24 | + # Job 1: 生成报告(仅定时或手动触发) |
28 | 25 | generate-report: |
| 26 | + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
29 | 27 | runs-on: ubuntu-latest |
30 | | - |
31 | 28 | steps: |
32 | | - - name: 📥 Checkout repository |
33 | | - uses: actions/checkout@v4 |
| 29 | + - uses: actions/checkout@v4 |
34 | 30 |
|
35 | | - - name: 🐍 Set up Python |
| 31 | + - name: 🐍 Setup Python |
36 | 32 | uses: actions/setup-python@v5 |
37 | 33 | with: |
38 | 34 | python-version: ${{ env.PYTHON_VERSION }} |
39 | | - cache: 'pip' |
40 | 35 |
|
41 | | - - name: 📦 Install dependencies |
42 | | - run: | |
43 | | - python -m pip install --upgrade pip |
44 | | - pip install -r requirements.txt |
| 36 | + - name: 📦 Install Python dependencies |
| 37 | + run: pip install -r requirements.txt |
45 | 38 |
|
46 | | - - name: 🚀 Generate trending report |
| 39 | + - name: 🚀 Generate report |
47 | 40 | env: |
48 | 41 | LLM_API_KEY: ${{ secrets.LLM_API_KEY }} |
49 | 42 | LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }} |
50 | 43 | LLM_MODEL: ${{ secrets.LLM_MODEL }} |
51 | 44 | GITHUB_API_TOKEN: ${{ secrets.GITHUB_API_TOKEN }} |
52 | | - GITHUB_TOKEN: ${{ secrets.DATA_REPO_TOKEN }} |
53 | | - DATA_REPO_OWNER: ${{ github.repository_owner }} |
54 | | - DATA_REPO_NAME: github-trending-reporter-data |
| 45 | + run: python main.py --local --no-push |
| 46 | + |
| 47 | + - name: 📁 Move output to reports |
55 | 48 | run: | |
56 | | - # Set language filter if provided |
57 | | - LANGUAGE_ARG="" |
58 | | - if [ -n "${{ github.event.inputs.language }}" ]; then |
59 | | - LANGUAGE_ARG="-l ${{ github.event.inputs.language }}" |
| 49 | + DATE=$(date +%Y-%m-%d) |
| 50 | + YEAR=$(date +%Y) |
| 51 | + MONTH=$(date +%m) |
| 52 | + mkdir -p reports/$YEAR/$MONTH data/$YEAR/$MONTH |
| 53 | + if [ -f output/$DATE.md ]; then |
| 54 | + cp output/$DATE.md reports/$YEAR/$MONTH/ |
| 55 | + fi |
| 56 | + if [ -f output/$DATE.json ]; then |
| 57 | + cp output/$DATE.json data/$YEAR/$MONTH/ |
60 | 58 | fi |
61 | | - |
62 | | - # Set since filter (use input or default) |
63 | | - SINCE_ARG="-s ${{ github.event.inputs.since || 'daily' }}" |
64 | | - |
65 | | - # Set analysis type (use input or default) |
66 | | - ANALYSIS_ARG="-a ${{ github.event.inputs.analysis_type || 'comprehensive' }}" |
67 | | - |
68 | | - # Run the report generator |
69 | | - python main.py $LANGUAGE_ARG $SINCE_ARG $ANALYSIS_ARG --local |
70 | | - |
71 | | - - name: 📤 Upload artifacts |
72 | | - uses: actions/upload-artifact@v4 |
73 | | - with: |
74 | | - name: trending-report-${{ github.run_id }} |
75 | | - path: output/ |
76 | | - retention-days: 30 |
77 | 59 | |
78 | | - - name: 📊 Report summary |
| 60 | + - name: 📤 Commit and push |
79 | 61 | run: | |
80 | | - echo "## 📈 GitHub Trending Report" >> $GITHUB_STEP_SUMMARY |
81 | | - echo "" >> $GITHUB_STEP_SUMMARY |
82 | | - echo "Report generated successfully!" >> $GITHUB_STEP_SUMMARY |
83 | | - echo "" >> $GITHUB_STEP_SUMMARY |
84 | | - if [ -f "output/*.md" ]; then |
85 | | - echo "### Report Preview" >> $GITHUB_STEP_SUMMARY |
86 | | - head -50 output/*.md >> $GITHUB_STEP_SUMMARY |
87 | | - fi |
| 62 | + git config user.name "github-actions[bot]" |
| 63 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 64 | + git add reports/ data/ |
| 65 | + git diff --staged --quiet || git commit -m "📈 Add report for $(date +%Y-%m-%d)" |
| 66 | + git push |
88 | 67 |
|
89 | | - # Optional: Generate reports for specific languages |
90 | | - generate-language-reports: |
| 68 | + # Job 2: 构建部署网站 |
| 69 | + build-deploy: |
91 | 70 | runs-on: ubuntu-latest |
92 | | - if: github.event_name == 'schedule' |
93 | | - needs: generate-report |
94 | | - |
95 | | - strategy: |
96 | | - matrix: |
97 | | - language: [python, javascript, typescript, go, rust] |
98 | | - fail-fast: false |
99 | | - |
| 71 | + needs: [generate-report] |
| 72 | + if: always() && (needs.generate-report.result == 'success' || needs.generate-report.result == 'skipped') |
100 | 73 | steps: |
101 | | - - name: 📥 Checkout repository |
102 | | - uses: actions/checkout@v4 |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + with: |
| 76 | + ref: main |
| 77 | + fetch-depth: 0 |
103 | 78 |
|
104 | | - - name: 🐍 Set up Python |
105 | | - uses: actions/setup-python@v5 |
| 79 | + - name: 🔄 Pull latest changes |
| 80 | + run: git pull origin main |
| 81 | + |
| 82 | + - name: 🟢 Setup Node.js |
| 83 | + uses: actions/setup-node@v4 |
106 | 84 | with: |
107 | | - python-version: ${{ env.PYTHON_VERSION }} |
108 | | - cache: 'pip' |
| 85 | + node-version: ${{ env.NODE_VERSION }} |
109 | 86 |
|
110 | 87 | - name: 📦 Install dependencies |
111 | | - run: | |
112 | | - python -m pip install --upgrade pip |
113 | | - pip install -r requirements.txt |
| 88 | + run: npm install |
114 | 89 |
|
115 | | - - name: 🚀 Generate ${{ matrix.language }} trending report |
116 | | - env: |
117 | | - LLM_API_KEY: ${{ secrets.LLM_API_KEY }} |
118 | | - LLM_BASE_URL: ${{ secrets.LLM_BASE_URL }} |
119 | | - LLM_MODEL: ${{ secrets.LLM_MODEL }} |
120 | | - GITHUB_API_TOKEN: ${{ secrets.GITHUB_API_TOKEN }} |
121 | | - GITHUB_TOKEN: ${{ secrets.DATA_REPO_TOKEN }} |
122 | | - DATA_REPO_OWNER: ${{ github.repository_owner }} |
123 | | - DATA_REPO_NAME: github-trending-reporter-data |
124 | | - run: | |
125 | | - python main.py -l ${{ matrix.language }} -a brief --local |
126 | | - continue-on-error: true |
| 90 | + - name: 🔧 Generate sidebar |
| 91 | + run: npm run generate-sidebar |
| 92 | + |
| 93 | + - name: 🏗️ Build |
| 94 | + run: npm run build |
127 | 95 |
|
128 | | - - name: 📤 Upload artifacts |
129 | | - uses: actions/upload-artifact@v4 |
| 96 | + - name: 📤 Upload artifact |
| 97 | + uses: actions/upload-pages-artifact@v3 |
130 | 98 | with: |
131 | | - name: trending-report-${{ matrix.language }}-${{ github.run_id }} |
132 | | - path: output/ |
133 | | - retention-days: 30 |
| 99 | + path: build |
| 100 | + |
| 101 | + deploy: |
| 102 | + environment: |
| 103 | + name: github-pages |
| 104 | + url: ${{ steps.deployment.outputs.page_url }} |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: build-deploy |
| 107 | + steps: |
| 108 | + - name: 🚀 Deploy to GitHub Pages |
| 109 | + id: deployment |
| 110 | + uses: actions/deploy-pages@v4 |
0 commit comments