Skip to content

Instantly share code, notes, and snippets.

@cristovaov
Created July 9, 2016 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristovaov/c7409d2e7b552298a98f82bb4ff30a79 to your computer and use it in GitHub Desktop.
Save cristovaov/c7409d2e7b552298a98f82bb4ff30a79 to your computer and use it in GitHub Desktop.
Generates a log file from latest tag and (n) of commits passed
#!/bin/bash -
#title :generate_release_log.sh
#description :generates a log file from latest tag and (n) of commits passed
#author :Cristovao Verstraeten
#date :20160709
#version :20160709
#usage :./generate_release_log.sh
#notes :
#bash_version :4.3.39(3)-release
#============================================================================
set -euo pipefail
IFS=$'\n\t'
NUMBER=$1
check_argument() {
if [[ "$NUMBER" =~ ^-[0-9]+$ ]] 2>/dev/null; then
trap 'rm tempfile' EXIT
write_release_log
else
echo "Usage: ./generate_release_log -[0-9]"
exit 0
fi
}
write_release_log() {
local TAG
local COMMITS
TAG=$(git describe --abbrev=0)
COMMITS=$(git log "$NUMBER" --pretty="%h - %s")
if [[ ! -f 'release_notes' ]]; then
touch release-log.txt
fi
cat << EOF | tee tempfile
[$TAG]
$COMMITS
EOF
cat tempfile release-log.txt > tempfile2 && mv tempfile2 release-log.txt
}
# Main
check_argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment