extract the git version from the remote repo when it's a shallow clone to allow the sgum-packager work with release branches
This commit is contained in:
+47
-6
@@ -30,6 +30,8 @@
|
||||
|
||||
SG_PROJECT_NAME := The SenseGlove Unreal Engine Handbook
|
||||
|
||||
SG_PROJECT_GIT_REPOSITORY := https://dev.azure.com/SenseGlove/SenseGlove-Unreal/_git/SenseGlove-Unreal
|
||||
|
||||
SG_HANDBOOK_ESCAPED_NAME := $(shell echo $(SG_PROJECT_NAME) | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')
|
||||
|
||||
SG_HANDBOOK_DIR := $(CURDIR)
|
||||
@@ -40,6 +42,9 @@ SG_HANDBOOK_DEPLOY_CONFIG_FILENAME := deploy.conf
|
||||
SG_HANDBOOK_DEPLOY_TEMP_DIR_NAME := unreal-docs-senseglove-com-deploy-XXXXXXXXXX
|
||||
SG_HANDBOOK_FAVICON_FILE := $(SG_HANDBOOK_SRC_DIR)/favicon.svg
|
||||
|
||||
SG_DOT_GIT_DIR := $(realpath $(SG_HANDBOOK_DIR)/../.git)
|
||||
SG_DOT_GIT_SHALLOW_FILE := $(realpath $(SG_DOT_GIT_DIR)/shallow)
|
||||
|
||||
SG_PLUGIN_DIR := $(realpath $(SG_HANDBOOK_DIR)/..)
|
||||
SG_PLUGIN_RESOURCES_DIR := $(SG_PLUGIN_DIR)/Resources
|
||||
SG_PLUGIN_FILE := $(SG_PLUGIN_DIR)/SenseGlove.uplugin
|
||||
@@ -116,13 +121,21 @@ SG_PLUGIN_PLATFORM_SUPPORT_MATRIX_FILE := $(SG_PLUGIN_DIR)/PLATFORM_SUPPORT_M
|
||||
# Version and Build Information
|
||||
################################################################################
|
||||
|
||||
SG_GIT_TREE_STATE_CLEAN := clean
|
||||
SG_GIT_TREE_STATE_DIRTY := dirty
|
||||
|
||||
SG_GIT_NO := no
|
||||
SG_GIT_YES := yes
|
||||
|
||||
SG_RELEASE_BRANCH_PATTERN := ^[0-9]+\.[0-9]+$$
|
||||
|
||||
SG_GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||
SG_GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null)
|
||||
SG_GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
|
||||
SG_GIT_COMMIT_NUMS_SINCE_TAG := $(shell git rev-list --count HEAD ^`git describe --tags --abbrev=0 2>/dev/null` 2>/dev/null)
|
||||
SG_GIT_TREE_STATE := $(shell test -n "`git status --porcelain 2>/dev/null`" && echo "dirty" || echo "clean")
|
||||
SG_GIT_TREE_STATE := $(shell test -n "`git status --porcelain 2>/dev/null`" && echo "$(SG_GIT_TREE_STATE_DIRTY)" || echo "$(SG_GIT_TREE_STATE_CLEAN)")
|
||||
SG_GIT_IS_SHALLOW_CLONE := $(shell [ -d $(SG_DOT_GIT_DIR) ] && [ -f $(SG_DOT_GIT_SHALLOW_FILE) ] && echo "$(SG_GIT_YES)" || echo "$(SG_GIT_NO)")
|
||||
SG_GIT_LATEST_REMOTE_TAG := $(shell git -c versionsort.suffix=- ls-remote --exit-code --refs --sort=version:refname --tags $(SG_PROJECT_GIT_REPOSITORY) '*.*.*' | tail -n 1 | sed 's/.*refs\/tags\///' 2>/dev/null)
|
||||
|
||||
SG_PLUGIN_VERSION := $(shell grep -o '"VersionName": "[^"]*"' ${SG_PLUGIN_FILE} | awk -F'"' '{print "v" $$4}')
|
||||
|
||||
@@ -134,17 +147,25 @@ ifneq ($(strip $(SG_GIT_TAG)),)
|
||||
SG_GIT_VERSION := $(SG_GIT_TAG)
|
||||
endif # ($(strip $(SG_GIT_TAG)),)
|
||||
|
||||
SG_GIT_VERSION_MAJOR := $(shell echo $(SG_GIT_TAG) | cut -d '.' -f 1 | tr -d -c 0-9)
|
||||
ifeq ($(strip $(SG_GIT_VERSION)),)
|
||||
ifeq ($(strip $(SG_GIT_IS_SHALLOW_CLONE)),$(SG_GIT_YES))
|
||||
ifneq ($(strip $(SG_GIT_LATEST_REMOTE_TAG)),)
|
||||
SG_GIT_VERSION := $(SG_GIT_LATEST_REMOTE_TAG)
|
||||
endif # ($(strip $(SG_GIT_LATEST_REMOTE_TAG)),)
|
||||
endif # ($(strip $(SG_GIT_IS_SHALLOW_CLONE)),$(SG_GIT_YES))
|
||||
endif # ($(strip $(SG_GIT_VERSION)),)
|
||||
|
||||
SG_GIT_VERSION_MAJOR := $(shell echo $(SG_GIT_VERSION) | cut -d '.' -f 1 | tr -d -c 0-9)
|
||||
ifeq ($(SG_GIT_VERSION_MAJOR),)
|
||||
SG_GIT_VERSION_MAJOR := 0
|
||||
endif # ($(SG_GIT_VERSION_MAJOR),)
|
||||
|
||||
SG_GIT_VERSION_MINOR := $(shell echo $(SG_GIT_TAG) | cut -d '.' -f 2 | tr -d -c 0-9)
|
||||
SG_GIT_VERSION_MINOR := $(shell echo $(SG_GIT_VERSION) | cut -d '.' -f 2 | tr -d -c 0-9)
|
||||
ifeq ($(SG_GIT_VERSION_MINOR),)
|
||||
SG_GIT_VERSION_MINOR := 0
|
||||
endif # ($(SG_GIT_VERSION_MINOR),)
|
||||
|
||||
SG_GIT_VERSION_PATCH := $(shell echo $(SG_GIT_TAG) | cut -d '.' -f 3 | tr -d -c 0-9)
|
||||
SG_GIT_VERSION_PATCH := $(shell echo $(SG_GIT_VERSION) | cut -d '.' -f 3 | tr -d -c 0-9)
|
||||
ifeq ($(SG_GIT_VERSION_PATCH),)
|
||||
SG_GIT_VERSION_PATCH := 0
|
||||
endif # ($(SG_GIT_VERSION_PATCH),)
|
||||
@@ -177,14 +198,23 @@ SG_IS_GIT_BRANCH_HEAD_OR_MASTER := $(or $(filter HEAD,$(strip $(SG_GIT_BRANCH)))
|
||||
|
||||
ifneq ($(SG_IS_GIT_BRANCH_HEAD_OR_MASTER),)
|
||||
ifeq ($(strip $(SG_GIT_COMMIT_NUMS_SINCE_TAG)),0)
|
||||
ifeq ($(strip $(SG_GIT_TREE_STATE)),clean)
|
||||
ifeq ($(strip $(SG_GIT_TREE_STATE)),$(SG_GIT_TREE_STATE_CLEAN))
|
||||
ifeq ($(strip $(SG_GIT_VERSION)),$(strip $(SG_PLUGIN_VERSION)))
|
||||
SG_HANDBOOK_REVISION := $(SG_PLUGIN_VERSION_MAJOR).$(SG_PLUGIN_VERSION_MINOR)
|
||||
endif # ($(strip $(SG_GIT_VERSION)),$(strip $(SG_PLUGIN_VERSION)))
|
||||
endif # ($(strip $(SG_GIT_TREE_STATE)),clean)
|
||||
endif # ($(strip $(SG_GIT_TREE_STATE)),$(SG_GIT_TREE_STATE_CLEAN))
|
||||
endif # ($(strip $(SG_GIT_COMMIT_NUMS_SINCE_TAG)),0)
|
||||
endif # ($(SG_IS_GIT_BRANCH_HEAD_OR_MASTER),)
|
||||
|
||||
ifeq ($(strip $(SG_GIT_IS_SHALLOW_CLONE)),$(SG_GIT_YES))
|
||||
SG_IS_GIT_BRANCH_RELEASE := $(shell echo $(SG_GIT_BRANCH) | grep -E '$(SG_RELEASE_BRANCH_PATTERN)' || echo "")
|
||||
ifneq ($(SG_IS_GIT_BRANCH_RELEASE),)
|
||||
ifeq ($(strip $(SG_GIT_VERSION)),$(strip $(SG_PLUGIN_VERSION)))
|
||||
SG_HANDBOOK_REVISION := $(SG_PLUGIN_VERSION_MAJOR).$(SG_PLUGIN_VERSION_MINOR)
|
||||
endif # ($(strip $(SG_GIT_VERSION)),$(strip $(SG_PLUGIN_VERSION)))
|
||||
endif # ($(SG_IS_GIT_BRANCH_RELEASE),)
|
||||
endif # ($(strip $(SG_GIT_IS_SHALLOW_CLONE)),$(SG_GIT_YES))
|
||||
|
||||
ifeq ($(strip $(SG_HANDBOOK_REVISION)),)
|
||||
SG_HANDBOOK_REVISION := mismatched
|
||||
endif # ($(strip $(SG_HANDBOOK_REVISION)),)
|
||||
@@ -307,6 +337,8 @@ info:
|
||||
@echo " - Git Commit : $(SG_GIT_COMMIT)"
|
||||
@echo " - Git Commits Since Tag : $(SG_GIT_COMMIT_NUMS_SINCE_TAG)"
|
||||
@echo " - Git Tree State : $(SG_GIT_TREE_STATE)"
|
||||
@echo " - Git Is Shallow Clone : $(SG_GIT_IS_SHALLOW_CLONE)"
|
||||
@echo " - Git Latest Remote Tag : $(SG_GIT_LATEST_REMOTE_TAG)"
|
||||
@echo " - Git Version : $(SG_GIT_VERSION)"
|
||||
@echo " - Git Version Major : $(SG_GIT_VERSION_MAJOR)"
|
||||
@echo " - Git Version Minor : $(SG_GIT_VERSION_MINOR)"
|
||||
@@ -376,6 +408,11 @@ ifeq ($(SG_HANDBOOK_REVISION), mismatched)
|
||||
@echo " - You're building from the dev branch."
|
||||
@echo " - The Git version value evaluates to empty."
|
||||
@echo ""
|
||||
@echo "If you're packaging the handbook:"
|
||||
@echo " - You're on a release branch."
|
||||
@echo " - You're shallow cloning."
|
||||
@echo " - The remorte Git repository contains releae tags."
|
||||
@echo ""
|
||||
@exit 1
|
||||
else # ($(SG_HANDBOOK_REVISION), mismatched)
|
||||
@echo "Building a release handbook: $(SG_HANDBOOK_REVISION)..."
|
||||
@@ -424,6 +461,8 @@ _mdbook_serve:
|
||||
SG_GIT_COMMIT='$(SG_GIT_COMMIT)' \
|
||||
SG_GIT_COMMIT_NUMS_SINCE_TAG='$(SG_GIT_COMMIT_NUMS_SINCE_TAG)' \
|
||||
SG_GIT_TREE_STATE='$(SG_GIT_TREE_STATE)' \
|
||||
SG_GIT_IS_SHALLOW_CLONE='$(SG_GIT_IS_SHALLOW_CLONE)' \
|
||||
SG_GIT_LATEST_REMOTE_TAG='$(SG_GIT_LATEST_REMOTE_TAG)' \
|
||||
SG_GIT_VERSION='$(SG_GIT_VERSION)' \
|
||||
SG_GIT_VERSION_MAJOR='$(SG_GIT_VERSION_MAJOR)' \
|
||||
SG_GIT_VERSION_MINOR='$(SG_GIT_VERSION_MINOR)' \
|
||||
@@ -453,6 +492,8 @@ _mdbook_build:
|
||||
SG_GIT_TAG='$(SG_GIT_TAG)' \
|
||||
SG_GIT_COMMIT='$(SG_GIT_COMMIT)' \
|
||||
SG_GIT_COMMIT_NUMS_SINCE_TAG='$(SG_GIT_COMMIT_NUMS_SINCE_TAG)' \
|
||||
SG_GIT_IS_SHALLOW_CLONE='$(SG_GIT_IS_SHALLOW_CLONE)' \
|
||||
SG_GIT_LATEST_REMOTE_TAG='$(SG_GIT_LATEST_REMOTE_TAG)' \
|
||||
SG_GIT_TREE_STATE='$(SG_GIT_TREE_STATE)' \
|
||||
SG_GIT_VERSION='$(SG_GIT_VERSION)' \
|
||||
SG_GIT_VERSION_MAJOR='$(SG_GIT_VERSION_MAJOR)' \
|
||||
|
||||
@@ -49,6 +49,8 @@ SG_GIT_TAG_ESCAPED=$(escape_string "${SG_GIT_TAG}")
|
||||
SG_GIT_COMMIT_ESCAPED=$(escape_string "${SG_GIT_COMMIT}")
|
||||
SG_GIT_COMMIT_NUMS_SINCE_TAG_ESCAPED=$(escape_string "${SG_GIT_COMMIT_NUMS_SINCE_TAG}")
|
||||
SG_GIT_TREE_STATE_ESCAPED=$(escape_string "${SG_GIT_TREE_STATE}")
|
||||
SG_GIT_IS_SHALLOW_CLONE_ESCAPED=$(escape_string "${SG_GIT_IS_SHALLOW_CLONE}")
|
||||
SG_GIT_LATEST_REMOTE_TAG_ESCAPED=$(escape_string "${SG_GIT_LATEST_REMOTE_TAG}")
|
||||
SG_GIT_VERSION_ESCAPED=$(escape_string "${SG_GIT_VERSION}")
|
||||
SG_GIT_VERSION_MAJOR_ESCAPED=$(escape_string "${SG_GIT_VERSION_MAJOR}")
|
||||
SG_GIT_VERSION_MINOR_ESCAPED=$(escape_string "${SG_GIT_VERSION_MINOR}")
|
||||
@@ -74,6 +76,8 @@ PARSED_BOOK=$(echo "${BOOK}" | xq "
|
||||
gsub(\"{{ #sg-git-commit }}\"; \"${SG_GIT_COMMIT_ESCAPED}\") |
|
||||
gsub(\"{{ #sg-git-commit-nums-since-tag }}\"; \"${SG_GIT_COMMIT_NUMS_SINCE_TAG_ESCAPED}\") |
|
||||
gsub(\"{{ #sg-git-tree-state }}\"; \"${SG_GIT_TREE_STATE_ESCAPED}\") |
|
||||
gsub(\"{{ #sg-git-is-shallow-clone }}\"; \"${SG_GIT_IS_SHALLOW_CLONE_ESCAPED}\") |
|
||||
gsub(\"{{ #sg-git-latest-remote-tag }}\"; \"${SG_GIT_LATEST_REMOTE_TAG_ESCAPED}\") |
|
||||
gsub(\"{{ #sg-git-version }}\"; \"${SG_GIT_VERSION_ESCAPED}\") |
|
||||
gsub(\"{{ #sg-git-version-major }}\"; \"${SG_GIT_VERSION_MAJOR_ESCAPED}\") |
|
||||
gsub(\"{{ #sg-git-version-minor }}\"; \"${SG_GIT_VERSION_MINOR_ESCAPED}\") |
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
| Git Commit | {{ #sg-git-commit }} |
|
||||
| Git Commits Since Tag | {{ #sg-git-commit-nums-since-tag }} |
|
||||
| Git Tree State | {{ #sg-git-tree-state }} |
|
||||
| Git Is Shallow Clone | {{ #sg-git-is-shallow-clone }} |
|
||||
| Git Latest Remote Tag | {{ #sg-git-latest-remote-tag }} |
|
||||
| Git Version | {{ #sg-git-version }} |
|
||||
| Git Version Major | {{ #sg-git-version-major }} |
|
||||
| Git Version Minor | {{ #sg-git-version-minor }} |
|
||||
|
||||
Reference in New Issue
Block a user