-
Notifications
You must be signed in to change notification settings - Fork 159
/
startRelease.sh
executable file
·141 lines (108 loc) · 4.17 KB
/
startRelease.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
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
#Setup the release
echo $GIT_BRANCH
BRANCHNAME=$(echo ${GIT_BRANCH} | cut -d "/" -f 2)
VERSION=$(echo ${GIT_BRANCH} | cut -d "-" -f 2)
#We start on a commit so checkout the branch and change the config to only push this one
git checkout -b $BRANCHNAME
git config --global push.default current
echo $BRANCHNAME
echo $VERSION
echo "Checking requested release version string"
#First remove all local tags and get the ones from the remote. This is in case of imperfect clean up - shouldn't really be necessary after testing
git tag -d $(git tag)
git fetch --tags
#Check if the requested version is "x.y.z"
if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: Version string did not match \"^[0-9]+\.[0-9]+\.[0-9]+$\""
exit 1
fi
#Check if the requested version has already been released
tag=$(git ls-remote --tags origin ${VERSION})
if [[ $? != 0 ]]; then
echo "ERROR: Command \"git ls-remote --tags origin ${VERSION}\" failed"
elif [[ $tag ]]; then
echo "ERROR: Version string already found"
exit 1
fi
echo "Sorting release notes"
#Setting version and date on release notes
sed --in-place "s/@VERSION@/${VERSION} (`date '+%Y\/%m\/%d'`)/g" ganga/GangaRelease/ReleaseNotes
#Copying release notes
git mv ganga/GangaRelease/ReleaseNotes ganga/GangaRelease/ReleaseNotes-${VERSION}
#Creating new release notes from template
cat << EOF > ganga/GangaRelease/ReleaseNotes
**************************************************************************************************************
@VERSION@
--------------------------------------------------------------------------------------------------------------
ganga/ganga/Ganga
--------------------------------------------------------------------------------------------------------------
* ...
**************************************************************************************************************
EOF
git add ganga/GangaRelease/ReleaseNotes
git add ganga/GangaRelease/ReleaseNotes-${VERSION}
#Committing changes
git commit -m "Updating release notes"
echo "Changing version numbers"
#Setting version number and turn off DEV flag
sed --in-place "s/^_gangaVersion = .*/_gangaVersion = '${VERSION}'/g" ganga/GangaCore/__init__.py
sed --in-place "s/^_gangaVersion = .*/_gangaVersion = '${VERSION}'/g" ./setup.py
sed --in-place "s/^_development = .*/_development = False/g" ganga/GangaCore/__init__.py
git add ganga/GangaCore/__init__.py ./setup.py
#Committing changes
git commit -m "Setting release number"
echo "Creating tag $VERSION"
#Now create a tag and fire it at github
git tag -a $VERSION -m "Release ${VERSION}"
echo "Pushing to origin"
git push --tags
#Now send the release notes to github - need some python magic
echo "Creating new release on github"
function sendReleaseNotes {
version=$VERSION apiuser=$GITHUBAPIUSER apipassword=$GITHUBAPIPASSWORD python - <<END
import requests
import json
import os
version = os.environ.get('version')
changelog = open('ganga/GangaRelease/ReleaseNotes-'+version, 'r').readlines()
changelog = changelog[4:-2] # Strip headings...?
changelog = ''.join(changelog)
release = {
'tag_name': version,
'target_commitish': 'master',
'name': version,
'body': changelog,
'draft': False,
'prerelease': False
}
r = requests.post('https://api.github.com/repos/ganga-devs/ganga/releases', data=json.dumps(release), auth=(os.environ.get('apiuser'), os.environ.get('apipassword')))
r.raise_for_status()
END
}
sendReleaseNotes
#Below is the necessaries for the pypi upload.
pip install --upgrade pip
pip install --upgrade twine
cat << EOF > ~/.pypirc
[distutils]
index-servers =
pypi
[pypi]
#The repository line is apparently outdated now
#repository = https://pypi.python.org/pypi/
username: $PYPI_USER
password: $PYPI_PASSWORD
EOF
echo "uploading to pypi"
python setup.py register
python setup.py sdist
twine upload --skip-existing dist/ganga-*.tar.gz
rm dist/ganga-*.tar.gz
rm ~/.pypirc
#Now the release is sorted we can set the development flag again and push the changes back to the release branch!
sed --in-place "s/^_development = .*/_development = True/g" ganga/GangaCore/__init__.py
git add ganga/GangaCore/__init__.py
git commit -m "setting development flag"
git push origin ${BRANCHNAME}
#All done!