script/build writes the version script/version prints into dist/package.json, which quak --version reports: the VERSION environment variable or build arg when one is given, otherwise git describe --tags --always, otherwise package.json's version. A checkout with .git whose version comes out empty, dev or unknown fails the build. .dockerignore no longer leaves out .git, and ARG VERSION has no default, so a plain docker build . of a clone stamps its commit. script/docker and script/cibuild still pass the host's version. make build-bin bundles the built dist/, so the single binary reports the same version. Model: opus-5-5
40 lines
1.2 KiB
Bash
Executable File
40 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# script/version: print the version script/build stamps into the built
|
|
# package. Our own extension to scripts-to-rule-them-all.
|
|
#
|
|
# Order of precedence:
|
|
#
|
|
# 1. $VERSION, if set and not empty: an explicit value, such as the
|
|
# Dockerfile's VERSION build arg.
|
|
# 2. If this checkout has .git, `git describe --tags --always`: the tag
|
|
# on a tagged commit, otherwise the short commit.
|
|
# 3. Otherwise, as in a source tarball, the version package.json declares.
|
|
#
|
|
# A checkout with .git whose version still comes out empty, dev or unknown
|
|
# fails: git is missing or could not read the checkout, and the build could
|
|
# not be traced back to its commit.
|
|
set -eu
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
|
|
main() {
|
|
cd "$ROOT"
|
|
version="${VERSION:-}"
|
|
if [ -e .git ]; then
|
|
if [ -z "$version" ]; then
|
|
version="$(git describe --tags --always || true)"
|
|
fi
|
|
case "$version" in
|
|
"" | dev | unknown)
|
|
echo "version: $ROOT has .git, but the version came out '$version'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
elif [ -z "$version" ]; then
|
|
version="$(node -p 'require("./package.json").version')"
|
|
fi
|
|
echo "$version"
|
|
}
|
|
|
|
main "$@"
|