Add scripts and CHANGELOG.md

This commit is contained in:
wpioneer 2018-10-24 12:32:55 +03:00
parent 5c4e5e32de
commit 00c468d258
3 changed files with 81 additions and 0 deletions

3
CHANGELOG.md Normal file
View File

@ -0,0 +1,3 @@
# Change Log
All notable changes to this project will be documented in this file.

31
scripts/update_changelog.sh Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -e
usage() {
echo "$0 <tag> <repo>" >&2;
}
if [ "$1" = "-h" -o "$1" = "--help" ]; then
usage
exit 1;
fi
if [ -z "$2" ]
then
REPO=$(git ls-remote --get-url origin | \
sed -u 's/git@//g; s/https:\/\///g; s/github.com\///g; s/\.git//g')
else
REPO=$2
fi
NEW_TAG=$1
CURRENT_DATE=$(date +"%Y-%m-%d")
LAST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
LAST_DATE=$(git log -1 --format=%ai $LAST_TAG)
CHANGES=$(curl -s "https://api.github.com/repos/${REPO}/pulls?state=closed" | \
jq --arg l "$LAST_DATE" -r '.[] | select((.merged_at != null) and (.closed_at > $l)) | "- [Pull #\(.number)](\(.html_url)): \(.title)"')
sed -i "4i ## [$NEW_TAG] - $CURRENT_DATE\n### Added\n${CHANGES//$'\n'/\\$'\n'}\n" CHANGELOG.md

47
scripts/update_release_note.sh Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -e
usage() {
echo "$0 <repo> <tag> [<release name>]" >&2;
}
if [ "$1" = "-h" -o "$1" = "--help" ]; then
usage
exit 1;
fi
if [ -z "$1" ]
then
REPO=$(git ls-remote --get-url origin | \
sed -u 's/git@//g; s/https:\/\///g; s/github.com\///g; s/\.git//g')
else
REPO=$1
fi
if [ -z "$2" ]
then
TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
else
TAG=$2
fi
BODY=$(awk "/$TAG/ {print; exit}" RS="\n\n" ORS="\n\n" CHANGELOG.md | tail -n+2)
PAYLOAD=$(
jq --null-input \
--arg t "$TAG" \
--arg n "$TAG" \
--arg b "$BODY" \
'{ tag_name: $t, name: $n, body: $b}'
)
TAG_ID=$(curl -s "https://api.github.com/repos/$REPO/releases/tags/$TAG" | jq -r '.id')
curl --fail \
--netrc \
--silent \
--location \
--request PATCH \
--data "$PAYLOAD" \
"https://api.github.com/repos/${REPO}/releases/${TAG_ID}"