From e1dfd2e400b402b59f974b4ba1a2738b6160e556 Mon Sep 17 00:00:00 2001 From: Nick Irvine Date: Thu, 17 Oct 2019 17:47:44 -0700 Subject: [PATCH] pipeline: use automatic changelog --- Makefile.release | 10 ++++- scripts/changelog | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100755 scripts/changelog diff --git a/Makefile.release b/Makefile.release index 90db6555..810006f0 100644 --- a/Makefile.release +++ b/Makefile.release @@ -31,13 +31,19 @@ publish-github: publish-github-darwin publish-github-linux publish-github-window publish-packagecloud: publish-packagecloud-deb publish-packagecloud-rpm github-release: - github-release release \ + scripts/changelog | github-release release \ --security-token $$GH_LOGIN \ --user segmentio \ --repo chamber \ $(GITHUB_RELEASE_FLAGS) \ --tag $(VERSION) \ - --name $(VERSION) + --description - \ + --name $(VERSION) || \ + github-release info \ + --security-token $$GH_LOGIN \ + --user segmentio \ + --repo chamber \ + --tag $(VERSION) publish-github-darwin: dist/chamber-$(VERSION)-darwin-amd64 | github-release github-release upload \ diff --git a/scripts/changelog b/scripts/changelog new file mode 100755 index 00000000..d129d843 --- /dev/null +++ b/scripts/changelog @@ -0,0 +1,96 @@ +#!/bin/bash + +# generates a markdown-formatted changelog + +set -euo pipefail + +commit_url_base='https://github.com/segmentio/chamber/commit' + +# generates a changelog between the current commit and the previous tag +changelog() { + local repo_url prev current excludes current_sha current_tag + + # if HEAD is a tag already, prev will the be second (non-prerelease) line + if git describe --exact-match --tags > /dev/null 2>&1; then + prev="$(git -c versionsort.suffix=- tag -l --sort=-v:refname | awk 'NR > 1 {print}' | grep -v '-' | awk 'NR == 1 {print}')" + current_tag="$(git -c versionsort.suffix=- tag -l --sort=-v:refname | awk 'NR == 1 {print}')" + else + prev="$(git -c versionsort.suffix=- tag -l --sort=-v:refname | grep -v '-' | awk 'NR == 1 {print}')" + fi + current=HEAD + + # head -1 actually closes the pipe early, causing a SIGPIPE + set +o pipefail + current_sha="$(git log --pretty=format:%h | head -1)" + set -o pipefail + + if [[ -z "${current_tag:-}" ]]; then + echo "# ${current_sha} vs ${prev}" + else + echo "# ${current_tag} vs ${prev}" + fi + + + declare -a feat pipeline fix meta misc lines + local lines + local lines_s + local feat=() + local pipeline=() + local fix=() + local meta=() + local misc=() + oldifs=$IFS + lines_s=$(git log --pretty=format:"* [\`%h\`](${commit_url_base}/%H) %s (%an)" "${prev}..${current}" -- . ${excludes}) + local IFS=$'\n' + lines=($lines_s) + for line in "${lines[@]:-}"; do + if echo $line | grep -E ') feat[^:]*:' > /dev/null 2>&1; then + feat+=("$line") + elif echo $line | grep -E ') pipeline[^:]*:' > /dev/null 2>&1; then + pipeline+=("$line") + elif echo $line | grep -E ') fix[^:]*:' > /dev/null 2>&1; then + fix+=("$line") + elif echo $line | grep -E ') meta[^:]*:' > /dev/null 2>&1; then + meta+=("$line") + else + misc+=("$line") + fi + done + + if [[ "${#feat[@]}" -gt 0 ]]; then + echo "# Features" + for l in "${feat[@]}"; do + echo "$l" + done + fi + + if [[ "${#fix[@]}" -gt 0 ]]; then + echo "# Fixes" + for l in "${fix[@]}"; do + echo "$l" + done + fi + + if [[ "${#pipeline[@]}" -gt 0 ]]; then + echo "# Pipeline" + for l in "${pipeline[@]}"; do + echo "$l" + done + fi + + if [[ "${#meta[@]}" -gt 0 ]]; then + echo "# Meta" + for l in "${meta[@]}"; do + echo "$l" + done + fi + + if [[ "${#misc[@]}" -gt 0 ]]; then + echo "# Misc" + for l in "${misc[@]}"; do + echo "$l" + done + fi +} + +changelog