Skip to content

Commit 062e145

Browse files
authored
Merge pull request gocsaf#650 from gocsaf/write-version
Use folder name as version if git describe failed
2 parents ce886f1 + 36aab33 commit 062e145

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ tag_checked_out:
4747
# In this case we might in some situations see an error like
4848
# `/bin/bash: line 1: 2b55bbb: value too great for base (error token is "2b55bbb")`
4949
# which can be ignored.
50-
GITDESC := $(shell git describe --tags --always)
50+
GITDESC := $(shell git describe --tags --always 2>/dev/null || true)
51+
CURRENT_FOLDER_NAME := $(notdir $(CURDIR))
52+
ifeq ($(strip $(GITDESC)),)
53+
SEMVER := $(CURRENT_FOLDER_NAME)
54+
else
5155
GITDESCPATCH := $(shell echo '$(GITDESC)' | sed -E 's/v?[0-9]+\.[0-9]+\.([0-9]+)[-+]?.*/\1/')
5256
SEMVERPATCH := $(shell echo $$(( $(GITDESCPATCH) + 1 )))
5357
# Hint: The second regexp in the next line only matches
5458
# if there is a hyphen (`-`) followed by a number,
5559
# by which we assume that git describe has added a string after the tag
5660
SEMVER := $(shell echo '$(GITDESC)' | sed -E -e 's/^v//' -e 's/([0-9]+\.[0-9]+\.)([0-9]+)(-[1-9].*)/\1$(SEMVERPATCH)\3/' )
61+
endif
5762
testsemver:
5863
@echo from \'$(GITDESC)\' transformed to \'$(SEMVER)\'
5964

0 commit comments

Comments
 (0)