Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 8efd57c

Browse files
authored
Merge pull request #536 from erkarl/release-notes
Generate release notes from commit messages
2 parents 810f288 + 7d03225 commit 8efd57c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

assets/script/release-notes.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
# avoid issues with relative paths
4+
cd "$(dirname "$0")"
5+
6+
if [ -z "$(eval "echo \$GH_TOKEN")" ]; then
7+
echo "Missing environment variable GH_TOKEN."
8+
exit 1
9+
fi
10+
11+
GITHUB_API_ENDPOINT="https://api.github.com/repos/lightninglabs/lightning-app/releases"
12+
CURRENT_TAG=v$(sed -n 's/.*"version": "\(.*\)".*/\1/p' ../../package.json)
13+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "$(git rev-list --tags --skip=1 --max-count=1)")
14+
RELEASE_NOTES="\\n# Release Notes\\n$(git log "${PREVIOUS_TAG}"..HEAD \
15+
--merges --pretty='* %b [%h](http://github.com/lightninglabs/lightning-app/commit/%H)\n')"
16+
17+
# get existing release from Github
18+
RELEASE=$(echo \
19+
'{"releases": '"$(curl -H "Content-Type: application/json" \
20+
-H "Authorization: token $GH_TOKEN" \
21+
$GITHUB_API_ENDPOINT)"'}' \
22+
| jq '.releases[] | select(.tag_name == "'"$CURRENT_TAG"'") | {id, name, tag_name, target_commitish, body, draft}')
23+
24+
if [ -z "$RELEASE" ]; then
25+
echo "Release not found for tag $CURRENT_TAG."
26+
exit 1
27+
fi
28+
29+
# append release notes to the existing release
30+
UPDATED_RELEASE_NOTES="$(echo "$RELEASE" | jq -r .body)"$RELEASE_NOTES
31+
UPDATED_RELEASE=$(echo "$RELEASE" | jq ".body |= \"$UPDATED_RELEASE_NOTES\"")
32+
UPDATE_API_ENDPOINT=$GITHUB_API_ENDPOINT/$(echo "$RELEASE" | jq -r .id)
33+
curl \
34+
-H "Content-Type: application/json" \
35+
-H "Authorization: token $GH_TOKEN" \
36+
-X PATCH \
37+
-d "$UPDATED_RELEASE" \
38+
"$UPDATE_API_ENDPOINT";

0 commit comments

Comments
 (0)