|
4 | 4 | from json import load, dump
|
5 | 5 | from github_release import gh_release_create
|
6 | 6 | from sys import exit
|
| 7 | +from os import path |
7 | 8 | from argparse import ArgumentParser
|
8 | 9 | from subprocess import run
|
| 10 | +'''WARNING: IF YOU DO NOT UPDATE YOUR README.md USING generate_plugininfo.py |
| 11 | +THIS PLUGIN WILL OVERWRITE IT!''' |
9 | 12 |
|
10 | 13 | parser = ArgumentParser()
|
11 | 14 | parser.add_argument("-d", "--description", help="Description for the new release", action="store", dest="description", default="")
|
12 |
| -parser.parse_args() |
| 15 | +parser.add_argument("-v", "--version", help="New version string", action="store", dest="new_version", default="") |
| 16 | +parser.add_argument("--force", help="Override the repository dirty check", action="store_true", dest="dirtyoverride", default=False) |
| 17 | +args = parser.parse_args() |
| 18 | +#TODO |
13 | 19 |
|
14 | 20 | repo = Repo(".")
|
15 | 21 | reponame = list(repo.remotes.origin.urls)[0].split(':')[1].split('.')[0]
|
| 22 | +if repo.is_dirty() and not args.dirtyoverride: |
| 23 | + print("Cowardly refusing to do anything as the plugin repository is currently dirty.") |
| 24 | + exit(-1) |
| 25 | + |
| 26 | +if not path.isfile("./generate_plugininfo.py"): |
| 27 | + print("Missing ./generate_plugininfo.py.") |
| 28 | + exit(-1) |
16 | 29 |
|
17 | 30 | with open('plugin.json') as plugin:
|
18 | 31 | data = load(plugin)
|
19 | 32 |
|
| 33 | +def update_version(data): |
| 34 | + print(f"Updating plugin with new version {data['version']}") |
| 35 | + with open('plugin.json', 'w') as plugin: |
| 36 | + dump(data, plugin) |
| 37 | + run(["./generate_plugininfo.py", "-r", "-f"], check=True) |
| 38 | + repo.index.add('plugin.json') |
| 39 | + repo.index.add('README.md') |
| 40 | + if args.description == "": |
| 41 | + repo.index.commit(f"Updating to {data['version']}") |
| 42 | + else: |
| 43 | + repo.index.commit(args.description) |
| 44 | + repo.git.push('origin') |
| 45 | + |
20 | 46 | for tag in repo.tags:
|
21 | 47 | if tag.name == data['version']:
|
22 |
| - print(f"Current plugin version {data['version']} is already a tag. Shall I increment it for you?") |
23 |
| - yn = input("[y/n]: ") |
24 |
| - if yn == "Y" or yn == "y": |
25 |
| - digits = data['version'].split('.') |
26 |
| - newlast = str(int(digits[-1])+1) |
27 |
| - digits[-1] = newlast |
28 |
| - new_version = '.'.join(digits) |
29 |
| - data['version'] = new_version |
30 |
| - print(f"Updating plugin with new version {new_version}") |
31 |
| - with open('plugin.json', 'w') as plugin: |
32 |
| - dump(data, plugin) |
33 |
| - run(["./generate_plugininfo.py", "-r", "-f"], check=True) |
34 |
| - repo.index.add('plugin.json') |
35 |
| - repo.index.add('README.md') |
36 |
| - repo.index.commit(f"Updating to {new_version}") |
37 |
| - repo.git.push('origin') |
| 48 | + if args.new_version == "": |
| 49 | + print(f"Current plugin version {data['version']} is already a tag. Shall I increment it for you?") |
| 50 | + yn = input("[y/n]: ") |
| 51 | + if yn == "Y" or yn == "y": |
| 52 | + digits = data['version'].split('.') |
| 53 | + newlast = str(int(digits[-1])+1) |
| 54 | + digits[-1] = newlast |
| 55 | + inc_version = '.'.join(digits) |
| 56 | + data['version'] = inc_version |
| 57 | + update_version(data) |
| 58 | + else: |
| 59 | + print("Stopping...") |
| 60 | + exit(-1) |
38 | 61 | else:
|
39 |
| - print("Stopping...") |
40 |
| - exit(-1) |
| 62 | + data['version'] = args.new_version |
| 63 | + update_version(data) |
41 | 64 |
|
42 | 65 | # Create new tag
|
43 | 66 | new_tag = repo.create_tag(data['version'])
|
|
0 commit comments