From 08042459aed62357d204d69f8f74a4a73687c3e2 Mon Sep 17 00:00:00 2001 From: Lan Date: Sat, 11 Jul 2026 21:48:38 +0800 Subject: [PATCH] feat: automate frontend releases --- .github/workflows/release-please.yml | 45 ++++++++++++++++++++++++++++ .release-please-manifest.json | 3 ++ CHANGELOG.md | 3 ++ README.md | 8 +++++ env.d.ts | 3 ++ release-please-config.json | 11 +++++++ src/i18n/locales/en-US.ts | 3 +- src/i18n/locales/zh-CN.ts | 3 +- src/utils/build-info.ts | 10 +++++++ src/views/manage/DashboardView.vue | 16 ++++++++-- vite.config.ts | 31 +++++++++++++++++++ 11 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release-please.yml create mode 100644 .release-please-manifest.json create mode 100644 CHANGELOG.md create mode 100644 release-please-config.json create mode 100644 src/utils/build-info.ts diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..982c8c8 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,45 @@ +name: Release Please + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + actions: write + contents: write + pull-requests: write + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +jobs: + release: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - id: release + uses: googleapis/release-please-action@v4 + with: + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + + - name: Merge release pull request + if: ${{ steps.release.outputs.prs_created == 'true' }} + env: + GH_TOKEN: ${{ github.token }} + RELEASE_PR: ${{ fromJSON(steps.release.outputs.pr).number }} + run: | + for attempt in {1..120}; do + if gh pr merge "$RELEASE_PR" --squash --delete-branch; then + break + fi + if [[ "$attempt" -eq 120 ]]; then + echo "Timed out waiting for release PR #$RELEASE_PR to merge" >&2 + exit 1 + fi + sleep 10 + done + gh workflow run release-please.yml --ref main diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..a549f59 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "2.4.0" +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..cf8695a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +此文件由 Release Please 根据 Conventional Commits 自动维护。 diff --git a/README.md b/README.md index 8ea06d4..cc6432d 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,14 @@ pnpm install pnpm dev ``` +The frontend version comes from `package.json`. Production builds also embed the +current Git commit. CI can override these values with `VITE_APP_VERSION` and +`VITE_GIT_COMMIT`. + +Releases are managed by Release Please. Use Conventional Commits such as +`feat:` and `fix:`; the workflow automatically merges its release pull request, +updates the version and changelog, and creates a `vX.Y.Z` tag. + ### Type-Check, Compile and Minify for Production ```sh diff --git a/env.d.ts b/env.d.ts index 11f02fe..53cbf48 100644 --- a/env.d.ts +++ b/env.d.ts @@ -1 +1,4 @@ /// + +declare const __APP_VERSION__: string +declare const __GIT_COMMIT__: string diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..eaa3ab7 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "packages": { + ".": { + "release-type": "node", + "package-name": "filecodebox-frontend", + "include-component-in-tag": false, + "changelog-path": "CHANGELOG.md" + } + } +} diff --git a/src/i18n/locales/en-US.ts b/src/i18n/locales/en-US.ts index dfda104..ddca646 100644 --- a/src/i18n/locales/en-US.ts +++ b/src/i18n/locales/en-US.ts @@ -73,7 +73,8 @@ export default { lastUpdated: 'Last updated: {time}', loadFailed: 'Failed to load dashboard data', footerProduct: 'FileCodeBox Admin Console', - runtimeVersion: 'Runtime Version', + backendVersion: 'Server Version', + frontendVersion: 'Frontend Version', versionPending: 'Pending sync', fileHealth: 'File Health', fileHealthDesc: 'Status insights for available, risky, and pending file queues.', diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts index 228bc4b..c4da53c 100644 --- a/src/i18n/locales/zh-CN.ts +++ b/src/i18n/locales/zh-CN.ts @@ -73,7 +73,8 @@ export default { lastUpdated: '最近更新:{time}', loadFailed: '仪表盘数据加载失败', footerProduct: 'FileCodeBox 管理后台', - runtimeVersion: '运行版本', + backendVersion: '服务端版本', + frontendVersion: '前端版本', versionPending: '待同步', fileHealth: '文件健康', fileHealthDesc: '基于状态洞察统计可取件、风险与待处理队列。', diff --git a/src/utils/build-info.ts b/src/utils/build-info.ts new file mode 100644 index 0000000..6c7d08b --- /dev/null +++ b/src/utils/build-info.ts @@ -0,0 +1,10 @@ +const abbreviatedCommit = __GIT_COMMIT__.slice(0, 12) + +export const buildInfo = Object.freeze({ + version: __APP_VERSION__, + commit: abbreviatedCommit, + displayVersion: + abbreviatedCommit && abbreviatedCommit !== 'unknown' + ? `${__APP_VERSION__} (${abbreviatedCommit})` + : __APP_VERSION__ +}) diff --git a/src/views/manage/DashboardView.vue b/src/views/manage/DashboardView.vue index 55bbe85..e87ed8f 100644 --- a/src/views/manage/DashboardView.vue +++ b/src/views/manage/DashboardView.vue @@ -223,8 +223,8 @@ :class="[isDarkMode ? 'border-gray-800 text-gray-500' : 'border-gray-200 text-gray-500']" > {{ t('admin.dashboard.footerProduct') }} - - {{ t('admin.dashboard.runtimeVersion') }} + + {{ t('admin.dashboard.backendVersion') }} + {{ buildInfo.displayVersion }} + @@ -263,6 +274,7 @@ import { useI18n } from 'vue-i18n' import { ROUTES } from '@/constants' import { useConfigStore } from '@/stores/configStore' import type { DashboardHealthAction } from '@/types' +import { buildInfo } from '@/utils/build-info' const isDarkMode = useInjectedDarkMode() const { t } = useI18n() diff --git a/vite.config.ts b/vite.config.ts index 058b471..1bbc295 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,42 @@ import { fileURLToPath, URL } from 'node:url' +import { execFileSync } from 'node:child_process' +import { readFileSync } from 'node:fs' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueJsx from '@vitejs/plugin-vue-jsx' import tailwindcss from 'tailwindcss' import autoprefixer from 'autoprefixer' + +interface PackageMetadata { + version: string +} + +const packageMetadata = JSON.parse( + readFileSync(fileURLToPath(new URL('./package.json', import.meta.url)), 'utf8') +) as PackageMetadata + +const resolveGitCommit = () => { + if (process.env.VITE_GIT_COMMIT) return process.env.VITE_GIT_COMMIT + + try { + return execFileSync('git', ['rev-parse', '--short=12', 'HEAD'], { + encoding: 'utf8', + stdio: ['ignore', 'pipe', 'ignore'] + }).trim() + } catch { + return 'unknown' + } +} + +const buildVersion = process.env.VITE_APP_VERSION || packageMetadata.version +const buildCommit = resolveGitCommit() + export default defineConfig({ + define: { + __APP_VERSION__: JSON.stringify(buildVersion), + __GIT_COMMIT__: JSON.stringify(buildCommit) + }, plugins: [vue(), vueJsx()], resolve: { alias: {