diff --git a/.drone.yml b/.drone.yml index 9db863f..56b6672 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,7 +8,7 @@ steps: entrypoint: [ "/bin/bash" ] commands: - apt update - - apt install -y --no-install-recommends pipx python3-venv python3.9 python3-pip + - apt install -y --no-install-recommends pipx python3-venv python3.9 python3-pip git - cd updater - pipx install pipenv - pipx ensurepath @@ -22,8 +22,6 @@ steps: settings: branch: main remote: git@git.nelim.org:matt1432/android_vendor_mulchwebview.git - commit: true - commit_message: "Update APK" ssh_key: from_secret: ssh diff --git a/updater/git.py b/updater/git.py new file mode 100644 index 0000000..6968174 --- /dev/null +++ b/updater/git.py @@ -0,0 +1,16 @@ +import subprocess + + +user_name = 'Updater Robot' +user_email = 'robot@nowhere.invalid' + + +def add_commit(directory: str, message: str): + diff = subprocess.run(['git', 'diff', '--cached', '--exit-code'], capture_output=True, text=True) + if diff.returncode != 0: + status = subprocess.run(['git', 'status'], capture_output=True, text=True) + raise Exception('Unknown staged changes found: {}'.format(status.stdout)) + + subprocess.run(['git', 'add', '--all', directory], check=True) + subprocess.run(['git', '-c', 'user.name={}'.format(user_name), '-c', 'user.email={}'.format(user_email), + 'commit', '--message', message]) diff --git a/updater/main.py b/updater/main.py index 1fa22c9..d958db1 100644 --- a/updater/main.py +++ b/updater/main.py @@ -2,6 +2,7 @@ import urllib.request from os import path import certificates +import git from sources import ApkRelease, fdroid_recommended_release @@ -27,6 +28,11 @@ def update_if_needed(module: str, release: ApkRelease): version_code_file.truncate() version_code_file.close() + + print('commit...') + git.add_commit(module_dir, 'Update {} to {}'.format(module, release.version_name)) + + elif version_code > release.version_code: print('{} ahead of suggested version ({} > {})'.format(module, version_code, release.version_code)) elif version_code == release.version_code: