mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
✨ Use updates json from other branch
This commit is contained in:
committed by
Nikhil Badyal
parent
cf8dd0fb59
commit
24f170552f
@@ -43,6 +43,7 @@ jobs:
|
|||||||
- name: Update Env for custom build
|
- name: Update Env for custom build
|
||||||
run: |
|
run: |
|
||||||
echo "${{ secrets.ENVS }}" >> .env
|
echo "${{ secrets.ENVS }}" >> .env
|
||||||
|
echo "GITHUB_REPOSITORY=${{ github.repository }}" >> .env
|
||||||
|
|
||||||
- name: Install Dot-Env
|
- name: Install Dot-Env
|
||||||
if: ${{ inputs.PREFERRED_PATCH_APPS }}
|
if: ${{ inputs.PREFERRED_PATCH_APPS }}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from src.downloader.download import Downloader
|
|||||||
from src.exceptions import AppNotFoundError, BuilderError, PatchesJsonLoadError, PatchingFailedError
|
from src.exceptions import AppNotFoundError, BuilderError, PatchesJsonLoadError, PatchingFailedError
|
||||||
from src.parser import Parser
|
from src.parser import Parser
|
||||||
from src.patches import Patches
|
from src.patches import Patches
|
||||||
from src.utils import check_java, delete_old_changelog, save_patch_info, write_changelog_to_file
|
from src.utils import check_java, delete_old_changelog, load_older_updates, save_patch_info, write_changelog_to_file
|
||||||
|
|
||||||
|
|
||||||
def get_app(config: RevancedConfig, app_name: str) -> APP:
|
def get_app(config: RevancedConfig, app_name: str) -> APP:
|
||||||
@@ -26,10 +26,12 @@ def main() -> None:
|
|||||||
env = Env()
|
env = Env()
|
||||||
env.read_env()
|
env.read_env()
|
||||||
config = RevancedConfig(env)
|
config = RevancedConfig(env)
|
||||||
|
updates_info = {}
|
||||||
Downloader.extra_downloads(config)
|
Downloader.extra_downloads(config)
|
||||||
if not config.dry_run:
|
if not config.dry_run:
|
||||||
check_java()
|
check_java()
|
||||||
delete_old_changelog()
|
delete_old_changelog()
|
||||||
|
updates_info = load_older_updates(env)
|
||||||
|
|
||||||
logger.info(f"Will Patch only {config.apps}")
|
logger.info(f"Will Patch only {config.apps}")
|
||||||
for possible_app in config.apps:
|
for possible_app in config.apps:
|
||||||
@@ -43,7 +45,7 @@ def main() -> None:
|
|||||||
app.download_apk_for_patching(config)
|
app.download_apk_for_patching(config)
|
||||||
parser.include_exclude_patch(app, app_all_patches, patcher.patches_dict)
|
parser.include_exclude_patch(app, app_all_patches, patcher.patches_dict)
|
||||||
logger.info(app)
|
logger.info(app)
|
||||||
save_patch_info(app)
|
updates_info = save_patch_info(app, updates_info)
|
||||||
parser.patch_app(app)
|
parser.patch_app(app)
|
||||||
except AppNotFoundError as e:
|
except AppNotFoundError as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
@@ -53,7 +55,7 @@ def main() -> None:
|
|||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
except BuilderError as e:
|
except BuilderError as e:
|
||||||
logger.exception(f"Failed to build {possible_app} because of {e}")
|
logger.exception(f"Failed to build {possible_app} because of {e}")
|
||||||
write_changelog_to_file()
|
write_changelog_to_file(updates_info)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -10,15 +10,17 @@ from environs import Env
|
|||||||
|
|
||||||
from src.app import APP
|
from src.app import APP
|
||||||
from src.manager.release_manager import ReleaseManager
|
from src.manager.release_manager import ReleaseManager
|
||||||
from src.utils import branch_name, updates_file
|
from src.utils import branch_name, updates_file, updates_file_url
|
||||||
|
|
||||||
|
|
||||||
class GitHubManager(ReleaseManager):
|
class GitHubManager(ReleaseManager):
|
||||||
"""Release manager with GitHub."""
|
"""Release manager with GitHub."""
|
||||||
|
|
||||||
def __init__(self: Self, env: Env) -> None:
|
def __init__(self: Self, env: Env) -> None:
|
||||||
self.update_file_url = (
|
self.update_file_url = updates_file_url.format(
|
||||||
f"https://raw.githubusercontent.com/{env.str('GITHUB_REPOSITORY')}/{branch_name}/{updates_file}"
|
github_repository=env.str("GITHUB_REPOSITORY"),
|
||||||
|
branch_name=branch_name,
|
||||||
|
updates_file=updates_file,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_last_version(self: Self, app: APP, resource_name: str) -> str:
|
def get_last_version(self: Self, app: APP, resource_name: str) -> str:
|
||||||
|
|||||||
+23
-11
@@ -6,12 +6,14 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import urllib.error
|
||||||
|
import urllib.request
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from json import JSONDecodeError
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from environs import Env
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
from requests import Response, Session
|
from requests import Response, Session
|
||||||
@@ -45,6 +47,7 @@ request_timeout = 60
|
|||||||
session = Session()
|
session = Session()
|
||||||
session.headers["User-Agent"] = request_header["User-Agent"]
|
session.headers["User-Agent"] = request_header["User-Agent"]
|
||||||
updates_file = "updates.json"
|
updates_file = "updates.json"
|
||||||
|
updates_file_url = "https://raw.githubusercontent.com/{github_repository}/{branch_name}/{updates_file}"
|
||||||
changelogs: dict[str, dict[str, str]] = {}
|
changelogs: dict[str, dict[str, str]] = {}
|
||||||
time_zone = "Asia/Kolkata"
|
time_zone = "Asia/Kolkata"
|
||||||
app_version_key = "app_version"
|
app_version_key = "app_version"
|
||||||
@@ -99,7 +102,7 @@ def format_changelog(name: str, response: dict[str, str]) -> dict[str, str]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def write_changelog_to_file() -> None:
|
def write_changelog_to_file(updates_info: dict[str, Any]) -> None:
|
||||||
"""The function `write_changelog_to_file` writes a given changelog json to a file."""
|
"""The function `write_changelog_to_file` writes a given changelog json to a file."""
|
||||||
markdown_table = inspect.cleandoc(
|
markdown_table = inspect.cleandoc(
|
||||||
"""
|
"""
|
||||||
@@ -124,6 +127,7 @@ def write_changelog_to_file() -> None:
|
|||||||
with Path(changelog_file).open("w", encoding="utf_8") as file1:
|
with Path(changelog_file).open("w", encoding="utf_8") as file1:
|
||||||
file1.write(markdown_table)
|
file1.write(markdown_table)
|
||||||
Path(changelog_json_file).write_text(json.dumps(changelogs, indent=4) + "\n")
|
Path(changelog_json_file).write_text(json.dumps(changelogs, indent=4) + "\n")
|
||||||
|
Path(updates_file).write_text(json.dumps(updates_info, indent=4, default=str) + "\n")
|
||||||
|
|
||||||
|
|
||||||
def get_parent_repo() -> str:
|
def get_parent_repo() -> str:
|
||||||
@@ -242,16 +246,24 @@ def datetime_to_ms_epoch(dt: datetime) -> int:
|
|||||||
return int(round(microseconds / float(1000)))
|
return int(round(microseconds / float(1000)))
|
||||||
|
|
||||||
|
|
||||||
def save_patch_info(app: "APP") -> None:
|
def load_older_updates(env: Env) -> dict[str, Any]:
|
||||||
"""Save version info a patching resources used to a file."""
|
"""Load older updated from updates.json."""
|
||||||
|
update_file_url = updates_file_url.format(
|
||||||
|
github_repository=env.str("GITHUB_REPOSITORY"),
|
||||||
|
branch_name=branch_name,
|
||||||
|
updates_file=updates_file,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
with Path(updates_file).open() as file:
|
with urllib.request.urlopen(update_file_url) as url:
|
||||||
old_version = json.load(file)
|
return json.load(url) # type: ignore[no-any-return]
|
||||||
except (JSONDecodeError, FileNotFoundError):
|
except urllib.error.URLError as e:
|
||||||
# Handle the case when the file is empty
|
logger.error(f"Failed to retrieve update file: {e}")
|
||||||
old_version = {} # or any default value you want to assign
|
return {}
|
||||||
|
|
||||||
old_version[app.app_name] = {
|
|
||||||
|
def save_patch_info(app: "APP", updates_info: dict[str, Any]) -> dict[str, Any]:
|
||||||
|
"""Save version info a patching resources used to a file."""
|
||||||
|
updates_info[app.app_name] = {
|
||||||
app_version_key: app.app_version,
|
app_version_key: app.app_version,
|
||||||
integration_version_key: app.resource["integrations"]["version"],
|
integration_version_key: app.resource["integrations"]["version"],
|
||||||
patches_version_key: app.resource["patches"]["version"],
|
patches_version_key: app.resource["patches"]["version"],
|
||||||
@@ -261,4 +273,4 @@ def save_patch_info(app: "APP") -> None:
|
|||||||
"date_patched": datetime.now(timezone(time_zone)),
|
"date_patched": datetime.now(timezone(time_zone)),
|
||||||
"app_dump": app.for_dump(),
|
"app_dump": app.for_dump(),
|
||||||
}
|
}
|
||||||
Path(updates_file).write_text(json.dumps(old_version, indent=4, default=str) + "\n")
|
return updates_info
|
||||||
|
|||||||
Reference in New Issue
Block a user