From 4a08e7affebb4b9c7558fbebd0e414202e734460 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Fri, 12 Apr 2024 16:57:55 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Save=20patch=20resource=20versio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-artifact.yml | 2 +- main.py | 3 ++- src/utils.py | 22 ++++++++++++++++++++++ updates.json | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 updates.json diff --git a/.github/workflows/build-artifact.yml b/.github/workflows/build-artifact.yml index 1178a97..b44d341 100644 --- a/.github/workflows/build-artifact.yml +++ b/.github/workflows/build-artifact.yml @@ -104,6 +104,6 @@ jobs: with: branch: changelogs skip_checkout: true - file_pattern: changelog.md + file_pattern: 'changelog.md updates.json' commit_message: 🚀New Build push_options: '--force' diff --git a/main.py b/main.py index ee3622c..0e66aac 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,7 @@ from src.downloader.download import Downloader from src.exceptions import AppNotFoundError, BuilderError, PatchesJsonLoadError, PatchingFailedError from src.parser import Parser from src.patches import Patches -from src.utils import check_java, delete_old_changelog +from src.utils import check_java, delete_old_changelog, save_patch_info def get_app(config: RevancedConfig, app_name: str) -> APP: @@ -42,6 +42,7 @@ def main() -> None: app.download_apk_for_patching(config) parser.include_exclude_patch(app, app_all_patches, patcher.patches_dict) logger.info(app) + save_patch_info(app) parser.patch_app(app) except AppNotFoundError as e: logger.info(e) diff --git a/src/utils.py b/src/utils.py index 40ce908..ade9548 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,8 +1,10 @@ """Utilities.""" +import json import re import subprocess import sys +from json import JSONDecodeError from pathlib import Path from typing import Any @@ -31,6 +33,7 @@ changelog_file = "changelog.md" request_timeout = 60 session = Session() session.headers["User-Agent"] = request_header["User-Agent"] +updates_file = "updates.json" def update_changelog(name: str, response: dict[str, str]) -> None: @@ -198,3 +201,22 @@ def apkmirror_status_check(package_name: str) -> Any: def contains_any_word(string: str, words: list[str]) -> bool: """Checks if a string contains any word.""" return any(word in string for word in words) + + +def save_patch_info(app: Any) -> None: + """Save version info a patching resources used to a file.""" + try: + with Path(updates_file).open() as file: + old_version = json.load(file) + except (JSONDecodeError, FileNotFoundError): + # Handle the case when the file is empty + old_version = {} # or any default value you want to assign + + old_version[app.app_name] = { + "version": app.app_version, + "integrations_version": app.resource["integrations"]["version"], + "patches_version": app.resource["patches"]["version"], + "cli_version": app.resource["cli"]["version"], + "patches_json_version": app.resource["patches_json"]["version"], + } + Path(updates_file).write_text(json.dumps(old_version, indent=4) + "\n") diff --git a/updates.json b/updates.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/updates.json @@ -0,0 +1 @@ +{}