-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (78 loc) · 2.21 KB
/
Copy pathupdate-projects.yml
File metadata and controls
92 lines (78 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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