-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannounce-a-release.bash
More file actions
147 lines (124 loc) · 4.4 KB
/
Copy pathannounce-a-release.bash
File metadata and controls
147 lines (124 loc) · 4.4 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# Announces a release after artifacts have been built:
#
# - Publishes release notes to GitHub
# - Announces in the #announce stream of Zulip
# - Adds a note about the release to LWIP
#
# Tools required in the environment that runs this:
#
# - bash
# - changelog-tool
# - curl
# - git
# - jq
set -o errexit
# Verify ENV is set up correctly
# We validate all that need to be set in case, in an absolute emergency,
# we need to run this by hand. Otherwise the GitHub actions environment should
# provide all of these if properly configured
if [[ -z "${GITHUB_REF}" ]]; then
echo -e "\e[31mThe release tag needs to be set in GITHUB_REF."
echo -e "\e[31mThe tag should be in the following GitHub specific form:"
echo -e "\e[31m /refs/tags/announce-X.Y.Z"
echo -e "\e[31mwhere X.Y.Z is the version we are announcing"
echo -e "\e[31mExiting.\e[0m"
exit 1
fi
if [[ -z "${GITHUB_REPOSITORY}" ]]; then
echo -e "\e[31mName of this repository needs to be set in GITHUB_REPOSITORY."
echo -e "\e[31mShould be in the form OWNER/REPO, for example:"
echo -e "\e[31m ponylang/ponyup"
echo -e "\e[31mExiting.\e[0m"
exit 1
fi
if [[ -z "${RELEASE_TOKEN}" ]]; then
echo -e "\e[31mA personal access token needs to be set in RELEASE_TOKEN."
echo -e "\e[31mIt should not be secrets.GITHUB_TOKEN. It has to be a"
echo -e "\e[31mpersonal access token otherwise next steps in the release"
echo -e "\e[31mprocess WILL NOT trigger."
echo -e "\e[31mPersonal access tokens are in the form:"
echo -e "\e[31m TOKEN"
echo -e "\e[31mfor example:"
echo -e "\e[31m 1234567890"
echo -e "\e[31mExiting.\e[0m"
exit 1
fi
if [[ -z "${SLACK_TOKEN}" ]]; then
echo -e "\e[31mA Slack access token needs to be set in SLACK_TOKEN."
echo -e "Exiting.\e[0m"
exit 1
fi
# no unset variables allowed from here on out
# allow above so we can display nice error messages for expected unset variables
set -o nounset
PUSH_TO="https://${RELEASE_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
echo -e $GITHUB_REF
# Extract version from tag reference
# Tag ref version: "refs/tags/release-1.0.0"
# Version: "1.0.0"
VERSION="${GITHUB_REF/refs\/tags\/release-/}"
git pull
# Prepare release notes
echo -e "\e[34mPreparing to update GitHub release notes...\e[0m"
release_notes=""
if test -f ".release-notes/next-release.md"; then
echo -e "\e[34mnext-release.md found. Adding entries to release notes.\e[0m"
fc=$(<".release-notes/next-release.md")
echo -e $fc
release_notes="${fc}"
else
echo -e "\e[34mNo next-release.md found. Only using changelog entries\e[0m"
fi
echo -e $VERSION
changelog=$(changelog-tool get "${VERSION}")
echo -e $changelog
body="${release_notes}${changelog}"
jsontemplate="
{
\"tag_name\":\$version,
\"name\":\$version,
\"body\":\$body
}
"
json=$(jq -n \
--arg version "$VERSION" \
--arg body "$body" \
"${jsontemplate}")
# Upload release notes
echo -e "\e[34mUploading release notes...\e[0m"
result=$(curl -s -X POST "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "${RELEASE_TOKEN}" \
--data "${json}")
rslt_scan=$(echo "${result}" | jq -r '.id')
if [ "$rslt_scan" != null ]; then
echo -e "\e[34mRelease notes uploaded\e[0m"
else
echo -e "\e[31mUnable to upload release notes, here's the curl output..."
echo -e "\e[31m${result}\e[0m"
exit 1
fi
# Send announcement to Slack
message="
Version ${VERSION} of ${GITHUB_REPOSITORY} has been released.
See the release notes https://github.com/${GITHUB_REPOSITORY}/releases/tag/${VERSION} for more details.
"
curl -F token="${SLACK_TOKEN}" -F channel="alerts-releases" -F text="${message}" https://slack.com/api/chat.postMessage
# delete announce-VERSION tag
#echo -e "\e[34mDeleting no longer needed remote tag announce-${VERSION}\e[0m"
#git push --delete "${PUSH_TO}" "announce-${VERSION}"
# This doesn't account for the default branch changing commit. It assumes we
# are HEAD or can otherwise push without issue.
git checkout "${INPUT_DEFAULT_BRANCH}"
git pull
# rotate next-release.md content
if test -f ".release-notes/next-release.md"; then
echo -e "\e[34mRotating release notes\e[0m"
mv ".release-notes/next-release.md" ".release-notes/${VERSION}.md"
touch ".release-notes/next-release.md"
git add .release-notes/*
git commit -m "Rotate release notes as part of ${VERSION} release"
echo -e "\e[34mPushing release notes changes\e[0m"
git push "${PUSH_TO}" "${INPUT_DEFAULT_BRANCH}"
fi