commit ddf19cd33414d778598bb0dbe00ab46e3ca1aae1 Author: Benjamin Loison Date: Mon Sep 11 15:16:52 2023 +0200 Add `README.md` and `{gitea_actions, config}.py` diff --git a/README.md b/README.md new file mode 100644 index 0000000..18bfb76 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Gitea Actions + +## Installation: + +Install Gitea Actions Webscraper dependency by running: + +``` +pip install gitea_actions_webscraper +``` + +## Configuration: + +Modify `config.py` with the `i_like_gitea` cookie that you can obtain with the `Network` tab (`Ctrl` + `Shift` + `E` with Firefox) when refreshting [the actions webpage](https://gitea.lemnoslife.com/LemnosLife/LemnosLife_Client_chat_majeste/actions). + +## Usage: + +- `./gitea_actions.py check_compilation -m 'Check compilation' -a` which commits, pushes and waits for action execution and returns if compilation successful or the error otherwise +- `./gitea_actions.py compile -m 'Compile' -a` which additionally downloads the associated binary +- `./gitea_actions.py compile_and_run -m 'Compile and run' -a` which additionally runs the associated binary diff --git a/config.py b/config.py new file mode 100644 index 0000000..4c0163c --- /dev/null +++ b/config.py @@ -0,0 +1,3 @@ +instance = 'https://gitea.lemnoslife.com' +repository = 'LemnosLife/LemnosLife_Client_chat_majeste' +i_like_gitea = 'YOUR_i_like_gitea_COOKIE' diff --git a/gitea_actions.py b/gitea_actions.py new file mode 100755 index 0000000..220f0c2 --- /dev/null +++ b/gitea_actions.py @@ -0,0 +1,67 @@ +#!/usr/bin/python3 + +from gitea_actions_webscraper import GiteaActionsWebscraper +import config +import os +import sys +import time +import requests +import zipfile +import io +import shlex + +arguments = ' '.join([shlex.quote(argv) for argv in sys.argv[2:]]) + +if os.system('git commit ' + arguments) != 0: + exit(1) + +if os.system('git push') != 0: + exit(1) + +with open('.git/refs/heads/master') as f: + lastCommit = f.read()[:-1] + +# Isn't there already live updates on UI? + +gitea_actions_webscraper = GiteaActionsWebscraper(config.instance, config.repository, config.i_like_gitea) +while True: + while True: + actions = gitea_actions_webscraper.getFirstActionsPage() + for action in actions: + if action.commitHash == lastCommit: + break + else: + print('Waiting to notice action creation') + time.sleep(1) + continue + break + if not action.state in ['Running', 'Waiting']: + print('Waiting action execution') + time.sleep(1) + break + +print('Action state:', action.state) +if action.state == 'Failure': + messages = '\n'.join([stepLog['message'] for stepLog in actions[0].getStepLogs(9)]) + print(messages) + exit(1) + +if not sys.argv[1] in ['compile', 'compile_and_run']: + exit(0) + +artifactFileName = 'LemnosLife_client_debug' +print(f'Downloaing artifact {artifactFileName}') +artifactUrl = action.getArtifactUrl(artifactFileName) +cookies = { + 'i_like_gitea': config.i_like_gitea +} + +artifactBytes = requests.get(artifactUrl, cookies = cookies).content + +with zipfile.ZipFile(io.BytesIO(artifactBytes)) as z: + z.extractall() + +if sys.argv[1] != 'compile_and_run': + exit(0) + +os.system(f'./{artifactFileName}')