Skip to content

Sync Stars

Sync Stars #121

Workflow file for this run

name: Sync Stars
on:
schedule:
- cron: '0 3 * * *' # 每天凌晨3点 UTC (北京时间11点)
workflow_dispatch:
inputs:
reason:
description: 'Reason for manual run'
required: false
default: 'Manual update'
permissions:
contents: write
jobs:
sync:
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 Stars
env:
GITHUB_TOKEN: ${{ secrets.STARS_PAT || secrets.GITHUB_TOKEN }}
run: node scripts/fetch-stars.js
- name: Check for changes
id: check
run: |
if git diff --quiet data/github-stars.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/github-stars.json
git commit -m "chore: sync stars [$(date +%Y-%m-%d)]"
git push
build-and-deploy:
needs: sync
if: needs.sync.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