-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathrelease-notes.sh
executable file
·130 lines (107 loc) · 4.31 KB
/
release-notes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Usage:
# ./release-notes.sh
# ./release-notes.sh [current-release]
# ./release-notes.sh [current-release] [previous-release]
# GITHUB_TOKEN=ghp_hJe... ./release-notes.sh
#
# Example:
# ./release-notes.sh
# ./release-notes.sh v1.0.1
# ./release-notes.sh v1.0.1 v1.0.0
SERVICE_BRANCH="master"
VERSION=${1:-$(git rev-parse --short HEAD)}
PREVIOUS_VERSION=${2:-$(git describe --abbrev=0 ${VERSION}^ --tags)}
if ! git describe ${VERSION} --tags &> /dev/null; then
echo "Invalid current release: ${VERSION}"
exit 1
fi
if ! git describe ${PREVIOUS_VERSION} --tags &> /dev/null; then
echo "Invalid previous release: ${PREVIOUS_VERSION}"
exit 1
fi
# Call Github API and use GITHUB_TOKEN from env if available
#
# Example (Get latest release from repository)
# gh_api /repos/Netflix/metaflow-service/releases/latest
gh_api() {
if [ -z "$GITHUB_TOKEN" ]
then
curl -s https://api.github.com$1
else
curl -s -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com$1
fi
}
# Extract value of key from JSON input
#
# Example (key value of key 'foo'):
# get_json_value '{"foo": "bar"}' foo
get_json_value() {
json_value=$(echo $1 | sed -n "s|.*\"$2\": \"\([^\"]*\)\".*|\1|p")
echo "${json_value}"
}
# Format list of PR merge commits
#
# Expected input:
# 6207fe4 Merge pull request #296 from ...
#
# Output:
# https://github.com/Netflix/metaflow-ui/pull/296 - Pull request description
function format_pr() {
if [ -z "$1" ]
then
echo "None"
else
while read -r merge
do
local prid=$(echo $merge | egrep -o '#[[:digit:]]+')
local commit=$(echo $merge | awk '{print $1}')
# Take message from commit message body BUT take only first line of commit body. Github squash by default
# adds all the commits to the message and that doesn't looks so good here. Also remove '* ' that is in squashed messages
# by default
local body=$(git log $commit -1 --pretty='format:%b' | head -n 1 | sed 's/* //')
# If merge commit body is empty, use subject instead.
if [ -z "$body" ]
then
local body=$(git log $commit -1 --pretty='format:%s')
fi
echo "https://github.com/Netflix/metaflow-ui/pull/${prid:1} - $body"
done <<< "$1"
fi
}
GH_RELEASE=$(gh_api /repos/Netflix/metaflow-service/releases/latest)
GH_BRANCH_REF=$(gh_api /repos/Netflix/metaflow-service/git/refs/heads/${SERVICE_BRANCH})
SERVICE_RELEASE=$(get_json_value "$GH_RELEASE" tag_name)
SERVICE_REF=$(get_json_value "$GH_BRANCH_REF" sha)
SERVICE_RELEASE=${SERVICE_RELEASE:-2.1.0}
SERVICE_REF=${SERVICE_REF:-ea55caf22b38d6c4a9faa255216be2df35aa988a}
RELEASE_DATE=$(date)
MERGES=$(git log --first-parent --pretty='format:%h %s' ${PREVIOUS_VERSION}..${VERSION})
PR=$(echo "${MERGES}" | grep "#[[:digit:]]")
PR_FEATURES=$(echo "${PR}" | grep -Ei 'feat[/:]')
PR_BUGS=$(echo "${PR}" | grep -Ei 'bug[/:]|hotfix[/:]|fix[/:]|bugfix[/:]')
PR_IMPROVEMENTS=$(echo "${PR}" | grep -Eiv 'feat[/:]|bug[/:]|hotfix[/:]|fix[/:]|bugfix[/:]')
RELEASE_NOTES="\
**What’s new in version** \`${VERSION}\`
- Release date: \`${RELEASE_DATE}\`
- Release package: [metaflow-ui-${VERSION}.zip](https://github.com/Netflix/metaflow-ui/releases/download/${VERSION}/metaflow-ui-${VERSION}.zip)
## Compatibility
| Service version | <=2.0.6 | ~${SERVICE_RELEASE} | [${SERVICE_BRANCH}][service-branch] | Netflix/metaflow-service@${SERVICE_REF} |
| --------------- | ------- | ------------------- | -------------------- | --------------------------------------- |
| Compatibility | x | ✓ | ✓ | ✓ |
- \`✓\` Fully supported version
- \`x\` Not compatible
- \`?\` Unknown compatibility
[service-branch]: https://github.com/Netflix/metaflow-service/tree/${SERVICE_BRANCH}
## Changelog
- **New features**
$(format_pr "${PR_FEATURES}" | sed 's/^/ - /')
- **Bug fixes**
$(format_pr "${PR_BUGS}" | sed 's/^/ - /')
- **Improvements**
$(format_pr "${PR_IMPROVEMENTS}" | sed 's/^/ - /')
Full commit history since the previous release can be found [here](https://github.com/Netflix/metaflow-ui/compare/${PREVIOUS_VERSION}...${VERSION})
## Additional resources
No additional resources for this release.
"
echo "$RELEASE_NOTES"