-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (89 loc) · 2.68 KB
/
pages.yml
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
93
94
95
96
97
98
99
100
101
102
103
name: Build and Deploy Pages
on:
push:
branches: [ main ] # 假设您的主分支是 main
repository_dispatch:
types: [trigger-deploy]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MY_TOKEN }}
submodules: recursive
- name: Clone latest posts
env:
GH_PAT: ${{ secrets.MY_TOKEN }}
run: |
rm -rf source/_posts
git clone https://[email protected]/channinghsu/Blog-Post.git source/_posts
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # 使用 Node.js 20 LTS 版本
- name: Cache NPM dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
continue-on-error: true
- name: Check build output
run: |
if [ ! -d "public" ]; then
echo "Build failed: public directory not found"
exit 1
fi
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
- name: Checkout deploy repo
uses: actions/checkout@v4
with:
repository: channinghsu/blog_deploy
ref: gh-pages
token: ${{ secrets.MY_TOKEN }}
path: blog_deploy
- name: Copy build output to deploy repo
run: |
cp -r ./public/* blog_deploy/
- name: Commit and push changes to deploy repo
run: |
cd blog_deploy
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Deploy new static files - $(date +'%Y-%m-%d %H:%M:%S')"
git push origin gh-pages
deploy:
needs: build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
cleanup:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Cleanup workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ secrets.MY_TOKEN }}
repository: ${{ github.repository }}
retain_days: 30
keep_minimum_runs: 6