Skip to content

Commit de9fb46

Browse files
committed
Merge pull request #35 from mboersma/add-changelog
feat(gen-changelog.sh): add CHANGELOG.md generator
2 parents 238182d + 60daddd commit de9fb46

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@ REGISTRY ?= quay.io/
33
IMAGE_PREFIX ?= deis
44
IMAGE := ${REGISTRY}${IMAGE_PREFIX}/go-dev:${VERSION}
55

6+
# scripts are checked *after* build, so use paths inside the container
7+
SHELL_SCRIPTS = /usr/local/bin/gen-changelog.sh
8+
9+
# dockerized development environment variables
10+
DEV_ENV_PREFIX := docker run --rm -e GO15VENDOREXPERIMENT=1
11+
DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${IMAGE}
12+
613
build:
714
docker build -t ${IMAGE} rootfs
815

916
push: build
1017
docker push ${IMAGE}
18+
19+
test: build
20+
${DEV_ENV_CMD} shellcheck $(SHELL_SCRIPTS)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ creating [issues][] and submitting [pull requests][].
1111
## Image Contents
1212

1313
* based on the [official go Docker image][]
14+
* [gen-changelog.sh][]: generate updates to CHANGELOG.md
1415
* [ginkgo][]: BDD testing framework for go
1516
* [glide][]: go dependency management
1617
* [golint][]: go source code linter
@@ -46,6 +47,7 @@ The latest deis/go-dev Docker image is available at:
4647

4748
[Deis Workflow]: https://deis.com/
4849
[Docker Hub]: https://hub.docker.com
50+
[gen-changelog.sh]: https://github.com/deis/docker-go-dev/tree/master/rootfs/usr/local/bin/gen-changelog.sh
4951
[ginkgo]: https://github.com/onsi/ginkgo
5052
[glide]: https://github.com/Masterminds/glide
5153
[Go]: https://golang.org/
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Prints a Markdown-formatted summary of git commits ready to include in
4+
# a CHANGELOG.md file
5+
#
6+
# Usage: gen-changelog.sh [from] [to]
7+
# If no [from] argument is supplied, uses the most recent git tag.
8+
# if no [to] argument is supplied, uses git HEAD.
9+
#
10+
# The REPOROOT and TYPES variables may be used to customize what links are
11+
# generated and what is scraped from the commit logs.
12+
13+
set -euo pipefail
14+
15+
PACKAGE=${PACKAGE:=$(go list .)}
16+
REPOROOT=${REPOROOT:=https://$PACKAGE}
17+
TYPES=${TYPES:=feat(;Features fix(;Fixes docs(;Documentation chore(;Maintenance}
18+
19+
# Print the information scraped from git
20+
retrieve() {
21+
while read -r commit hash message; do
22+
# Extract the subsystem where type(subsystem): message
23+
SUBSYSTEM=$(echo "$message" | cut -d'(' -f2 | cut -d')' -f1 | sed 's/\*/\(all\)/g')
24+
# Extract the message where type(subsystem): message
25+
MESSAGE=$(echo "$message" | awk -F ")" '{ print $2}' | sed 's/://' | cut -f2- -d' ')
26+
# Generate a link to the full legal commit on GitHub
27+
LINK="$REPOROOT/commit/$hash"
28+
# Echo all this in a way that makes the commit hash and message a link
29+
# to the commit in markdown
30+
echo ' -' "[\`$commit\`]($LINK)" "$SUBSYSTEM": "$MESSAGE"
31+
done < <(git --no-pager log --oneline --merges --oneline --format="%h %H %b" --grep="$1" "$FROM".."$TO")
32+
# Scrape the information from git
33+
}
34+
35+
# Wrap feature type and show its relevant commits
36+
subheading() {
37+
echo "#### $1"
38+
echo
39+
retrieve "$2"
40+
echo
41+
}
42+
43+
main() {
44+
FROM=${1:-$(git describe --abbrev=0 --tags)}
45+
TO=${2:-"HEAD"}
46+
RELEASE=${RELEASE:=$TO}
47+
48+
printf "### %s -> %s\n\n" "$FROM" "$RELEASE"
49+
50+
# Iterate over the types of messages specified
51+
for LEGALTYPE in $TYPES; do
52+
SHORT=$(echo "$LEGALTYPE" | cut -f1 -d';')
53+
LONG=$(echo "$LEGALTYPE" | cut -f2 -d';')
54+
subheading "$LONG" "$SHORT"
55+
done
56+
}
57+
58+
if [ $SHLVL -eq 1 ] || [ $SHLVL -eq 2 ]; then
59+
# If this is being run as a command
60+
main "$@"
61+
>&2 echo -e "\033[0;33mBe sure to change headers, remove empty sections,"
62+
>&2 echo -e "and proofread before committing to CHANGELOG.md.\033[0m"
63+
else
64+
# Otherwise this is being sourced
65+
unset -f main
66+
unset -f usage
67+
fi

0 commit comments

Comments
 (0)