From 1aeac29f3829231830e39dda8036828f0ad5c71f Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:35:50 +1000 Subject: [PATCH 1/8] feat: add CI/CD information display in PreferencePanel and support for environment variables --- .gitea/workflows/workflow.yaml | 6 +++++ .gitignore | 3 +++ public/background.js | 29 ++++++++++++++++-------- src/components/PreferencePanel.vue | 36 ++++++++++++++++++++++++++++-- src/utils/cicdInfo.ts | 4 ++++ src/utils/index.ts | 3 ++- 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 src/utils/cicdInfo.ts diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index 7fb3e0b..555fa33 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -8,6 +8,9 @@ jobs: build-for-chrome: name: 构建 Chrome 扩展程序 runs-on: ubuntu-latest + env: + VITE_RUN_ID: ${{ gitea.run_id }} + VITE_HASH_ID: ${{ gitea.sha | slice(0, 7) }} steps: - uses: actions/checkout@v3 @@ -33,6 +36,9 @@ jobs: build-for-firefox: name: 构建 Firefox 附加组件 runs-on: ubuntu-latest + env: + VITE_RUN_ID: ${{ gitea.run_id }} + VITE_HASH_ID: ${{ gitea.sha | slice(0, 7) }} steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index a547bf3..ce0d618 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ dist-ssr *.njsproj *.sln *.sw? + +.env +.env.local \ No newline at end of file diff --git a/public/background.js b/public/background.js index c1e4463..4b009eb 100644 --- a/public/background.js +++ b/public/background.js @@ -1,6 +1,9 @@ console.log("aaaa") -browser.webRequest.onBeforeRequest.addListener( +// 兼容 Chrome 和 Firefox +const browserAPI = typeof browser !== 'undefined' ? browser : chrome; + +browserAPI.webRequest.onBeforeRequest.addListener( async (details) => { console.log( 'onBeforeRequest MAIN_FRAME:', @@ -11,27 +14,35 @@ browser.webRequest.onBeforeRequest.addListener( ) console.log('recived request for fontset api, redirecting to index.html') - const pref = await browser.storage.sync.get('preferences') + const pref = await browserAPI.storage.sync.get('preferences') if (pref === undefined || pref.preferences === undefined || pref.preferences.autoRedirect === undefined || pref.preferences.autoRedirect === true) { - const isChrome = typeof browser.runtime.getBrowserInfo === 'undefined'; + const isChrome = typeof browserAPI.runtime.getBrowserInfo === 'undefined'; if (isChrome) { - browser.tabs.create({ url: browser.runtime.getURL('index.html') }) - browser.tabs.remove(details.tabId) + if ( + details.url === 'https://monster-siren.hypergryph.com/manifest.json' && + details.type === 'other' && + details.frameId === 0 + ) { + const pref = await chrome.storage.sync.get('preferences') + + chrome.tabs.create({ url: chrome.runtime.getURL('index.html') }) + chrome.tabs.remove(details.tabId) + } } else { // Firefox: 直接在当前标签页导航 - browser.tabs.update(details.tabId, { url: browser.runtime.getURL('index.html') }) + browserAPI.tabs.update(details.tabId, { url: browserAPI.runtime.getURL('index.html') }) } } }, - { urls: ['https://monster-siren.hypergryph.com/api/fontset'] }, + { urls: ['https://monster-siren.hypergryph.com/api/fontset', 'https://monster-siren.hypergryph.com/manifest.json'] }, ) // 兼容新旧版本的 API -const actionAPI = browser.action || browser.browserAction; +const actionAPI = browserAPI.action || browserAPI.browserAction; if (actionAPI) { actionAPI.onClicked.addListener(() => { - browser.tabs.create({ url: browser.runtime.getURL('index.html') }) + browserAPI.tabs.create({ url: browserAPI.runtime.getURL('index.html') }) }) } \ No newline at end of file diff --git a/src/components/PreferencePanel.vue b/src/components/PreferencePanel.vue index 73238d2..ef58750 100644 --- a/src/components/PreferencePanel.vue +++ b/src/components/PreferencePanel.vue @@ -3,10 +3,10 @@ import XIcon from '../assets/icons/x.vue' import { usePreferences } from '../stores/usePreferences' import { computed } from 'vue' +import { cicdInfo } from '../utils' const preferences = usePreferences() - defineProps<{ present: boolean }>() @@ -103,7 +103,7 @@ const version = computed(() => { -
即使此项目关闭,随时都可以通过点按 MSR Mod 扩展图标启动 MSR Mod。
+
即使此项目关闭,随时都可以通过点按 MSR Mod 扩展图标启动 MSR Mod。
@@ -133,6 +133,38 @@ const version = computed(() => { + +
+
+
构建信息
+ +
MSR Mod 使用 Gitea Actions 完成打包与自动商店提交工作。此信息用于确认 MSR Mod 的 + CI/CD 构建版本信息,以及当前构建代码是否被篡改。
+
+
diff --git a/src/utils/cicdInfo.ts b/src/utils/cicdInfo.ts new file mode 100644 index 0000000..2d47548 --- /dev/null +++ b/src/utils/cicdInfo.ts @@ -0,0 +1,4 @@ +export default { + runId: import.meta.env.VITE_RUN_ID ?? '未知', + hashId: import.meta.env.VITE_HASH_ID ?? '未知', +} \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index 6b0c702..08ff66e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,5 @@ import artistsOrganize from "./artistsOrganize" import { audioVisualizer } from "./audioVisualizer" +import cicdInfo from "./cicdInfo" -export { artistsOrganize, audioVisualizer } +export { artistsOrganize, audioVisualizer, cicdInfo } -- 2.45.1 From 0d67ea682c6c9c7ad1c1638f912508339b0721bb Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:41:48 +1000 Subject: [PATCH 2/8] fix: update environment variables for Chrome build job to use correct identifiers --- .gitea/workflows/workflow.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index 555fa33..519840e 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -9,8 +9,8 @@ jobs: name: 构建 Chrome 扩展程序 runs-on: ubuntu-latest env: - VITE_RUN_ID: ${{ gitea.run_id }} - VITE_HASH_ID: ${{ gitea.sha | slice(0, 7) }} + VITE_RUN_ID: ${{ gitea.run_number }} + VITE_HASH_ID: ${{ gitea.workflow_sha }} steps: - uses: actions/checkout@v3 -- 2.45.1 From 0a1fb490582a98b10b2d987022473306cb494cdc Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:43:11 +1000 Subject: [PATCH 3/8] fix: update environment variables for Firefox build job to use correct identifiers --- .gitea/workflows/workflow.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index 519840e..5c0cd9f 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -37,8 +37,8 @@ jobs: name: 构建 Firefox 附加组件 runs-on: ubuntu-latest env: - VITE_RUN_ID: ${{ gitea.run_id }} - VITE_HASH_ID: ${{ gitea.sha | slice(0, 7) }} + VITE_RUN_ID: ${{ gitea.run_number }} + VITE_HASH_ID: ${{ gitea.workflow_sha }} steps: - uses: actions/checkout@v3 -- 2.45.1 From 48151350bd71e5b3ebc2be98c9d0f27e022ddfeb Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:45:50 +1000 Subject: [PATCH 4/8] fix: update VITE_HASH_ID to use correct identifier in build jobs --- .gitea/workflows/workflow.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index 5c0cd9f..f845d61 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest env: VITE_RUN_ID: ${{ gitea.run_number }} - VITE_HASH_ID: ${{ gitea.workflow_sha }} + VITE_HASH_ID: ${{ gitea.sha }} steps: - uses: actions/checkout@v3 @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-latest env: VITE_RUN_ID: ${{ gitea.run_number }} - VITE_HASH_ID: ${{ gitea.workflow_sha }} + VITE_HASH_ID: ${{ gitea.sha }} steps: - uses: actions/checkout@v3 -- 2.45.1 From b37ca033e9ba87d0bb64e82f77a89ad86ec84336 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:49:29 +1000 Subject: [PATCH 5/8] fix: update VITE_HASH_ID to use shortened SHA for build jobs --- .gitea/workflows/workflow.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index f845d61..604766c 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest env: VITE_RUN_ID: ${{ gitea.run_number }} - VITE_HASH_ID: ${{ gitea.sha }} + VITE_HASH_ID: ${{ substr(gitea.sha, 0, 10) }} steps: - uses: actions/checkout@v3 @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-latest env: VITE_RUN_ID: ${{ gitea.run_number }} - VITE_HASH_ID: ${{ gitea.sha }} + VITE_HASH_ID: ${{ substr(gitea.sha, 0, 10) }} steps: - uses: actions/checkout@v3 -- 2.45.1 From b919c44128478225a65f8f07fc63c44ef3ce0a51 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:53:29 +1000 Subject: [PATCH 6/8] fix: update VITE_HASH_ID to use full SHA in build jobs and adjust display in cicdInfo --- .gitea/workflows/workflow.yaml | 4 ++-- src/utils/cicdInfo.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index 604766c..f845d61 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest env: VITE_RUN_ID: ${{ gitea.run_number }} - VITE_HASH_ID: ${{ substr(gitea.sha, 0, 10) }} + VITE_HASH_ID: ${{ gitea.sha }} steps: - uses: actions/checkout@v3 @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-latest env: VITE_RUN_ID: ${{ gitea.run_number }} - VITE_HASH_ID: ${{ substr(gitea.sha, 0, 10) }} + VITE_HASH_ID: ${{ gitea.sha }} steps: - uses: actions/checkout@v3 diff --git a/src/utils/cicdInfo.ts b/src/utils/cicdInfo.ts index 2d47548..fee19ab 100644 --- a/src/utils/cicdInfo.ts +++ b/src/utils/cicdInfo.ts @@ -1,4 +1,4 @@ export default { runId: import.meta.env.VITE_RUN_ID ?? '未知', - hashId: import.meta.env.VITE_HASH_ID ?? '未知', + hashId: import.meta.env.VITE_HASH_ID?.slice(0, 10) ?? '未知', } \ No newline at end of file -- 2.45.1 From af41f70d37f337c22debcb04027ca02910aaffd6 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 11:57:19 +1000 Subject: [PATCH 7/8] fix: update description in PreferencePanel.vue for CI/CD build process clarity --- src/components/PreferencePanel.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/PreferencePanel.vue b/src/components/PreferencePanel.vue index ef58750..6198741 100644 --- a/src/components/PreferencePanel.vue +++ b/src/components/PreferencePanel.vue @@ -161,8 +161,7 @@ const version = computed(() => { -
MSR Mod 使用 Gitea Actions 完成打包与自动商店提交工作。此信息用于确认 MSR Mod 的 - CI/CD 构建版本信息,以及当前构建代码是否被篡改。
+
MSR Mod 通过 Gitea Actions 自动化完成构建与发布流程。此信息用于验证当前版本的构建来源,确保代码完整性与安全性。
-- 2.45.1 From 76e5125b9d1a880778f31fa713ed49fe96504718 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 29 May 2025 12:16:13 +1000 Subject: [PATCH 8/8] feat: add Edge Addons publishing workflow to CI/CD pipeline --- .gitea/workflows/workflow.yaml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/workflow.yaml b/.gitea/workflows/workflow.yaml index f845d61..eaea6fc 100644 --- a/.gitea/workflows/workflow.yaml +++ b/.gitea/workflows/workflow.yaml @@ -129,4 +129,33 @@ jobs: --api-secret ${{ secrets.FIREFOX_API_SECRET }} \ --channel listed - \ No newline at end of file + publish-to-edge-addons: + name: 发布至 Edge 附加组件商店 + runs-on: ubuntu-latest + needs: build-for-chrome + # 仅在 main 分支上执行发布 + if: gitea.ref == 'refs/heads/main' + + steps: + - name: 下载构建工件 + uses: actions/download-artifact@v3 + with: + name: chrome-extension + path: dist/ + + - name: 压缩为 ZIP 文件 + run: |- + cd dist && zip -r ../msrmod-edge.zip . && cd .. + + - name: 设置 Node.js + uses: actions/setup-node@v3 + with: + node-version: "22" + + - name: 上传扩展程序到 Edge Addons + uses: wdzeng/edge-addon@v2 + with: + product-id: d63fd5c5-baba-4fcb-95c8-f11c161f9878 + zip-path: msrmod-edge.zip + api-key: ${{ secrets.EDGE_CLIENT_SECRET }} + client-id: ${{ secrets.EDGE_CLIENT_ID }} \ No newline at end of file -- 2.45.1