Created
May 6, 2026 23:42
-
-
Save neomantra/bbcaf189347221ee70bef493cb20f40c to your computer and use it in GitHub Desktop.
go mod replace version-timestamp-hash extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # This script is used to generate a version string for the go.mod replace directive. | |
| # This is of the format version-timestamp-hash, where version is the current version of the module, | |
| # timestamp is the current time in UTC, and hash is the short git hash of the current commit. | |
| # | |
| # This script emits the "version-timestamp-hash" based on the current git HEAD. | |
| # | |
| # If passed with an argument, that string is used as the version, | |
| # otherwise "v0.0.0" is used as the default version. | |
| # | |
| # | |
| VERSION=${1:-"v0.0.0"} | |
| DT=$(TZ=UTC git show -s --format=%cd --date='format-local:%Y%m%d%H%M%S' HEAD) | |
| HASHISH=$(git rev-parse --short=12 HEAD) | |
| echo "$VERSION-$DT-$HASHISH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment