Skip to content

Instantly share code, notes, and snippets.

@jakzal
Last active May 9, 2026 20:09
Show Gist options
  • Select an option

  • Save jakzal/aa884c124eac90aa1570efc5f9fc1eb6 to your computer and use it in GitHub Desktop.

Select an option

Save jakzal/aa884c124eac90aa1570efc5f9fc1eb6 to your computer and use it in GitHub Desktop.
Generate a project version
# Versioning rules:
# - tagged commit -> <semver> -> 1.2.3
# - commit after tag -> <semver>.<commit-count-since-tag>-<shortsha> -> 1.2.3.133-f6101c9
# - no tags yet -> 0.0.0.<commit-count>-<shortsha> -> 0.0.0.133-f6101c9
VERSION ?= $(shell git describe --tags --always --long 2>/dev/null | sed -E 's/-0-g.*//;s/-(.*)-g/.\1-/;s/^[0-9a-f]+$$/0.0.0.'$(shell git rev-list --count HEAD)'-&/')
version: ## Generates the current project version
@echo $(VERSION)
.PHONY: version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment