-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbump.py
64 lines (54 loc) · 1.96 KB
/
bump.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
"""Simple script to handle the versioning for me to ensure I don't miss a version"""
import json
import subprocess
# Get the version to bump
while True:
bump_ver = input('[m]ajor / m[i]nor / [p]atch: ')
if bump_ver in ['m', 'i', 'p']:
break
# Open the manifest and package.json files and increment the version number, and also add a new header to the changelog
with open('package.json') as f:
data = json.load(f)
old_ver = data['version']
old_ver_segments = [int(v) for v in old_ver.split('.')]
# Incrememnt the correct number for the version
if bump_ver == 'p':
old_ver_segments[2] += 1
elif bump_ver == 'i':
old_ver_segments[1] += 1
old_ver_segments[2] = 0
elif bump_ver == 'm':
old_ver_segments[0] += 1
old_ver_segments[1] = 0
old_ver_segments[2] = 0
new_ver = '.'.join(str(v) for v in old_ver_segments)
print(f'Bumping to v{new_ver}')
data['version'] = new_ver
with open('package.json', 'w') as f:
json.dump(data, f, sort_keys=True, indent=2)
# Now the manifest files
with open('dist/manifest.json') as f:
data = json.load(f)
data['version'] = new_ver
with open('dist/manifest.json', 'w') as f:
json.dump(data, f, sort_keys=True, indent=2)
# Open the dist specific manifests
with open('dist/manifests/firefox.json') as f:
data = json.load(f)
data['version'] = new_ver
with open('dist/manifest.json', 'w') as f:
json.dump(data, f, sort_keys=True, indent=2)
with open('dist/manifests/chrome.json') as f:
data = json.load(f)
data['version'] = new_ver
with open('dist/manifest.json', 'w') as f:
json.dump(data, f, sort_keys=True, indent=2)
# Also append the new version to the start of the CHANGELOG
with open('CHANGELOG.md') as f:
lines = f.readlines()
lines = [f'# {new_ver}', '\n', '\n'] + lines
with open('CHANGELOG.md', 'w') as f:
f.write(''.join(lines))
# Also run sed on the popup.html file to change the version in the popup
cmd = ['sed', '-i', f's/v{old_ver}/v{new_ver}/', 'dist/popup.html']
subprocess.run(cmd)