From 12d13327a680b9e95da1ccc6ffaa7e2ec2d819a2 Mon Sep 17 00:00:00 2001
From: eezd
Date: Tue, 27 Oct 2026 14:15:57 +0800
Subject: [PATCH] feat(release): add semantic version to application builds
---
Dockerfile | 8 +++++++-
VERSION | 1 +
cmd/rawmark/main.go | 7 +++++++
web/src/pages/settings/index.vue | 5 +++--
web/types/build.d.ts | 1 +
web/vite.config.ts | 3 +++
6 files changed, 22 insertions(+), 3 deletions(-)
create mode 100644 VERSION
create mode 100644 web/types/build.d.ts
diff --git a/Dockerfile b/Dockerfile
index f4060a2..169a5b1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -7,12 +7,14 @@ RUN corepack enable && corepack prepare pnpm@12.11.2 --activate
COPY web/package.json web/pnpm-lock.yaml web/pnpm-workspace.yaml web/.npmrc ./
RUN pnpm install --frozen-lockfile
COPY web/ ./
+COPY VERSION /src/VERSION
RUN pnpm build
# ---- Backend (frontend assets embedded in the binary) ----
FROM golang:1-alpine AS server
WORKDIR /src
COPY go.mod go.sum ./
+COPY VERSION ./
RUN go mod download
COPY cmd ./cmd
COPY internal ./internal
@@ -20,10 +22,14 @@ COPY deploy/embed.go ./deploy/
COPY deploy/data/vault ./deploy/data/vault
COPY web/embed.go web/font_storage.go ./web/
COPY --from=web /src/web/dist ./web/dist
-RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/rawmark ./cmd/rawmark && mkdir -p /out/data
+RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.releaseVersion=$(cat VERSION)" -o /out/rawmark ./cmd/rawmark && mkdir -p /out/data
# ---- Runtime ----
FROM gcr.io/distroless/static:nonroot
+COPY LICENSE /LICENSE
+COPY web/LICENSE /licenses/vue3-starter-MIT.txt
+COPY web/src/common/appearance/fonts/*-OFL.txt /licenses/
+COPY web/src/common/appearance/fonts/maple/LICENSE.txt /licenses/Maple-Mono-OFL.txt
COPY --from=server /out/rawmark /rawmark
COPY --from=server --chown=nonroot:nonroot /out/data /data
ENV RAWMARK_DATA=/data
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
diff --git a/cmd/rawmark/main.go b/cmd/rawmark/main.go
index 4511879..d565e71 100644
--- a/cmd/rawmark/main.go
+++ b/cmd/rawmark/main.go
@@ -32,6 +32,9 @@ import (
"rawmark/web"
)
+// releaseVersion is set from VERSION by release and Docker builds.
+var releaseVersion = "dev"
+
func env(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
@@ -40,6 +43,10 @@ func env(key, def string) string {
}
func main() {
+ if len(os.Args) > 1 && os.Args[1] == "--version" {
+ fmt.Println("RawMark " + releaseVersion)
+ return
+ }
addr := env("RAWMARK_ADDR", ":8080")
if len(os.Args) > 1 && os.Args[1] == "healthcheck" {
os.Exit(healthcheck(addr))
diff --git a/web/src/pages/settings/index.vue b/web/src/pages/settings/index.vue
index 79a0a1c..21a03ee 100644
--- a/web/src/pages/settings/index.vue
+++ b/web/src/pages/settings/index.vue
@@ -21,6 +21,7 @@ import { searchSettings, SETTINGS_SECTIONS } from './settings-catalog'
const props = defineProps<{ prepareMaintenance: () => Promise, restoreNote: (id: string) => Promise }>()
const emit = defineEmits<{ importNotes: [] }>()
const { settingsSave } = useSettingsStore()
+const releaseVersion = __RAWMARK_RELEASE__
const buildVersion = import.meta.env.DEV ? translate('settings.development_0d1c11') : document.querySelector('meta[name="rawmark-version"]')?.content
if (!buildVersion) throw new Error(translate('settings.application_build_information_is_missing_6b04f9'))
const model = defineModel({ required: true })
@@ -80,7 +81,7 @@ function close() {
@@ -120,7 +121,7 @@ function close() {
{{ translate('settings.rawmark_a_markdown_note_editor_66b52a') }}
- {{ buildVersion }}
+ {{ releaseVersion }} ยท {{ buildVersion }}
diff --git a/web/types/build.d.ts b/web/types/build.d.ts
new file mode 100644
index 0000000..3342908
--- /dev/null
+++ b/web/types/build.d.ts
@@ -0,0 +1 @@
+declare const __RAWMARK_RELEASE__: string
diff --git a/web/vite.config.ts b/web/vite.config.ts
index f9a7a5e..eab6ae7 100644
--- a/web/vite.config.ts
+++ b/web/vite.config.ts
@@ -8,7 +8,10 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vitest/config'
+const releaseVersion = readFileSync(new URL('../VERSION', import.meta.url), 'utf8').trim()
+
export default defineConfig({
+ define: { __RAWMARK_RELEASE__: JSON.stringify(releaseVersion) },
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), '@@': fileURLToPath(new URL('./src/common', import.meta.url)) } },
plugins: [
vue(),