🎨 Save patch resource version

This commit is contained in:
Nikhil Badyal
2024-04-12 16:57:55 +05:30
committed by Nikhil Badyal
parent 0d84842ee4
commit 4a08e7affe
4 changed files with 26 additions and 2 deletions
+1 -1
View File
@@ -104,6 +104,6 @@ jobs:
with: with:
branch: changelogs branch: changelogs
skip_checkout: true skip_checkout: true
file_pattern: changelog.md file_pattern: 'changelog.md updates.json'
commit_message: 🚀New Build commit_message: 🚀New Build
push_options: '--force' push_options: '--force'
+2 -1
View File
@@ -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 from src.utils import check_java, delete_old_changelog, save_patch_info
def get_app(config: RevancedConfig, app_name: str) -> APP: def get_app(config: RevancedConfig, app_name: str) -> APP:
@@ -42,6 +42,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)
parser.patch_app(app) parser.patch_app(app)
except AppNotFoundError as e: except AppNotFoundError as e:
logger.info(e) logger.info(e)
+22
View File
@@ -1,8 +1,10 @@
"""Utilities.""" """Utilities."""
import json
import re import re
import subprocess import subprocess
import sys import sys
from json import JSONDecodeError
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
@@ -31,6 +33,7 @@ changelog_file = "changelog.md"
request_timeout = 60 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"
def update_changelog(name: str, response: dict[str, str]) -> None: 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: def contains_any_word(string: str, words: list[str]) -> bool:
"""Checks if a string contains any word.""" """Checks if a string contains any word."""
return any(word in string for word in words) 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")
+1
View File
@@ -0,0 +1 @@
{}