diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index c02dee6a..6d62c6a2 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -59,6 +59,7 @@ jobs: fi echo "VERSION=$VERSION" >> "$GITHUB_ENV" + echo "BUILD_DATE=$(date -u +'%Y-%m-%d %H:%M:%S')" >> "$GITHUB_ENV" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 @@ -80,6 +81,7 @@ jobs: outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true build-args: | VERSION=${{ env.VERSION }} + BUILD_DATE=${{ env.BUILD_DATE }} cache-from: type=gha,scope=docker-server-${{ matrix.arch }} cache-to: type=gha,mode=max,ignore-error=true,timeout=20m,scope=docker-server-${{ matrix.arch }} diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index a2d7075f..9630754b 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -103,30 +103,10 @@ jobs: working-directory: ${{ env.FRONTEND_DIR }} run: pnpm install --frozen-lockfile - - name: Stamp frontend package metadata - working-directory: ${{ env.FRONTEND_DIR }} - shell: bash - env: - VERSION: ${{ needs.create-release.outputs.version_without_v }} - BUILD_DATE: ${{ needs.create-release.outputs.build_date }} - run: | - set -euo pipefail - if [[ -f package.json ]]; then - node - <<'NODE' - const fs = require('fs'); - const path = './package.json'; - const pkg = JSON.parse(fs.readFileSync(path, 'utf8')); - if (process.env.VERSION && Object.hasOwn(pkg, 'version')) { - pkg.version = process.env.VERSION; - } - if (process.env.BUILD_DATE && Object.hasOwn(pkg, 'buildDate')) { - pkg.buildDate = process.env.BUILD_DATE; - } - fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + '\n'); - NODE - fi - - name: Build frontend + env: + NEXT_PUBLIC_APP_VERSION: ${{ needs.create-release.outputs.version }} + NEXT_PUBLIC_APP_BUILD_DATE: ${{ needs.create-release.outputs.build_date }} run: ${{ env.FRONTEND_BUILD_COMMAND }} working-directory: ${{ env.FRONTEND_DIR }} diff --git a/Makefile b/Makefile index f45b8297..c92dfcd6 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ cross-build: --file docker/Dockerfile.cross \ --target export \ --build-arg VERSION=$(or $(VERSION),dev) \ + --build-arg BUILD_DATE="$(shell date -u +'%Y-%m-%d %H:%M:%S')" \ $(if $(GOOS),--build-arg TARGET_OS=$(GOOS)) \ $(if $(GOARCH),--build-arg TARGET_ARCH=$(GOARCH)) \ --output type=local,dest=./bin \ diff --git a/docker/Dockerfile b/docker/Dockerfile index 79b71dd2..5419ceab 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,10 +6,15 @@ ARG ALPINE_VERSION=3.23 FROM node:${NODE_VERSION}-alpine AS frontend-builder +ARG VERSION=dev +ARG BUILD_DATE="" + ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" ENV NODE_ENV=production ENV NEXT_STANDALONE_EXPORT=true +ENV NEXT_PUBLIC_APP_VERSION=${VERSION} +ENV NEXT_PUBLIC_APP_BUILD_DATE=${BUILD_DATE} RUN corepack enable && corepack prepare pnpm@10.10.0 --activate @@ -19,10 +24,13 @@ COPY frontend/package.json frontend/pnpm-lock.yaml ./ RUN pnpm install --frozen-lockfile COPY frontend/ ./ + RUN pnpm build:embed FROM golang:${GO_VERSION}-alpine AS backend-builder +ARG VERSION=dev + RUN apk add --no-cache ca-certificates git WORKDIR /workspace @@ -36,7 +44,7 @@ COPY --from=frontend-builder /workspace/frontend/out ./internal/router/dist RUN CGO_ENABLED=0 GOOS=linux go build \ -tags embed_frontend \ -trimpath \ - -ldflags="-s -w" \ + -ldflags="-s -w -X github.com/Rain-kl/Wavelet/internal/cmd.Version=${VERSION}" \ -o /out/wavelet \ ./main.go diff --git a/docker/Dockerfile.backend b/docker/Dockerfile.backend index 2782e2d0..e8edbc2c 100644 --- a/docker/Dockerfile.backend +++ b/docker/Dockerfile.backend @@ -5,6 +5,8 @@ ARG ALPINE_VERSION=3.23 FROM golang:${GO_VERSION}-alpine AS builder +ARG VERSION=dev + RUN apk add --no-cache ca-certificates git WORKDIR /workspace @@ -16,7 +18,7 @@ COPY . . RUN CGO_ENABLED=0 GOOS=linux go build \ -trimpath \ - -ldflags="-s -w" \ + -ldflags="-s -w -X github.com/Rain-kl/Wavelet/internal/cmd.Version=${VERSION}" \ -o /out/wavelet \ ./main.go diff --git a/docker/Dockerfile.cross b/docker/Dockerfile.cross index 8439cf11..8167f660 100644 --- a/docker/Dockerfile.cross +++ b/docker/Dockerfile.cross @@ -29,11 +29,14 @@ ARG ALPINE_VERSION=3.23 FROM node:${NODE_VERSION}-alpine AS frontend-builder ARG VERSION=dev +ARG BUILD_DATE="" ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" ENV NODE_ENV=production ENV NEXT_STANDALONE_EXPORT=true +ENV NEXT_PUBLIC_APP_VERSION=${VERSION} +ENV NEXT_PUBLIC_APP_BUILD_DATE=${BUILD_DATE} RUN corepack enable && corepack prepare pnpm@10.10.0 --activate @@ -45,16 +48,6 @@ RUN pnpm install --frozen-lockfile COPY frontend/ ./ -# Stamp version into package.json when VERSION is not "dev" -RUN if [ "$VERSION" != "dev" ]; then \ - node -e " \ - const fs = require('fs'); \ - const pkg = require('./package.json'); \ - pkg.version = process.env.VERSION.replace(/^v/, ''); \ - fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n'); \ - "; \ - fi - RUN pnpm build:embed # ── Stage 2: Cross-compile Go backend ────────────────────────────────────── diff --git a/docker/Dockerfile.frontend b/docker/Dockerfile.frontend index 11b32cc0..e7197272 100644 --- a/docker/Dockerfile.frontend +++ b/docker/Dockerfile.frontend @@ -20,6 +20,9 @@ ENV WAVELET_BACKEND_URL=https://build-placeholder-2.invalid ARG VERSION="" ARG BUILD_DATE="" +ENV NEXT_PUBLIC_APP_VERSION=${VERSION} +ENV NEXT_PUBLIC_APP_BUILD_DATE=${BUILD_DATE} + WORKDIR /app COPY frontend/package.json frontend/pnpm-lock.yaml ./ @@ -27,10 +30,6 @@ RUN pnpm install --frozen-lockfile COPY frontend/ ./ -RUN if [ -n "$VERSION" ] || [ -n "$BUILD_DATE" ]; then \ - VERSION="$VERSION" BUILD_DATE="$BUILD_DATE" node -e "const fs = require('fs'); const pkg = require('./package.json'); const version = process.env.VERSION; const buildDate = process.env.BUILD_DATE; if (version) pkg.version = version; if (buildDate) pkg.buildDate = buildDate; fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\\n')"; \ - fi - RUN pnpm build RUN grep -rl \ diff --git a/frontend/components/common/settings/info-tab.tsx b/frontend/components/common/settings/info-tab.tsx index b3d3eb37..cb072630 100644 --- a/frontend/components/common/settings/info-tab.tsx +++ b/frontend/components/common/settings/info-tab.tsx @@ -2,6 +2,7 @@ import {Info, Server} from "lucide-react" import packageJson from "../../../package.json" +import {APP_VERSION, APP_BUILD_DATE} from "@/lib/app-info" import {apiConfig} from "@/lib/services" import {Card, CardContent, CardDescription, CardHeader, CardTitle} from "@/components/ui/card" @@ -36,8 +37,8 @@ export function InfoTab({ systemConfigsLength, authSourcesLength }: InfoTabProps - - + + {APP_BUILD_DATE && } }).dependencies?.next} /> }).dependencies?.react} /> diff --git a/frontend/components/layout/sidebar.tsx b/frontend/components/layout/sidebar.tsx index 6535982e..d55dd845 100644 --- a/frontend/components/layout/sidebar.tsx +++ b/frontend/components/layout/sidebar.tsx @@ -3,7 +3,7 @@ import * as React from "react" import Link from "next/link" import {usePathname, useRouter} from "next/navigation" -import packageJson from "../../package.json" +import {APP_VERSION, APP_BUILD_DATE} from "@/lib/app-info" import {toast} from "sonner" import {Button} from "@/components/ui/button" import {Spinner} from "@/components/ui/spinner" @@ -384,8 +384,8 @@ export function AppSidebar({ ...props }: React.ComponentProps) { - Version {packageJson.version} - Build At {packageJson.buildDate} + Version {APP_VERSION} + {APP_BUILD_DATE && Build At {APP_BUILD_DATE}} diff --git a/frontend/lib/app-info.ts b/frontend/lib/app-info.ts new file mode 100644 index 00000000..734326bb --- /dev/null +++ b/frontend/lib/app-info.ts @@ -0,0 +1,6 @@ +import packageJson from "../package.json" + +const rawVersion = process.env.NEXT_PUBLIC_APP_VERSION || packageJson.version + +export const APP_VERSION = rawVersion.startsWith('v') ? rawVersion.slice(1) : rawVersion +export const APP_BUILD_DATE = process.env.NEXT_PUBLIC_APP_BUILD_DATE || "" diff --git a/frontend/package.json b/frontend/package.json index 6a11ba39..3e598aff 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,6 @@ { "name": "wavelet", - "version": "1.3.9", - "buildDate": "2026-04-22 16:00:00", + "version": "dev", "private": true, "scripts": { "predev": "node scripts/generate-themes.js",