Skip to content

Commit d7aa0f1

Browse files
committed
fix ci
1 parent b6d5a5d commit d7aa0f1

5 files changed

Lines changed: 20 additions & 25 deletions

File tree

.github/workflows/publish.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ jobs:
3131
run: npm ci
3232

3333
- name: Build
34-
env:
35-
AppVersion: ${{ github.ref_name }}
36-
SimApiVersion: ${{ github.ref_name }}
37-
run: npm run build
34+
run: npm run build -- --define SimApiVersion="'${{github.ref_name}}'"
3835

3936
- name: Publish to npm
4037
run: npm publish --access public

AICONTEXT.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,21 @@ npm run build
108108

109109
**版本号注入:**
110110

111-
版本号通过 `vite.core.config.ts``define` 配置注入,从环境变量读取
111+
版本号通过 `vite.core.config.ts``define` 配置注入,从 npm config 读取
112112

113113
```typescript
114114
define: {
115-
'AppVersion': JSON.stringify(process.env.AppVersion || process.env.npm_config_AppVersion || '0.0.0-develop'),
116-
'SimApiVersion': JSON.stringify(process.env.SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
115+
'AppVersion': JSON.stringify(process.env.npm_config_AppVersion || '0.0.0-develop'),
116+
'SimApiVersion': JSON.stringify(process.env.npm_config_SimApiVersion || '0.0.0-develop'),
117117
}
118118
```
119119

120120
**本地构建示例:**
121121
```bash
122+
# 通过 npm config 传递(推荐)
123+
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
124+
125+
# 或通过环境变量
122126
# Windows PowerShell
123127
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
124128

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ npm link # 本地调试
338338

339339
**本地构建:**
340340
```bash
341+
# 通过 npm config 传递
342+
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
343+
344+
# 或设置环境变量后构建
341345
# Windows PowerShell
342346
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
343347

@@ -348,8 +352,8 @@ AppVersion=1.0.0 SimApiVersion=1.0.0 npm run build
348352
**CI/CD 构建版本号:**
349353
```bash
350354
env:
351-
AppVersion: ${VERSION}
352-
SimApiVersion: ${VERSION}
355+
AppVersion: ${{ github.ref_name }}
356+
SimApiVersion: ${{ github.ref_name }}
353357
```
354358

355359
如果未指定环境变量,版本号默认为 `0.0.0-develop`

src/simapi.core.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ async function fetchPost<T = any>(
7777

7878
export class SimApiCore {
7979
debug: boolean = true
80-
uiAppVersion?: string
81-
8280
auth: SimApiAuthConfig = {
8381
token_name: 'simapi-auth-token',
8482
check_url: '/auth/check',
@@ -210,8 +208,8 @@ export class SimApiCore {
210208
if (resp?.data) {
211209
const d = resp.data
212210
const versions: SimApiVersions = {
213-
uiApp: this.uiAppVersion ?? AppVersion,
214-
uiSimApi: SimApiVersion,
211+
uiApp: AppVersion ?? "0.0.0-develop",
212+
uiSimApi: SimApiVersion ?? "0.0.0-develop",
215213
apiApp: d.App?.split('+')[0] ?? '0.0.0',
216214
apiSimApi: d.SimApi?.split('+')[0] ?? '0.0.0',
217215
apiAppFull: d.App ?? '0.0.0',
@@ -226,8 +224,8 @@ export class SimApiCore {
226224
// 版本获取失败返回默认值
227225
}
228226
return {
229-
uiApp: AppVersion,
230-
uiSimApi: SimApiVersion,
227+
uiApp: "0.0.0-develop",
228+
uiSimApi: "0.0.0-develop",
231229
apiApp: '0.0.0',
232230
apiSimApi: '0.0.0',
233231
apiAppFull: '0.0.0',

vite.core.config.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from 'vite'
22

3-
export default defineConfig(({ mode }) => ({
3+
export default defineConfig({
44
build: {
55
outDir: 'dist',
66
emptyOutDir: true,
@@ -13,13 +13,5 @@ export default defineConfig(({ mode }) => ({
1313
rollupOptions: {
1414
// 不再需要 external,使用原生 fetch
1515
}
16-
},
17-
define: {
18-
// 版本号从环境变量读取,构建时传入:
19-
// npm run build:core -- --AppVersion=1.2.3 --SimApiVersion=2.3.4
20-
// 或:
21-
// AppVersion=1.2.3 SimApiVersion=2.3.4 npm run build:core
22-
'AppVersion': JSON.stringify(process.env.AppVersion || process.env.npm_config_AppVersion || '0.0.0-develop'),
23-
'SimApiVersion': JSON.stringify(process.env.SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
2416
}
25-
}))
17+
})

0 commit comments

Comments
 (0)