更新数据并部署 #4348
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: 更新数据并部署 | |
| on: | |
| schedule: | |
| - cron: '17 * * * *' | |
| push: | |
| branches: [main, dev] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "deploy" | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| - uses: pnpm/action-setup@v3 | |
| with: | |
| version: 8.4.0 | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Type check | |
| run: pnpm typecheck | |
| - name: Restore previous feed data | |
| run: | | |
| mkdir -p public | |
| if git ls-remote --exit-code --heads origin deploy >/dev/null 2>&1; then | |
| git fetch origin deploy --depth=1 | |
| if git cat-file -e FETCH_HEAD:data 2>/dev/null; then | |
| rm -rf public/data | |
| git archive --format=tar FETCH_HEAD data | tar -x -C public | |
| echo "Restored $(find public/data -type f | wc -l | tr -d ' ') feed data files from deploy branch" | |
| else | |
| echo "No data directory found on deploy branch" | |
| fi | |
| else | |
| echo "No deploy branch found, skipping feed data restore" | |
| fi | |
| - name: Update RSS feeds | |
| run: pnpm update-feeds | |
| env: | |
| LLM_API_KEY: ${{ secrets.LLM_API_KEY }} | |
| LLM_API_BASE: ${{ secrets.LLM_API_BASE }} | |
| LLM_NAME: ${{ secrets.LLM_NAME }} | |
| - name: Build static site | |
| run: pnpm build | |
| - name: Copy vercel config to output | |
| run: cp vercel.json ./out/ | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: site-build | |
| path: ./out | |
| retention-days: 1 | |
| deploy-github-pages: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: site-build | |
| path: ./out | |
| - uses: actions/configure-pages@v4 | |
| - uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./out | |
| - id: deployment | |
| uses: actions/deploy-pages@v4 | |
| deploy-branch: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: site-build | |
| path: ./build-output | |
| - name: Deploy to deploy branch | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Always create a fresh orphan branch (no history) | |
| git checkout --orphan deploy-new | |
| # Remove all existing files | |
| git rm -rf . 2>/dev/null || true | |
| # Copy build output | |
| cp -r build-output/* . | |
| rm -rf build-output | |
| # Add and commit | |
| git add -A | |
| git commit -m "Deploy: $(date +'%Y-%m-%d %H:%M:%S')" | |
| # Force push to deploy branch (replaces all history) | |
| git push -f origin deploy-new:deploy |