diff --git a/netlify.toml b/netlify.toml index 6d7d2fdcb..c0470fbc0 100644 --- a/netlify.toml +++ b/netlify.toml @@ -9,7 +9,9 @@ VITE_SHOW_SAMPLE_DATA= "true" [build] -command = "sed -i \"s|DICOM_WEB_API_KEY|${DICOM_WEB_API_KEY}|g; s|DICOM_WEB_ADDRESS|${DICOM_WEB_ADDRESS}|g\" netlify.toml && npm run build" +# The version shown in the About box comes from `git describe`, which needs tags +# and enough history to count from them. Netlify clones neither by default. +command = "{ git fetch --tags --unshallow || git fetch --tags; } 2>/dev/null; sed -i \"s|DICOM_WEB_API_KEY|${DICOM_WEB_API_KEY}|g; s|DICOM_WEB_ADDRESS|${DICOM_WEB_ADDRESS}|g\" netlify.toml && npm run build" [dev] targetPort = 8080 diff --git a/vite.config.ts b/vite.config.ts index c879bacb8..517300225 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -30,6 +30,8 @@ function resolvePath(...args: string[]) { return normalizePath(path.resolve(...args)); } +const PLACEHOLDER_VERSION = '0.0.0'; + function getPackageInfo() { const mainPkgPath = path.resolve(__dirname, 'package.json'); const mainPkg = JSON.parse(fs.readFileSync(mainPkgPath, 'utf-8')); @@ -48,13 +50,32 @@ function getPackageInfo() { return { versions: { - volview: mainPkg.version, + volview: getVolViewVersion(mainPkg.version), 'vtk.js': vtkJsPkg.version, 'itk-wasm': itkWasmPkg.version, }, }; } +// package.json carries the placeholder 0.0.0 on main; the release workflow +// stamps the real version from the pushed tag before it builds. Builds that +// skip that step (Netlify, local dev) fall back to describing the tag directly. +function getVolViewVersion(pkgVersion: string) { + if (pkgVersion !== PLACEHOLDER_VERSION) return pkgVersion; + return getGitDescribe() ?? pkgVersion; +} + +function getGitDescribe() { + try { + const described = execSync('git describe --tags --always') + .toString() + .trim(); + return described.replace(/^v/, ''); + } catch { + return undefined; + } +} + function getGitShortSha() { try { return execSync('git rev-parse --short HEAD').toString().trim();