fix: show git commit in About instead of "unknown"
This commit is contained in:
@@ -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 }}
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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
|
||||
|
||||
+14
-5
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user