Skip to content

Commit

Permalink
fix: version for tags with -arabica, -mocha, -rc suffixes (#3977)
Browse files Browse the repository at this point in the history
Closes #3933

## Testing 

```
$ git checkout v2.2.0-mocha
$ make debug-version
GIT_TAG: v2.2.0-mocha
VERSION: 2.2.0-mocha
$ git tag --delete v2.2.0-mocha
Deleted tag 'v2.2.0-mocha' (was d3f8b29)
$ make debug-version
GIT_TAG: v2.2.0-arabica
VERSION: 2.2.0-arabica
$ git tag --delete v2.2.0-arabica
Deleted tag 'v2.2.0-arabica' (was d3f8b29)
$ make debug-version
GIT_TAG: v2.2.0-rc0
VERSION: 2.2.0-rc0
$ git tag --delete v2.2.0-rc0
Deleted tag 'v2.2.0-rc0' (was d3f8b29)
$ make debug-version
GIT_TAG: v2.1.2-4-gd3f8b2997
VERSION: 2.1.2-4-gd3f8b2997
```
  • Loading branch information
rootulp authored Oct 16, 2024
1 parent b1f43f5 commit 3d49b60
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
VERSION := $(shell echo $(shell git describe --tags 2>/dev/null || git log -1 --format='%h') | sed 's/^v//')
# GIT_TAG is an environment variable that is set to the latest git tag on the
# current commit with the following example priority: v2.2.0, v2.2.0-mocha,
# v2.2.0-arabica, v2.2.0-rc0, v2.2.0-beta, v2.2.0-alpha. If no tag points to the
# current commit, git describe is used. The priority in this command is
# necessary because `git tag --sort=-creatordate` only works for annotated tags
# with metadata. Git tags created via GitHub releases are not annotated and do
# not have metadata like creatordate. Therefore, this command is a hacky attempt
# to get the most recent tag on the current commit according to Celestia's
# testnet versioning scheme + SemVer.
GIT_TAG := $(shell git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-mocha$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-arabica$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]*$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(beta)$$' \
|| git tag --points-at HEAD --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-(alpha)$$' \
|| git describe --tags)
VERSION := $(shell echo $(GIT_TAG) | sed 's/^v//')
COMMIT := $(shell git rev-parse --short HEAD)
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
Expand Down Expand Up @@ -256,3 +272,9 @@ enable-bbr:
echo "BBR is already enabled."; \
fi
.PHONY: enable-bbr

## debug-version: Print the git tag and version.
debug-version:
@echo "GIT_TAG: $(GIT_TAG)"
@echo "VERSION: $(VERSION)"
.PHONY: debug-version

0 comments on commit 3d49b60

Please sign in to comment.