소스 검색

fix: the release deb could not say which commit built it

build.sh has always computed the commit and passed it as
--build-arg BUILD_GIT_COMMIT. Dockerfile.build never declared the ARG, so
Docker silently dropped it and nothing consumed it; inside the container
.dockerignore excludes .git, so CMake's probe failed and fell back to
"unknown". Every release deb we have ever shipped reports
commit: unknown, while the local build reports the sha - which is why the
two paths disagreed and nobody noticed.

Accepted and ignored, in the build system rather than on a route. Same
shape this repo has now fixed three times on the HTTP surface: a value
plumbed in, dropped, and the caller shown a plausible default.

It surfaced because it is the instrument for a question just asked of me -
"is that fix in this release?" - which I could not answer from the
artefact. The alternatives are the deb's mtime, which is not evidence, and
git merge-base against the bump commit, which needs you to already know
the bump. The deb reporting its own commit is strictly better than both.

CMake now prefers an explicitly provided SVAPI_GIT_COMMIT over the probe,
so the release path can inject what the host knows and the local path keeps
working unchanged.
fszontagh 1 개월 전
부모
커밋
2061c25733
2개의 변경된 파일과 25개의 추가작업 그리고 5개의 파일을 삭제
  1. 21 5
      CMakeLists.txt
  2. 4 0
      packaging/Dockerfile.build

+ 21 - 5
CMakeLists.txt

@@ -37,11 +37,27 @@ if(PkgConfig_FOUND)
     pkg_check_modules(SYSTEMD IMPORTED_TARGET libsystemd)
 endif()
 
-# git commit for version banner
-execute_process(COMMAND git rev-parse --short HEAD
-    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
-    OUTPUT_VARIABLE SVAPI_GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE
-    ERROR_QUIET)
+# git commit for version banner.
+#
+# An EXPLICITLY PROVIDED value wins over the git probe, and that ordering is the
+# whole point: the Docker release path has no `.git` (`.dockerignore` excludes
+# it), so the probe fails there and every release deb reported
+# `commit: unknown` while the local build reported the sha. build.sh had always
+# computed the commit and passed it as `--build-arg BUILD_GIT_COMMIT`, and
+# Dockerfile.build never declared the ARG - so Docker silently dropped it and
+# nothing consumed it. Accepted and ignored, in the build system rather than on
+# a route.
+#
+# It matters because this field is the cheapest answer to "is that fix in this
+# release": without it, the only instruments are the deb's mtime, which is not
+# evidence, and mapping a commit against a bump commit, which needs you to
+# already know the bump.
+if(NOT SVAPI_GIT_COMMIT)
+    execute_process(COMMAND git rev-parse --short HEAD
+        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+        OUTPUT_VARIABLE SVAPI_GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE
+        ERROR_QUIET)
+endif()
 if(NOT SVAPI_GIT_COMMIT)
     set(SVAPI_GIT_COMMIT "unknown")
 endif()

+ 4 - 0
packaging/Dockerfile.build

@@ -5,9 +5,13 @@ ARG BUILD_DEB_REVISION=1
 # The runner vendors QuickJS from GitHub at configure time; the build network
 # already reaches GitHub for cpp-httplib, so this adds no new requirement.
 ARG BUILD_RUNNER=ON
+# Passed by build.sh. Without this the container has no .git, so the commit
+# probe fails and the shipped deb reports "unknown".
+ARG BUILD_GIT_COMMIT=unknown
 WORKDIR /build
 COPY . /build/
 RUN cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_WEBUI=ON -DBUILD_TESTS=OFF \
+    -DSVAPI_GIT_COMMIT="${BUILD_GIT_COMMIT}" \
         -DBUILD_RUNNER=${BUILD_RUNNER} -S . \
     && cmake --build build -j"$(nproc)"
 RUN OUTPUT_DIR=/packages BUILD_DEB_REVISION=${BUILD_DEB_REVISION} packaging/deb/create-debs.sh