From 599fa668221cdc8eeac3711a01efd738f52fc68a Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Sat, 2 May 2026 00:28:08 +0200 Subject: [PATCH] fix: show git commit in About instead of "unknown" --- .github/workflows/docker-publish-releases.yml | 2 ++ .github/workflows/docker-publish.yml | 2 ++ Dockerfile | 4 ++++ next.config.ts | 19 ++++++++++++++----- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-publish-releases.yml b/.github/workflows/docker-publish-releases.yml index 1369adbc..2c052a00 100644 --- a/.github/workflows/docker-publish-releases.yml +++ b/.github/workflows/docker-publish-releases.yml @@ -50,6 +50,8 @@ jobs: context: . platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + GIT_COMMIT=${{ github.sha }} outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true cache-from: type=gha,scope=${{ matrix.platform }} cache-to: type=gha,mode=max,scope=${{ matrix.platform }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 43114ea9..6a718fbb 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -78,6 +78,8 @@ jobs: context: . platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + GIT_COMMIT=${{ github.sha }} outputs: type=image,name=${{ needs.prepare.outputs.image_name }},push-by-digest=true,name-canonical=true,push=true cache-from: type=gha,scope=${{ matrix.platform }} cache-to: type=gha,mode=max,scope=${{ matrix.platform }} diff --git a/Dockerfile b/Dockerfile index d6095c4b..e91af29a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,10 @@ ENV NEXT_TELEMETRY_DISABLED=1 # at build time, so it cannot be changed without rebuilding. ARG NEXT_PUBLIC_BASE_PATH= ENV NEXT_PUBLIC_BASE_PATH=$NEXT_PUBLIC_BASE_PATH +# Commit SHA shown in the About screen. .dockerignore excludes .git, so +# `git rev-parse` inside the build can't find it — CI must pass it in. +ARG GIT_COMMIT=unknown +ENV GIT_COMMIT=$GIT_COMMIT RUN npx next build --webpack FROM node:24-alpine AS runner diff --git a/next.config.ts b/next.config.ts index 02070b12..13f6cc77 100644 --- a/next.config.ts +++ b/next.config.ts @@ -4,11 +4,20 @@ import { execSync } from "child_process"; import { readFileSync } from "fs"; import { join } from "path"; -let gitCommitHash = "unknown"; -try { - gitCommitHash = execSync("git rev-parse --short HEAD").toString().trim(); -} catch { - // git not available +// Prefer an explicit build arg (passed in by CI / Docker, where .git is +// excluded from the build context) and fall back to `git rev-parse` for +// local builds. +let gitCommitHash = process.env.GIT_COMMIT?.trim() || ""; +if (!gitCommitHash) { + try { + gitCommitHash = execSync("git rev-parse --short HEAD").toString().trim(); + } catch { + gitCommitHash = "unknown"; + } +} +// Normalise full 40-char SHAs (e.g. ${{ github.sha }}) to the short form. +if (/^[0-9a-f]{40}$/i.test(gitCommitHash)) { + gitCommitHash = gitCommitHash.slice(0, 7); } let appVersion = "0.0.0";