generated from RyotaUshio/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
release
executable file
·72 lines (55 loc) · 2.26 KB
/
release
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
#!/usr/bin/env python3
import json
import argparse
import subprocess
import sys
def run(cmd):
comp = subprocess.run(cmd)
if comp.returncode != 0:
exit(1)
if __name__ == '__main__':
run(['git', 'switch', 'main'])
parser = argparse.ArgumentParser()
parser.add_argument('version')
args = parser.parse_args()
args.version = args.version.strip()
with open('./manifest.json') as f:
manifest = json.load(f)
with open('./manifest-beta.json') as f:
manifest_beta = json.load(f)
with open('./package.json') as f:
package = json.load(f)
assert manifest['version'] == package['version']
old_version = manifest['version']
diff = subprocess.run(['git', 'diff', f'{old_version}..', 'src', 'styles.css'], capture_output=True, text=True).stdout
diff = diff or subprocess.run(['git', 'diff', '--cached', 'src', 'styles.css'], capture_output=True, text=True).stdout
if not diff:
print('No changes to release. Perhaps you forgot to merge the dev branch?', file=sys.stderr)
exit(1)
if 'beta' in args.version:
ans = input(f'[Beta-release] Update beta version from {manifest_beta["version"]} to {args.version}? (y/[n]): ').strip()
if ans != 'y':
exit(1)
manifest_beta['version'] = args.version
with open('./manifest-beta.json', 'w') as f:
json.dump(manifest_beta, f, indent=4)
else:
ans = input(f'Update version from {manifest["version"]} to {args.version}? (y/[n]): ').strip()
if ans != 'y':
exit(1)
manifest['version'] = args.version
manifest_beta['version'] = args.version
package['version'] = args.version
with open('./manifest.json', 'w') as f:
json.dump(manifest, f, indent=4)
with open('./manifest-beta.json', 'w') as f:
json.dump(manifest, f, indent=4)
with open('./package.json', 'w') as f:
json.dump(package, f, indent=4)
run(['npm', 'i'])
run(['git', 'add', '.'])
run(['git', 'commit', '-m', f'release: {args.version}'])
run(['git', 'pull', '--rebase'])
run(['git', 'push'])
run(['git', 'tag', '-a', args.version, '-m', args.version])
run(['git', 'push', 'origin', args.version])