From 141baeb779b4950cb7f72f8bcaeb05c7e4449740 Mon Sep 17 00:00:00 2001 From: salman Date: Wed, 4 Nov 2026 16:32:11 +0100 Subject: [PATCH] Show build for non-git installations. --- .gitattributes | 1 + CHANGELOG.md | 3 ++- README.md | 6 +++++- build-revision.txt | 1 + scripts/deploy-web.sh | 18 +++++++++++++++++- tests/help-window.test.js | 3 ++- 6 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 .gitattributes create mode 100644 build-revision.txt diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7b31107 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +build-revision.txt export-subst diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e9848..cda21d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ release path documented in [`TODO.md`](TODO.md). version. Development and locally packaged modified trees are marked as such. - Electron packages embed build provenance during Linux and Windows packaging; web deployment stamps equivalent provenance from the deployed checkout and - configured server tools. + configured server tools. Gitea source archives preserve their commit through + Git archive substitution even though the extracted directory has no `.git`. - Parameter-plot controls are hidden by default and toggle with a deliberate tap or click on all pointer types; drag gestures remain reserved for plots. diff --git a/README.md b/README.md index 2c06288..fa0fae9 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,11 @@ deployed tree is not already owned by the invoking user, so the script also runs unprivileged against a developer-owned web tree (skip that case's `sudo`). Override the targets and owner as needed with `MUSRFLOW_WEB_TARGET`, `MUSRFLOW_CGI_TARGET`, `MUSRFLOW_STARTUP_XML_TARGET`, `MUSRFLOW_WEB_OWNER`, and -`MUSRFLOW_WEB_GROUP`. +`MUSRFLOW_WEB_GROUP`. Official Git source archives carry their commit through +`build-revision.txt`, so Quick Start can identify an archive deployment without +a `.git` directory. For a tar file produced by another tool, set +`MUSRFLOW_BUILD_REVISION` to its full Git commit when running the deployment +script; otherwise the UI identifies it as a versioned source archive. The installed `musrfit_startup.xml` is rewritten when the machine's data tree lives under a non-PSI root: set `MUSRFLOW_DATA_ROOT` (e.g. `/mnt/fake`) and the diff --git a/build-revision.txt b/build-revision.txt new file mode 100644 index 0000000..c494841 --- /dev/null +++ b/build-revision.txt @@ -0,0 +1 @@ +muSRFlow=$Format:%H$ diff --git a/scripts/deploy-web.sh b/scripts/deploy-web.sh index d47bed8..844b572 100755 --- a/scripts/deploy-web.sh +++ b/scripts/deploy-web.sh @@ -49,7 +49,23 @@ find "$web_target/docs" -type f -exec chmod 0644 {} + # its own and ROOT's versions using the same executable configured for the CGI. if command -v node >/dev/null 2>&1; then version="$(node -p 'require(process.argv[1]).version' "$project_root/package.json")" - revision="$(git -C "$project_root" rev-parse --short=12 HEAD 2>/dev/null || printf 'unrecorded')" + revision="${MUSRFLOW_BUILD_REVISION:-}" + if [[ "$revision" =~ ^[0-9a-fA-F]{7,40}$ ]]; then + revision="${revision:0:12}" + elif git_revision="$(git -C "$project_root" rev-parse --short=12 HEAD 2>/dev/null)"; then + revision="$git_revision" + else + # git archive expands the export-subst placeholder in this file. Gitea + # source archives therefore retain the exact commit without a .git tree. + archive_revision="$(sed -n 's/^muSRFlow=//p' "$project_root/build-revision.txt" 2>/dev/null || true)" + if [[ "$archive_revision" =~ ^[0-9a-fA-F]{40}$ ]]; then + revision="${archive_revision:0:12}" + else + # Third-party tar programs do not expand git placeholders. The + # release version is still more useful and honest than "unrecorded". + revision="v${version}-archive" + fi + fi modified="" if [ -n "$(git -C "$project_root" status --porcelain 2>/dev/null || true)" ]; then modified=" (modified)" diff --git a/tests/help-window.test.js b/tests/help-window.test.js index 63b2f77..589639f 100644 --- a/tests/help-window.test.js +++ b/tests/help-window.test.js @@ -77,6 +77,7 @@ function testDocumentationDeployment() { "cgi/single_musrfit.cgi", "cgi/musrfit_startup.xml"]; for (const file of assets) fs.writeFileSync(path.join(source, file), "fixture\n"); fs.copyFileSync(path.join(repoRoot, "quick-start.html"), path.join(source, "quick-start.html")); + fs.writeFileSync(path.join(source, "build-revision.txt"), "muSRFlow=" + "b".repeat(40) + "\n"); fs.writeFileSync(path.join(source, "package.json"), JSON.stringify({ version: "1.2.3" })); const options = { encoding: "utf8", env: { ...process.env, MUSRFLOW_WEB_TARGET: path.join(target, "web"), @@ -102,7 +103,7 @@ function testDocumentationDeployment() { const installedHelp = fs.readFileSync(path.join(target, "web/quick-start.html"), "utf8"); assert.match(installedHelp, /id="musrflowVersion">1\.2\.3Webunrecordedbbbbbbbbbbbb