From 594838099780fe0b9e7301143468fbfc6157f4c9 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Wed, 7 Apr 2021 01:01:01 +0800 Subject: automatically generate version info from git HEAD --- .gitignore | 1 + Makefile | 7 +++++-- chapter01/changelog.xml | 1 + general.ent | 21 +++++++++++++++------ git-version.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 8 deletions(-) create mode 100755 git-version.sh diff --git a/.gitignore b/.gitignore index 4d9db122b..9f764ff0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ lfs-bootscripts-*.tar.xz +version.ent diff --git a/Makefile b/Makefile index c28733ce3..83064f376 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ tmpdir: $(Q)rm -f $(RENDERTMP)/*md5sum* $(Q)rm -f $(RENDERTMP)/*pdf.fo -validate: tmpdir +validate: tmpdir version @echo "Processing bootscripts..." $(Q)bash process-scripts.sh @@ -187,6 +187,9 @@ $(BASEDIR)/md5sums: stylesheets/wget-list.xsl chapter03/chapter03.xml \ "s/BOOTSCRIPTS-MD5SUM/$(shell md5sum lfs-bootscripts*.tar.xz | cut -d' ' -f1)/" \ $(BASEDIR)/md5sums +version: + $(Q)./git-version.sh + #dump-commands: validate # @echo "Dumping book commands..." # $(Q)xsltproc --nonet \ @@ -204,5 +207,5 @@ $(BASEDIR)/md5sums: stylesheets/wget-list.xsl chapter03/chapter03.xml \ all: book nochunks pdf # dump-commands -.PHONY : all book dump-commands nochunks pdf profile-html tmpdir validate md5sums wget-list +.PHONY : all book dump-commands nochunks pdf profile-html tmpdir validate md5sums wget-list version diff --git a/chapter01/changelog.xml b/chapter01/changelog.xml index cd59ea662..b02437f6d 100644 --- a/chapter01/changelog.xml +++ b/chapter01/changelog.xml @@ -42,6 +42,7 @@ or as appropriate for the entry or if needed the entire day's listitem. --> + 2021-03-26 diff --git a/general.ent b/general.ent index 0db8fe99b..90443c9b5 100644 --- a/general.ent +++ b/general.ent @@ -1,16 +1,25 @@ - + + +%version-entities; + + + + + - - - - - diff --git a/git-version.sh b/git-version.sh new file mode 100755 index 000000000..8b1f13d00 --- /dev/null +++ b/git-version.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +if ! git status; then + # Either it's not a git repository, or git is unavaliable. + # Just workaround. + echo "" > version.ent + echo "" >> version.ent + echo "" >> version.ent + echo "" >> version.ent + exit 0 +fi + +export LC_ALL=en_US.utf8 +export TZ=US/Pacific + +commit_date=$(git show -s --format=format:"%cd" --date=local) +short_date=$(date --date "$commit_date" "+%Y%m%d") + +year=$(date --date "$commit_date" "+%Y") +month=$(date --date "$commit_date" "+%B") +month_digit=$(date --date "$commit_date" "+%m") +day=$(date --date "$commit_date" "+%d") + +case $day in + "1" | "21" | "31" ) suffix="st";; + "2" | "22" ) suffix="nd";; + "3" | "23" ) suffix="rd";; + * ) suffix="th";; +esac + +full_date="$month $day$suffix, $year" + +sha="g$(git describe --always)" +version="GIT-$short_date-$sha" +versiond="GIT-$short_date-$sha-systemd" + +if [ "$(git diff HEAD | wc -l)" != "0" ]; then + version="$version-MODIFIED" + versiond="$versiond-MODIFIED" +fi + +echo "" > version.ent +echo "" >> version.ent +echo "" >> version.ent +echo "" >> version.ent -- cgit v1.2.3-54-g00ecf