forked from seasalt-haiyan/OxygenBlogPlatform
-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (85 loc) · 2.82 KB
/
deploy.yml
File metadata and controls
98 lines (85 loc) · 2.82 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
name: Deploy to GitHub Pages
# 触发条件:推送到main分支或手动触发
on:
push:
branches: [ main ]
# 允许手动触发
workflow_dispatch:
# 设置权限
permissions:
contents: read
pages: write
id-token: write
# 确保只有一个部署任务同时运行
concurrency:
group: "pages"
cancel-in-progress: false
# 全局环境变量 - 强制使用 Node.js 24
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
# 构建任务
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Prepare for static export
run: |
# 删除本地环境文件,避免覆盖 GitHub Actions 的环境变量
rm -f .env.local
# 注意:不再创建 src/actions/index.ts 空实现文件
# 因为 momentActions.ts、todoActions.ts、backupActions.ts 等文件
# 已经内置了静态导出模式检测 (isStaticExport),会自动返回空实现
echo "静态导出准备完成:使用内置的静态导出模式检测"
- name: Build project
env:
# 设置GitHub Actions环境变量 - 使用 env 块确保变量被正确传递
NODE_ENV: production
NEXT_PUBLIC_GITHUB_REPO_NAME: ${{ github.event.repository.name }}
NEXT_PRIVATE_STATIC_EXPORT: "true"
STATIC_EXPORT: "true"
CUSTOM_DOMAIN: "true"
NEXT_PUBLIC_SITE_URL: "https://blog.xinchengp.cn"
NEXT_PUBLIC_BASE_PATH: ""
run: |
# 输出构建环境信息
echo "构建环境信息:"
echo "NODE_ENV: $NODE_ENV"
echo "NEXT_PUBLIC_GITHUB_REPO_NAME: $NEXT_PUBLIC_GITHUB_REPO_NAME"
echo "NEXT_PUBLIC_BASE_PATH: $NEXT_PUBLIC_BASE_PATH"
echo "NEXT_PUBLIC_SITE_URL: $NEXT_PUBLIC_SITE_URL"
echo "CUSTOM_DOMAIN: $CUSTOM_DOMAIN"
echo "NEXT_PRIVATE_STATIC_EXPORT: $NEXT_PRIVATE_STATIC_EXPORT"
echo "STATIC_EXPORT: $STATIC_EXPORT"
# 执行构建(使用 build:pages 脚本,会自动替换 actions 文件)
npm run build:pages
- name: Setup Pages
uses: actions/configure-pages@v4
with:
static_site_generator: next
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./out
# 部署任务
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
permissions:
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4