-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (115 loc) · 4.04 KB
/
Copy pathbuild-on-push.yml
File metadata and controls
136 lines (115 loc) · 4.04 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
name: Build on Push
on:
push:
branches:
- frontend-remake
pull_request:
branches:
- frontend-remake
workflow_dispatch: # 允许手动触发
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 9
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'
check-latest: true
- name: Verify installation
shell: bash
run: |
echo "Checking installations..."
node --version
npm --version
pnpm --version
echo "All installations verified."
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check version info
id: check-version
shell: bash
run: |
# 获取当前版本信息
CURRENT_PACKAGE_VERSION=$(jq -r .version package.json)
CURRENT_POLICY_VERSION=$(jq -r .policyVersion public/config/version.json)
CURRENT_APP_VERSION=$(jq -r .appVersion public/config/version.json)
echo "Current versions:"
echo " Package: $CURRENT_PACKAGE_VERSION"
echo " Policy: $CURRENT_POLICY_VERSION"
echo " App: $CURRENT_APP_VERSION"
# 尝试获取上一个提交的版本信息(如果存在)
if git log -n 1 --oneline > /dev/null 2>&1; then
PREV_PACKAGE_VERSION=$(git show HEAD~1:package.json 2>/dev/null | jq -r .version 2>/dev/null || echo "none")
PREV_POLICY_VERSION=$(git show HEAD~1:public/config/version.json 2>/dev/null | jq -r .policyVersion 2>/dev/null || echo "none")
PREV_APP_VERSION=$(git show HEAD~1:public/config/version.json 2>/dev/null | jq -r .appVersion 2>/dev/null || echo "none")
echo "Previous versions:"
echo " Package: $PREV_PACKAGE_VERSION"
echo " Policy: $PREV_POLICY_VERSION"
echo " App: $PREV_APP_VERSION"
# 检查版本变化(仅用于信息输出)
if [[ "$CURRENT_PACKAGE_VERSION" != "$PREV_PACKAGE_VERSION" ]]; then
echo "⚠️ Package version changed from $PREV_PACKAGE_VERSION to $CURRENT_PACKAGE_VERSION"
fi
if [[ "$CURRENT_POLICY_VERSION" != "$PREV_POLICY_VERSION" ]]; then
echo "⚠️ Policy version changed from $PREV_POLICY_VERSION to $CURRENT_POLICY_VERSION"
fi
if [[ "$CURRENT_APP_VERSION" != "$PREV_APP_VERSION" ]]; then
echo "⚠️ App version changed from $PREV_APP_VERSION to $CURRENT_APP_VERSION"
fi
else
echo "No previous commit found (first commit or shallow clone)"
fi
- name: Build SPA
run: |
# 构建SPA版本
echo "Building SPA version..."
pnpm run build
# 将SPA构建产物移动到spa-dist目录
mv dist spa-dist
echo "SPA build completed. Output directory: spa-dist/"
- name: Build SSG
run: |
# 构建SSG版本
echo "Building SSG version..."
pnpm run build:ssg
# 将SSG构建产物移动到ssg-dist目录
mv dist ssg-dist
echo "SSG build completed. Output directory: ssg-dist/"
- name: Upload SPA artifacts
uses: actions/upload-artifact@v4
with:
name: spa-dist
path: spa-dist/
retention-days: 7
- name: Upload SSG artifacts
uses: actions/upload-artifact@v4
with:
name: ssg-dist
path: ssg-dist/
retention-days: 7