-
Notifications
You must be signed in to change notification settings - Fork 13
174 lines (152 loc) · 5.37 KB
/
main.yml
File metadata and controls
174 lines (152 loc) · 5.37 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Build Hugo and Deploy
on:
push:
branches:
- main
schedule:
- cron: '0 0 1 * *'
workflow_dispatch:
repository_dispatch:
types: [build]
jobs:
build-deploy:
runs-on: ubuntu-latest
env:
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }}
COS_BUCKET: ${{ secrets.COS_CN_BUCKET }}
COS_SECRET_ID: ${{ secrets.SECRET_COS_ID }}
COS_SECRET_KEY: ${{ secrets.SECRET_COS_KEY }}
DIRECTUS_ACCESS_TOKEN: ${{ secrets.DIRECTUS_ACCESS_TOKEN }}
DIRECTUS_API_URL: ${{ secrets.DIRECTUS_API_URL }}
DIRECTUS_FILES_URL: ${{ secrets.DIRECTUS_FILES_URL }}
DIRECTUS_S3_URL: ${{ secrets.DIRECTUS_S3_URL }}
ESA_SITE_ID: ${{ secrets.ESA_SITE_ID }}
HUGOMODS_CACHEDIR: /tmp/.hugo_mods_cache
HUGO_CACHEDIR: /tmp/.hugo_cache
NEODB_ACCESS_TOKEN: ${{ secrets.NEODB_ACCESS_TOKEN }}
PNPM_CACHEDIR: /tmp/.pnpm-store
STEAM_WEB_API_KEY: ${{ secrets.STEAM_WEB_API_KEY }}
steps:
- uses: actions/checkout@v6
with:
submodules: recursive
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.161.1'
extended: false
- name: Cache Hugo Resources
uses: actions/cache@v5
id: cache-hugo
with:
path: |
resources/_gen
${{ env.HUGO_CACHEDIR }}
key: ${{ runner.os }}-hugo-${{ hashFiles('content/**', 'assets/**', 'layouts/**', 'config/**', 'static/**', 'pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-hugo-
- name: Cache Hugo Modules
uses: actions/cache@v5
with:
path: ${{ env.HUGOMODS_CACHEDIR }}
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugomod-
- name: Setup PNPM
uses: pnpm/action-setup@v5
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- name: Install Dependencies
run: |
pnpm install
# - name: Setup Aliyun CLI
# uses: aliyun/setup-aliyun-cli-action@v1
# with:
# version: "latest"
- name: Build Site
id: build
timeout-minutes: 5
run: |
echo "🔨 Starting build..."
echo "📚 Fetching full site data..."
# 使用 set +e 允许命令失败而不立即退出
set +e
# 执行 fetch 脚本,如果任何一个失败,FETCH_STATUS 将非 0
(
set -e
pnpm run directus:article
pnpm run directus:friendslinks
pnpm run directus:pages
pnpm run fetch:stats
)
FETCH_STATUS=$?
# 恢复 set -e
set -e
if [ $FETCH_STATUS -ne 0 ]; then
echo "⚠️ Data fetching failed. Skipping build and deployment."
echo "should_deploy=false" >> $GITHUB_OUTPUT
# 正常退出,保持 workflow 为绿色
exit 0
fi
# Build Hugo site
echo "🏗️ Building Hugo site..."
pnpm run gen:llms
pnpm run build:hugo
pnpm run build:pagefind
echo "✅ Build completed"
echo "should_deploy=true" >> $GITHUB_OUTPUT
- name: Deploy to Aliyun OSS
if: steps.build.outputs.should_deploy == 'true'
uses: docker://ghcr.io/eallion/aliyun-oss-website-action:v1
env:
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }}
BUCKET: eallion-com
ENDPOINT: oss-cn-shanghai.aliyuncs.com
FOLDER: public
SKIP_SETTING: true
INCREMENTAL: true
- name: "Purge Dogecloud CDN Cache"
uses: seatonjiang/dogecloud-cdn-action@main
with:
access_key: ${{ secrets.DOGECLOUD_ACCESS_KEY }}
secret_key: ${{ secrets.DOGECLOUD_SECRET_KEY }}
type: "path"
urls: "https://www.eallion.com/"
# - name: Deploy to Tencent COS
# if: steps.build.outputs.should_deploy == 'true'
# uses: eallion/s3-deploy-action@dev
# with:
# provider: tencent
# cos_secret_id: ${{ secrets.SECRET_COS_ID }}
# cos_secret_key: ${{ secrets.SECRET_COS_KEY }}
# cos_bucket: ${{ secrets.COS_CN_BUCKET }}
# cos_region: ap-shanghai
# folder: public
# incremental: true
# skipSetting: true
# - name: Configure Aliyun CLI
# run: |
# aliyun configure set --profile default \
# --mode "AK" \
# --access-key-id ${{ secrets.ACCESS_KEY_ID }} \
# --access-key-secret ${{ secrets.ACCESS_KEY_SECRET }} \
# --region cn-shanghai \
# --language zh
#
# - name: Purge Aliyun ESA
# if: steps.build.outputs.should_deploy == 'true'
# timeout-minutes: 10
# run: |
# echo "🗑️ Purging cache..."
# echo "📚 Full site purge - purging all cache..."
# aliyun esa PurgeCaches --SiteId ${{ secrets.ESA_SITE_ID }} --Type purgeall --Content '{"PurgeAll":true}'
# echo "✅ Cache purge completed"