forked from LorenFrankLab/rec_to_nwb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_release_github.sh
105 lines (77 loc) · 2.33 KB
/
make_release_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
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
#!/bin/bash
read_prerelease() {
echo "Pre-release? [y/n]: "
read is_prerelease
if [ $is_prerelease == "y" ]; then
is_prerelease="true"
elif [ $is_prerelease == "n" ]; then
is_prerelease="false"
else
read_prerelease
fi
}
read_draft() {
echo "Draft? [y/n]: "
read is_draft
if [ $is_draft == "y" ]; then
is_draft="true"
elif [ $is_draft == "n" ]; then
is_draft="false"
else
read_draft
fi
}
generate_post_data() {
cat <<EOF
{
"tag_name": "$versionLabel",
"target_commitish": "$masterBranch",
"name": "$title",
"body": "",
"draft": $is_draft,
"prerelease": $is_prerelease
}
EOF
}
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
projectName="$(git config --get remote.origin.url | cut -d/ -f5 | cut -d. -f1)"
repoFullName=$(git config --get remote.origin.url | sed 's/.*:\/\/github.com\///;s/.git$//')
# Personal access token, set by command: git config --global github.token XXXXXXXXXXXXXXXXX
token=$(git config --global github.token)
masterBranch=master
git checkout $masterBranch
echo "To start releasing for $projectName, click enter"
read enterKey
if [ $branch == "master" ]; then
# It takes stdout from print in setup. It will throw an error, but that is ok. python setup.py --version use normalization that change 0.0.001 to 0.0.1.
versionNumber=$(python setup.py)
versionLabel=v$versionNumber
releaseBranch=master_release
title=$versionLabel
read_draft
read_prerelease
echo "Delete old branch $releaseBranch ....."
git branch -d master_release
git push origin --delete master_release
git checkout $masterBranch
echo "Started releasing $versionLabel for $projectName ....."
git pull
response=$(curl -o /dev/null -s -w "%{http_code}\n" --data "$(generate_post_data)" "https://api.github.com/repos/$repoFullName/releases?access_token=$token")
if [ $response == 201 ]; then
echo "$versionLabel is successfully released for $projectName !"
git checkout -b $releaseBranch $masterBranch
git checkout $masterBranch
git push -u origin $releaseBranch
git checkout $masterBranch
git pull
echo "Bye!"
else
echo "Something went wrong, code $response"
echo "Check if the release does not exist already"
fi
else
echo "Please make sure you are on master branch and come back!"
echo "Bye!"
fi
echo "Click 'Enter' to exit"
read _