diff --git a/0.9-alpha.1/metadata.json b/0.9-alpha.1/metadata.json deleted file mode 100644 index 5783de1..0000000 --- a/0.9-alpha.1/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718114820, "file": "realweather-0.9a1.jar"} diff --git a/0.9-alpha.1/realweather-0.9a1.jar b/0.9-alpha.1/realweather-0.9a1.jar deleted file mode 100644 index cb22965..0000000 Binary files a/0.9-alpha.1/realweather-0.9a1.jar and /dev/null differ diff --git a/latest b/latest deleted file mode 120000 index 2494a8e..0000000 --- a/latest +++ /dev/null @@ -1 +0,0 @@ -0.9-alpha.1 \ No newline at end of file diff --git a/latest.json b/latest.json new file mode 100644 index 0000000..eca7270 --- /dev/null +++ b/latest.json @@ -0,0 +1 @@ +{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718449299, "file": "realweather-0.9-SNAPSHOT.jar"} \ No newline at end of file diff --git a/release.py b/release.py new file mode 100755 index 0000000..5143a72 --- /dev/null +++ b/release.py @@ -0,0 +1,118 @@ +#!/usr/bin/python3 + +import json, os, time +from typing import Tuple + +def confirm(prompt: str) -> bool: + confirmed = input(prompt + ' (Y/N) ') + return confirmed.lower() == 'y' + +def load_latest_data() -> dict: + if os.path.isfile('latest.json'): + return json.loads(open('latest.json').read()) + return {'id': 0} + +def match_name(filename: str, extension: str=None, exact_name: str=None): + if exact_name is not None: + return filename == exact_name + elif extension is not None: + return filename.lower().endswith(extension.lower()) + return True + +def scan_for_file(ask: bool=False, extension: str=None, exact_name: str=None) -> Tuple[str]: + for file in os.scandir(): + if file.is_dir(): continue + if not match_name(file.name, extension, exact_name): continue + + if ask: + if not confirm(f"Found {file.name} in the current directory, do you want to proceed with it?"): + return (None, None) + + return (file.path, file.name) + return (None, None) + +def wait_for_file(waiting_dir: str, extension: str=None, exact_name: str=None) -> Tuple[str]: + print(f"Please put a {extension} file in {waiting_dir}") + while True: + files = [i for i in os.scandir(waiting_dir)] + + if len(files) == 0: + time.sleep(0.5) + continue + + file = files[0] + filepath = file.path + filename = file.name + + if match_name(filename, extension, exact_name): + break + else: + os.remove(filepath) + print(f"Not a {extension} file: {filename}") + + return (filepath, filename) + +def write_metadata(metadata: dict): + dir = metadata['label'] + metadata = json.dumps(metadata) + for filepath in [os.path.join('releases', dir, 'meta.json'), 'latest.json']: + file = open(filepath, 'w') + file.write(metadata) + file.close() + +def main(): + latest_data = load_latest_data() + if latest_data['id'] > 0: + print(f"Current release: {latest_data['label']}") + print(f"Released {time.strftime('%d.%m.%Y %H:%M', time.localtime(latest_data['timestamp']))}") + print('') + + version = input('New version? ') + + if os.path.isdir(version): + raise FileExistsError() + + filepath, filename = scan_for_file(ask=True, extension='jar') + + if filepath is None: + os.makedirs('pending', exist_ok=True) + try: + filepath, filename = wait_for_file('pending', 'jar') + except KeyboardInterrupt: + os.rmdir('pending') + return + + changelog = confirm('Do you want to include a changelog?') + if changelog: + cfilepath, cfilename = scan_for_file(ask=True, exact_name='changelog.txt') + if cfilepath is None: + try: + os.makedirs('pending', exist_ok=True) + cfilepath, cfilename = wait_for_file('pending', 'txt') + except KeyboardInterrupt: + os.rmdir('pending') + return + + version_dir = os.path.join('releases', version) + + os.mkdir(version_dir) + os.rename(filepath, os.path.join(version_dir, filename)) + if changelog: os.rename(cfilepath, os.path.join(version_dir, 'changelog.txt')) + + try: + os.rmdir('pending') + except FileNotFoundError: + pass + + metadata = { + 'label': version, + 'id': latest_data['id'] + 1, + 'timestamp': int(time.time()), + 'file': filename + } + write_metadata(metadata) + + print("Done, don't forget to commit and push") + +if __name__ == "__main__": + main() diff --git a/releases/0.9-alpha.1/meta.json b/releases/0.9-alpha.1/meta.json new file mode 100644 index 0000000..eca7270 --- /dev/null +++ b/releases/0.9-alpha.1/meta.json @@ -0,0 +1 @@ +{"label": "0.9-alpha.1", "id": 1, "timestamp": 1718449299, "file": "realweather-0.9-SNAPSHOT.jar"} \ No newline at end of file diff --git a/releases/0.9-alpha.1/realweather-0.9-SNAPSHOT.jar b/releases/0.9-alpha.1/realweather-0.9-SNAPSHOT.jar new file mode 100644 index 0000000..05b2594 Binary files /dev/null and b/releases/0.9-alpha.1/realweather-0.9-SNAPSHOT.jar differ diff --git a/reset.py b/reset.py new file mode 100755 index 0000000..c126f5b --- /dev/null +++ b/reset.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 + +from shutil import rmtree +from os import remove, mkdir + +confirmation = input('If you really want to delete all releases, type CONFIRM: ') +if confirmation != 'CONFIRM': + print('Cancelled') + exit() + +remove('latest.json') +rmtree('releases') +mkdir('releases') + +print('Reset complete')