From d27e16e9ca81f2d65f4d1a4655a4c32f8d60c880 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 8 Aug 2021 12:34:11 +0530 Subject: [PATCH] Add a VERSION file for git-archive export - Use git to get tag and commit hash or fall back to extracting the values from the VERSION file if it is (from git archive) --- .gitattributes | 1 + Makefile | 8 ++++++-- VERSION | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 VERSION diff --git a/.gitattributes b/.gitattributes index fbad357..16225b4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ frontend/* linguist-vendored +VERSION export-subst diff --git a/Makefile b/Makefile index 0434c89..ff8f1c5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ -LAST_COMMIT := $(shell git rev-parse --short HEAD) -VERSION := $(shell git describe --tags --abbrev=0) +# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback. +LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"UNKNOWN") + +# Try to get the semver from 1) git 2) the VERSION file 3) fallbakc. +VERSION := $(or $(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP "tag: \K(.*)(?=,)" VERSION),"v0.0.0") + BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")) YARN ?= yarn diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..4df4b1d --- /dev/null +++ b/VERSION @@ -0,0 +1,2 @@ +$Format:%h$ +$Format:%D$