Skip to content

Instantly share code, notes, and snippets.

@anubhavsrivastava
Created December 27, 2019 14:28
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 anubhavsrivastava/879b4d162768820561e72fc759f2c5b0 to your computer and use it in GitHub Desktop.
Save anubhavsrivastava/879b4d162768820561e72fc759f2c5b0 to your computer and use it in GitHub Desktop.
bash script to generate release notes from github repo
#!/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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment