forked from neomatrix369/nlp_profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-to-github.sh
executable file
·72 lines (63 loc) · 2.38 KB
/
release-to-github.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
#!/bin/bash
#
# Copyright 2020 Mani Sarkar
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -e
set -u
set -o pipefail
PACKAGE_VERSION=$(grep "__version__ = " nlp_profiler/__init__.py | awk '{print $3}' | tr -d '"' || true)
TARGET_REPO="neomatrix369/nlp_profiler"
if [[ -z "${PACKAGE_VERSION:-}" ]]; then
echo "ERROR: Cannot find the version number in 'nlp_profiler/__init__.py', cannot proceed. Exiting..."
exit -1
fi
if [[ -z "${GITHUB_TOKEN:-}" ]]; then
echo "GITHUB_TOKEN cannot be found in the current environment, please populate to proceed."
echo "For e.g."
echo " $ GITHUB_TOKEN=<your token> ./release-to-github.sh"
echo ""
exit -1
fi
TAG_NAME="v${PACKAGE_VERSION}"
POST_DATA=$(printf '{
"tag_name": "%s",
"target_commitish": "master",
"name": "%s",
"body": "Release %s: changelog available at https://github.com/neomatrix369/nlp_profiler/blob/master/CHANGELOG.md",
"draft": false,
"prerelease": false
}' ${TAG_NAME} ${TAG_NAME} ${TAG_NAME})
echo "Creating release ${PACKAGE_VERSION}: $POST_DATA"
curl \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github.v3+json" \
-X POST -d "${POST_DATA}" "https://api.github.com/repos/${TARGET_REPO}/releases"
TMP_FOLDER=release-artifacts
mkdir -p "${TMP_FOLDER}"
CURL_OUTPUT="./${TMP_FOLDER}/github-release.listing"
echo "Getting Github ReleaseId"
curl \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
-X GET "https://api.github.com/repos/${TARGET_REPO}/releases/tags/${TAG_NAME}" |
tee ${CURL_OUTPUT}
RELEASE_VERSION=$(cat "${CURL_OUTPUT}" | grep id | head -n 1 | tr -d " " | tr "," ":" | cut -d ":" -f 2)
echo ""
echo "GitHub RELEASE_VERSION: ${RELEASE_VERSION}"
echo "PACKAGE_VERSION: ${PACKAGE_VERSION}. TAG_NAME: ${TAG_NAME}."
echo "~~~ Finished creating tag and release on GitHub ~~~"
echo ""
echo ""