-
Notifications
You must be signed in to change notification settings - Fork 275
/
release.py
executable file
·74 lines (48 loc) · 2.19 KB
/
release.py
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
#! /usr/bin/env python
import changelog
import re
import subprocess
import sys
def checkExistingTag(version):
if (subprocess.call(('git show-ref --verify --quiet refs/heads/%s' % version).split()) == 0 or
subprocess.call(('git show-ref --verify --quiet refs/tags/%s' % version).split()) == 0):
print "Error: The tag '%s' already exists" % version
raise Exception()
def updateHomepage(version):
file_str = None
with open('build/includes/home/home.html') as f:
file_str = f.read()
file_str = re.sub(r'href="[^"]*"',
'href="https://github.com/lumapps/lumX/archive/%s.zip"' % version,
file_str)
file_str = re.sub(r'<span class="home-banner__version">[^"]*<\/span>',
'<span class="home-banner__version">%s</span>' % version,
file_str)
with open('demo/includes/home/home.html', "w") as f:
f.write(file_str)
def addAndCommitReleaseFiles(version):
subprocess.call(['git', 'add', '-f', 'demo/includes/home/home.html', 'CHANGELOG.md', 'dist'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
subprocess.call(['git', 'commit', '-m', 'chore release: new release %s' % version], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
def commit(version):
changelog.main(version)
print "Adding and committing files..."
addAndCommitReleaseFiles(version)
print "Publishing new commit to master..."
subprocess.call(('git push origin master').split(), stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
print "Publishing to NPM registry..."
subprocess.call(('npm version %s' % version).split())
subprocess.call(('npm publish').split())
print "Push git repository..."
subprocess.call(('git push origin %s' % version).split(), stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
print "Release %s created!" % version
if __name__ == "__main__":
try:
if len(sys.argv) == 1:
print "Error: The version name is required"
raise Exception()
version = sys.argv[1]
checkExistingTag(version)
updateHomepage(version)
commit(version)
except Exception as e:
exit(-1)