Update Projects #131
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: Update Projects | |
| on: | |
| schedule: | |
| - cron: '0 4 * * *' # 每天凌晨4点 UTC (北京时间12点),比 stars 晚1小时 | |
| workflow_dispatch: | |
| inputs: | |
| reason: | |
| description: 'Reason for manual run' | |
| required: false | |
| default: 'Manual update' | |
| permissions: | |
| contents: write | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changed: ${{ steps.check.outputs.changed }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Fetch Projects | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: node scripts/fetch-projects.js | |
| - name: Check for changes | |
| id: check | |
| run: | | |
| if git diff --quiet data/projects.json 2>/dev/null; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "No changes detected" | |
| else | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "Changes detected" | |
| fi | |
| - name: Commit and push | |
| if: steps.check.outputs.changed == 'true' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add data/projects.json | |
| git commit -m "chore: update projects list [$(date +%Y-%m-%d)]" | |
| git push | |
| build-and-deploy: | |
| needs: update | |
| if: needs.update.outputs.changed == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build website | |
| run: pnpm run build | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: './build' | |
| - name: Deploy to GitHub Pages | |
| uses: actions/deploy-pages@v4 |