fix ci
Publish to npm / publish (push) Failing after 12s

This commit is contained in:
2026-04-08 01:45:53 +08:00
parent b6d5a5dbe1
commit d7aa0f171d
5 changed files with 20 additions and 25 deletions
+1 -4
View File
@@ -31,10 +31,7 @@ jobs:
run: npm ci
- name: Build
env:
AppVersion: ${{ github.ref_name }}
SimApiVersion: ${{ github.ref_name }}
run: npm run build
run: npm run build -- --define SimApiVersion="'${{github.ref_name}}'"
- name: Publish to npm
run: npm publish --access public
+7 -3
View File
@@ -108,17 +108,21 @@ npm run build
**版本号注入:**
版本号通过 `vite.core.config.ts``define` 配置注入,从环境变量读取:
版本号通过 `vite.core.config.ts``define` 配置注入,从 npm config 读取:
```typescript
define: {
'AppVersion': JSON.stringify(process.env.AppVersion || process.env.npm_config_AppVersion || '0.0.0-develop'),
'SimApiVersion': JSON.stringify(process.env.SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
'AppVersion': JSON.stringify(process.env.npm_config_AppVersion || '0.0.0-develop'),
'SimApiVersion': JSON.stringify(process.env.npm_config_SimApiVersion || '0.0.0-develop'),
}
```
**本地构建示例:**
```bash
# 通过 npm config 传递(推荐)
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
# 或通过环境变量
# Windows PowerShell
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
+6 -2
View File
@@ -338,6 +338,10 @@ npm link # 本地调试
**本地构建:**
```bash
# 通过 npm config 传递
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
# 或设置环境变量后构建
# Windows PowerShell
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
@@ -348,8 +352,8 @@ AppVersion=1.0.0 SimApiVersion=1.0.0 npm run build
**CI/CD 构建版本号:**
```bash
env:
AppVersion: ${VERSION}
SimApiVersion: ${VERSION}
AppVersion: ${{ github.ref_name }}
SimApiVersion: ${{ github.ref_name }}
```
如果未指定环境变量,版本号默认为 `0.0.0-develop`
+4 -6
View File
@@ -77,8 +77,6 @@ async function fetchPost<T = any>(
export class SimApiCore {
debug: boolean = true
uiAppVersion?: string
auth: SimApiAuthConfig = {
token_name: 'simapi-auth-token',
check_url: '/auth/check',
@@ -210,8 +208,8 @@ export class SimApiCore {
if (resp?.data) {
const d = resp.data
const versions: SimApiVersions = {
uiApp: this.uiAppVersion ?? AppVersion,
uiSimApi: SimApiVersion,
uiApp: AppVersion ?? "0.0.0-develop",
uiSimApi: SimApiVersion ?? "0.0.0-develop",
apiApp: d.App?.split('+')[0] ?? '0.0.0',
apiSimApi: d.SimApi?.split('+')[0] ?? '0.0.0',
apiAppFull: d.App ?? '0.0.0',
@@ -226,8 +224,8 @@ export class SimApiCore {
// 版本获取失败返回默认值
}
return {
uiApp: AppVersion,
uiSimApi: SimApiVersion,
uiApp: "0.0.0-develop",
uiSimApi: "0.0.0-develop",
apiApp: '0.0.0',
apiSimApi: '0.0.0',
apiAppFull: '0.0.0',
+2 -10
View File
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite'
export default defineConfig(({ mode }) => ({
export default defineConfig({
build: {
outDir: 'dist',
emptyOutDir: true,
@@ -13,13 +13,5 @@ export default defineConfig(({ mode }) => ({
rollupOptions: {
// 不再需要 external,使用原生 fetch
}
},
define: {
// 版本号从环境变量读取,构建时传入:
// npm run build:core -- --AppVersion=1.2.3 --SimApiVersion=2.3.4
// 或:
// AppVersion=1.2.3 SimApiVersion=2.3.4 npm run build:core
'AppVersion': JSON.stringify(process.env.AppVersion || process.env.npm_config_AppVersion || '0.0.0-develop'),
'SimApiVersion': JSON.stringify(process.env.SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
}
}))
})