Add README.md and {gitea_actions, config}.py

This commit is contained in:
Benjamin Loison 2023-09-11 15:16:52 +02:00
commit ddf19cd334
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
3 changed files with 89 additions and 0 deletions

19
README.md Normal file
View File

@ -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

3
config.py Normal file
View File

@ -0,0 +1,3 @@
instance = 'https://gitea.lemnoslife.com'
repository = 'LemnosLife/LemnosLife_Client_chat_majeste'
i_like_gitea = 'YOUR_i_like_gitea_COOKIE'

67
gitea_actions.py Executable file
View File

@ -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}')