Created
April 12, 2019 16:59
-
-
Save nilium/bd3adf2bd985d2d2edec5b63287d693c to your computer and use it in GitHub Desktop.
Script to print Go module v0.0.0-DATE-SHA version strings
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 | |
# Usage: gomodver [REF...] | |
# Prints a Go modules v0.0.0-DATE-SHA version string for the given Git refs. | |
# If no REF is given, gomodver defaults to HEAD. | |
datearg=d@ | |
case "$(uname -s | tr A-Z a-z)" in | |
*bsd|darwin) datearg=r; | |
esac | |
if [ $# -eq 0 ]; then | |
set -- HEAD | |
fi | |
nl='' | |
for ref; do | |
head="$(git rev-parse "$ref")" | |
shortsha="${head:0:12}" | |
ts="$(git log -n1 --date=raw --format='%cd' "$head" | cut -f1 -d' ')" | |
committed="$(date "-${datearg}${ts}" -u '+%Y%m%d%H%M%S')" | |
printf "%sv0.0.0-%s-%s" "${nl}" "${committed}" "${shortsha}" | |
nl=$'\n' | |
done | |
if [ -t 1 ]; then | |
printf '\n' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment