aboutsummaryrefslogtreecommitdiffstats
path: root/development
diff options
context:
space:
mode:
authorMark Stacey <markjstacey@gmail.com>2019-07-11 22:08:23 +0800
committerGitHub <noreply@github.com>2019-07-11 22:08:23 +0800
commit09eca3cc60db8a00e8ffb5ebb15ff42992eec044 (patch)
treea050fed9b4c203ea8594de4875bb3436ee240278 /development
parent1ca23078c44669c1d6d8638e7c18cac85984db27 (diff)
downloadtangerine-wallet-browser-09eca3cc60db8a00e8ffb5ebb15ff42992eec044.tar.gz
tangerine-wallet-browser-09eca3cc60db8a00e8ffb5ebb15ff42992eec044.tar.zst
tangerine-wallet-browser-09eca3cc60db8a00e8ffb5ebb15ff42992eec044.zip
Improve auto changelog script (#6753)
* Improve auto changelog script The auto changelog script was creating empty or invalid entries in a number of different cases, such as when the body of a commit spanned multiple lines. This has been fixed, and the following additional improvements have been made: - Error handling (it will now crash upon encountering an error) - Commits without a PR number in the subject are listed without the PR prefix - Invalid shellcheck warnings ignored - Only the first line of the commit body is shown - Carriage returns are stripped (some commits contain them) This script should be more reliable for helping to manually update the changelog. It's still not sufficiently robust to use as part of an automated process - I don't think that's feasible without maintaining stricter control over commit messages conventions and/or merge strategies.
Diffstat (limited to 'development')
-rwxr-xr-xdevelopment/auto-changelog.sh72
1 files changed, 53 insertions, 19 deletions
diff --git a/development/auto-changelog.sh b/development/auto-changelog.sh
index f9f577ade..3ed059b3d 100755
--- a/development/auto-changelog.sh
+++ b/development/auto-changelog.sh
@@ -1,26 +1,60 @@
-#! /bin/bash
-# update tags
+#!/usr/bin/env bash
+
+set -e
+set -u
+set -o pipefail
+
+readonly URL='https://github.com/MetaMask/metamask-extension'
+
git fetch --tags
-# get origin
-URL='https://github.com/MetaMask/metamask-extension'
-# get git logs from last tag until HEAD, pretty by 'subject::body' filtered by grep for PRs made with Github squash merge or Github regular merge
-LOG=$(git log $(git describe --tags $(git rev-list --tags --max-count=1))..HEAD --pretty="%s::%b" --reverse --grep="Merge pull request #" --grep="(#");
-while read -r line; do
- # get git log subject
- SUBJECT=$(echo $line | sed -E 's/(.*):{2}(.*)/\1/')
- # get git log PR id, PR made with Github squash merge or Github regular merge
- PR=$(echo $SUBJECT | sed 's/^.*(#\([^&]*\)).*/\1/' | sed 's/^.*#\([^&]*\) from.*/\1/')
- # if PR made with Github squash merge, subject is the body
- if [ -z "$(echo $line | sed -E 's/(.*):{2}(.*)/\2/')" ]; then
- BODY=$(echo $SUBJECT | sed "s/(#$PR)//g"); else
- BODY=$(echo $line | sed -E 's/(.*):{2}(.*)/\2/')
+
+most_recent_tag="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
+
+git rev-list "${most_recent_tag}"..HEAD | while read commit
+do
+ subject="$(git show -s --format="%s" "$commit")"
+
+ # Squash & Merge: the commit subject is parsed as `<description> (#<PR ID>)`
+ if grep -E -q '\(#[[:digit:]]+\)' <<< "$subject"
+ then
+ pr="$(awk '{print $NF}' <<< "$subject" | tr -d '()')"
+ prefix="[$pr]($URL/pull/${pr###}): "
+ description="$(awk '{NF--; print $0}' <<< "$subject")"
+
+ # Merge: the PR ID is parsed from the git subject (which is of the form `Merge pull request
+ # #<PR ID> from <branch>`, and the description is assumed to be the first line of the body.
+ # If no body is found, the description is set to the commit subject
+ elif grep -E -q '#[[:digit:]]+\sfrom' <<< "$subject"
+ then
+ pr="$(awk '{print $4}' <<< "$subject")"
+ prefix="[$pr]($URL/pull/${pr###}): "
+
+ first_line_of_body="$(git show -s --format="%b" "$commit" | head -n 1 | tr -d '\r')"
+ if [[ -z "$first_line_of_body" ]]
+ then
+ description="$subject"
+ else
+ description="$first_line_of_body"
+ fi
+
+ # Normal commits: The commit subject is the description, and the PR ID is omitted.
+ else
+ pr=''
+ prefix=''
+ description="$subject"
fi
+
# add entry to CHANGELOG
- if [[ "$OSTYPE" == "linux-gnu" ]]; then
+ if [[ "$OSTYPE" == "linux-gnu" ]]
+ then
+ # shellcheck disable=SC1004
sed -i'' '/## Current Develop Branch/a\
-- [#'"$PR"']('"$URL"'/pull/'"$PR"'): '"$BODY"''$'\n' CHANGELOG.md; else
+- '"$prefix$description"''$'\n' CHANGELOG.md
+ else
+ # shellcheck disable=SC1004
sed -i '' '/## Current Develop Branch/a\
-- [#'"$PR"']('"$URL"'/pull/'"$PR"'): '"$BODY"''$'\n' CHANGELOG.md;
+- '"$prefix$description"''$'\n' CHANGELOG.md
fi
-done <<< "$LOG"
+done
+
echo 'CHANGELOG updated'