1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

Automatic patch/PR for helpers 2.1

This commit is contained in:
Alexandre Aubin 2024-08-30 19:31:00 +02:00
parent df5f399c58
commit de66a2cfd8
4 changed files with 40 additions and 29 deletions

View file

@ -8,7 +8,6 @@ import time
from pathlib import Path from pathlib import Path
import requests import requests
import toml
# add apps/tools to sys.path # add apps/tools to sys.path
sys.path.insert(0, str(Path(__file__).parent.parent)) sys.path.insert(0, str(Path(__file__).parent.parent))
@ -18,16 +17,27 @@ from appslib.utils import ( # noqa: E402 pylint: disable=import-error,wrong-imp
get_catalog, get_catalog,
) )
APPS_CACHE_DIR = REPO_APPS_ROOT / ".apps_cache"
def app_cache_folder(app: str) -> Path:
return APPS_CACHE_DIR / app
my_env = os.environ.copy() my_env = os.environ.copy()
my_env["GIT_TERMINAL_PROMPT"] = "0" my_env["GIT_TERMINAL_PROMPT"] = "0"
os.makedirs(".apps_cache", exist_ok=True)
login = ( try:
login = (
(REPO_APPS_ROOT / "tools/.github_login").open("r", encoding="utf-8").read().strip() (REPO_APPS_ROOT / "tools/.github_login").open("r", encoding="utf-8").read().strip()
) )
token = ( token = (
(REPO_APPS_ROOT / "tools/.github_token").open("r", encoding="utf-8").read().strip() (REPO_APPS_ROOT / "tools/.github_token").open("r", encoding="utf-8").read().strip()
) )
except:
login = None
token = None
github_api = "https://api.github.com" github_api = "https://api.github.com"
@ -38,10 +48,6 @@ def apps(min_level=4):
yield infos yield infos
def app_cache_folder(app):
return os.path.join(".apps_cache", app)
def git(cmd, in_folder=None): def git(cmd, in_folder=None):
if not isinstance(cmd, list): if not isinstance(cmd, list):
cmd = cmd.split() cmd = cmd.split()
@ -72,30 +78,19 @@ def progressbar(it, prefix="", size=60, file=sys.stdout):
file.flush() file.flush()
def build_cache():
for app in progressbar(apps(), "Git cloning: ", 40):
folder = os.path.join(".apps_cache", app["id"])
reponame = app["url"].rsplit("/", 1)[-1]
git(f"clone --quiet --depth 1 --single-branch {app['url']} {folder}")
git(
f"remote add fork https://{login}:{token}@github.com/{login}/{reponame}",
in_folder=folder,
)
def apply(patch): def apply(patch):
patch_path = os.path.abspath(os.path.join("patches", patch, "patch.sh")) patch_path = os.path.abspath(os.path.join("patches", patch, "patch.sh"))
for app in progressbar(apps(), "Apply to: ", 40): for app in progressbar(apps(), "Apply to: ", 40):
folder = os.path.join(".apps_cache", app["id"]) folder = app_cache_folder(app["id"])
current_branch = git(f"symbolic-ref --short HEAD", in_folder=folder) current_branch = git("symbolic-ref --short HEAD", in_folder=folder)
git(f"reset --hard origin/{current_branch}", in_folder=folder) git(f"reset --hard origin/{current_branch}", in_folder=folder)
os.system(f"cd {folder} && bash {patch_path}") os.system(f"cd {folder} && bash {patch_path}")
def diff(): def diff():
for app in apps(): for app in apps():
folder = os.path.join(".apps_cache", app["id"]) folder = app_cache_folder(app["id"])
if bool( if bool(
subprocess.check_output(f"cd {folder} && git diff", shell=True) subprocess.check_output(f"cd {folder} && git diff", shell=True)
.strip() .strip()
@ -116,7 +111,7 @@ def push(patch):
) )
def diff_not_empty(app): def diff_not_empty(app):
folder = os.path.join(".apps_cache", app["id"]) folder = app_cache_folder(app["id"])
return bool( return bool(
subprocess.check_output(f"cd {folder} && git diff", shell=True) subprocess.check_output(f"cd {folder} && git diff", shell=True)
.strip() .strip()
@ -140,7 +135,7 @@ def push(patch):
for app in progressbar(apps_to_push, "Pushing: ", 40): for app in progressbar(apps_to_push, "Pushing: ", 40):
app["repo"] = app["url"][len("https://github.com/") :].strip("/") app["repo"] = app["url"][len("https://github.com/") :].strip("/")
app_repo_name = app["url"].rsplit("/", 1)[-1] app_repo_name = app["url"].rsplit("/", 1)[-1]
folder = os.path.join(".apps_cache", app["id"]) folder = app_cache_folder(app["id"])
current_branch = git(f"symbolic-ref --short HEAD", in_folder=folder) current_branch = git(f"symbolic-ref --short HEAD", in_folder=folder)
git(f"reset origin/{current_branch}", in_folder=folder) git(f"reset origin/{current_branch}", in_folder=folder)
git( git(
@ -200,7 +195,8 @@ def main():
Example usage: Example usage:
# Init local git clone for all apps # Init local git clone for all apps
./autopatch.py --build-cache # (script in parent directory)
./app_caches.py --ssh
# Apply patch in all local clones # Apply patch in all local clones
./autopatch.py --apply explicit-php-version-in-deps ./autopatch.py --apply explicit-php-version-in-deps

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
python3 ../../tools/helpers2.1/convert_to_helpers_2.1.py ./
git add .

View file

@ -0,0 +1,9 @@
This is an ***automated*** patch for the switch to helpers 2.1
If you are not familar with helpers 2.1, please check the discussion at https://forum.yunohost.org/t/new-experimental-2-1-helpers/30114
Please bear in mind that this is just an **automated** patch and it is very likely to not work out of the box.
In particular it is known to possibly create syntax issues or permission issues which may need to be resolved manually. You are absolutely encouraged to come discuss about this on the app packaging room if you are unsure how to fix a specific issue.

View file

@ -0,0 +1 @@
Automatic patch attempt for helpers 2.1