diff --git a/.env.production b/.env.production new file mode 100644 index 00000000..62aba29d --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_SENTRY_RELEASE=TeyvatGuide@0.9.0_0c8eda3f_windows diff --git a/.gitignore b/.gitignore index 62ca8b72..11126eab 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ dist *.tsbuildinfo # Sentry Config File -.env.sentry-build-plugin +.env.development.local \ No newline at end of file diff --git a/.sentryclirc b/.sentryclirc new file mode 100644 index 00000000..de060353 --- /dev/null +++ b/.sentryclirc @@ -0,0 +1,3 @@ +[defaults] +org = teyvat-guide +project = teyvat-guide diff --git a/package.json b/package.json index b2a807e0..64a68b76 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "packageManager": "pnpm@10.26.2", "type": "module", "scripts": { - "build": "tauri build", + "build": "tsx scripts/auto-build.ts", "debug": "tauri build --debug", "dev": "tauri dev --exit-on-panic", "eslint:pre": "pnpx @eslint/config-inspector@latest", @@ -119,6 +119,7 @@ "@vitejs/plugin-vue": "^6.0.3", "app-root-path": "^3.1.0", "concurrently": "^9.2.1", + "envfile": "^7.1.0", "eslint": "^9.39.2", "eslint-plugin-import": "^2.32.0", "eslint-plugin-jsonc": "^2.21.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6a94b79f..feb82833 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -150,6 +150,9 @@ importers: concurrently: specifier: ^9.2.1 version: 9.2.1 + envfile: + specifier: ^7.1.0 + version: 7.1.0 eslint: specifier: ^9.39.2 version: 9.39.2(jiti@2.6.1) @@ -2118,6 +2121,11 @@ packages: resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==} engines: {node: '>=6'} + envfile@7.1.0: + resolution: {integrity: sha512-dyH4QnnZsArCLhPASr29eqBWDvKpq0GggQFTmysTT/S9TTmt1JrEKNvTBc09Cd7ujVZQful2HBGRMe2agu7Krg==} + engines: {node: '>=8'} + hasBin: true + environment@1.1.0: resolution: {integrity: sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==} engines: {node: '>=18'} @@ -6253,6 +6261,8 @@ snapshots: env-paths@2.2.1: {} + envfile@7.1.0: {} + environment@1.1.0: {} error-ex@1.3.4: diff --git a/scripts/auto-build.ts b/scripts/auto-build.ts new file mode 100644 index 00000000..c361cbf3 --- /dev/null +++ b/scripts/auto-build.ts @@ -0,0 +1,61 @@ +/** + * 本地构建脚本 + * @since Beta v0.9.1 + */ +import { resolve } from "path"; +import { fileURLToPath } from "node:url"; +import pkgJson from "../package.json" with { type: "json" }; +import { execSync } from "child_process"; +import { parse, stringify } from "envfile"; +import { readFileSync, writeFileSync } from "fs"; + +const __dirname = resolve(fileURLToPath(import.meta.url), "../"); + +// 判断是否GithubAction +const isGitHubActions = process.env.GITHUB_ACTIONS === "true"; + +// 获取版本 +const pkgVersion = pkgJson.version; + +// 获取提交哈希 +const commitHash = execSync("git rev-parse --short HEAD").toString().trim(); + +// 获取当前平台 +let platform = "unknown"; +if (process.platform === "win32") { + platform = "windows"; +} else if (process.platform === "darwin") { + platform = process.arch === "arm64" ? "macos-arm" : "macos-intel"; +} else { + platform = `${process.platform}-${process.arch}`; +} + +// 构建 Release 字符串 +const release = `TeyvatGuide@${pkgVersion}_${commitHash}_${platform}`; +console.log(`🍄 gen sentry release ${release}`); + +// 修改 .env.production +const envPath = resolve(__dirname, "../.env.production"); +const envRead = parse(readFileSync(envPath, "utf-8")); +envRead.VITE_SENTRY_RELEASE = release; +writeFileSync(envPath, stringify(envRead), "utf-8"); +console.log("✅ .env.production updated!"); + +// 执行 pnpm build +execSync("pnpm tauri build", { stdio: "inherit" }); + +// 上传pdb +if (isGitHubActions) { + process.exit(); +} +const pdbGlob = "src-tauri/target/release/TeyvatGuide.pdb"; +try { + console.log(`📦 Uploading PDBs from ${pdbGlob}...`); + execSync(`sentry-cli releases new "${release}"`, { stdio: "inherit" }); + execSync(`sentry-cli upload-dif ${pdbGlob}`, { stdio: "inherit" }); + execSync(`sentry-cli releases finalize "${release}"`, { stdio: "inherit" }); + console.log("✅ PDB upload complete!"); +} catch (err) { + console.error("❌ Failed to upload PDBs:", err); + process.exit(1); +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 70e3adfa..7f4d5579 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,19 +1,17 @@ -//! @file src/main.rs -//! @desc 主模块,用于启动应用 -//! @since Beta v0.7.2 +// 主模块,用于启动应用 +// @since Beta v0.9.1 // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { let _guard = sentry::init(( - "https://8d59057c08ff381e1fccf3c9e97c6a6c@o4510617609175040.ingest.de.sentry.io/4510617659506768", - sentry::ClientOptions { - release: sentry::release_name!(), - // Capture user IPs and potentially sensitive headers when using HTTP server integrations - // see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info - send_default_pii: true, - ..Default::default() - })); + "https://8d59057c08ff381e1fccf3c9e97c6a6c@o4510617609175040.ingest.de.sentry.io/4510617659506768", + sentry::ClientOptions { + release: sentry::release_name!().into(), + send_default_pii: true, + ..Default::default() + })); + teyvat_guide_lib::run() } diff --git a/src/App.vue b/src/App.vue index 2c4e3ed0..2b2285d1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -28,7 +28,6 @@ import type { Event, UnlistenFn } from "@tauri-apps/api/event"; import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window"; import { mkdir } from "@tauri-apps/plugin-fs"; import { openUrl } from "@tauri-apps/plugin-opener"; -import { getBuildTime } from "@utils/TGBuild.js"; import TGLogger from "@utils/TGLogger.js"; import { getWindowSize, resizeWindow } from "@utils/TGWindow.js"; import { storeToRefs } from "pinia"; @@ -384,7 +383,8 @@ async function checkUpdate(): Promise { showSnackbar.error("请到设置页手动更新数据库!", 3000); return; } - buildTime.value = getBuildTime(); + // @ts-expect-error import.meta + buildTime.value = import.meta.env.VITE_SENTRY_RELEASE; await TGSqlite.update(); showSnackbar.success("数据库已更新!", 3000); await openUrl("https://app.btmuli.ink/docs/TeyvatGuide/changelogs.html"); diff --git a/src/main.ts b/src/main.ts index 077fffea..eedcab2e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,8 +8,6 @@ import * as Sentry from "@sentry/vue"; import { createApp } from "vue"; import { createVuetify } from "vuetify"; -import pkgJson from "../package.json" with { type: "json" }; - import App from "./App.vue"; import router from "./router/index.js"; import store from "./store/index.js"; @@ -23,7 +21,7 @@ const app = createApp(App); Sentry.init({ app, dsn: "https://8d59057c08ff381e1fccf3c9e97c6a6c@o4510617609175040.ingest.de.sentry.io/4510617659506768", - release: `TeyvatGuide@${pkgJson.version}`, + release: import.meta.env.VITE_SENTRY_RELEASE, enableLogs: true, integrations: [ Sentry.feedbackAsyncIntegration({ diff --git a/src/pages/common/PageConfig.vue b/src/pages/common/PageConfig.vue index eede6369..655002c9 100644 --- a/src/pages/common/PageConfig.vue +++ b/src/pages/common/PageConfig.vue @@ -37,7 +37,7 @@ {{ deviceInfo.device_name }}({{ deviceInfo.product }}) - {{ deviceInfo.device_fp }} @@ -64,7 +64,7 @@ - +