From 259ef296fa112e0e3ab009eb5887d43ad475fa46 Mon Sep 17 00:00:00 2001 From: Ricki Jay Date: Tue, 27 Feb 2024 13:54:22 +0100 Subject: [PATCH] Build Parameter --- build.sh | 14 +++++++++++ update_commits.py | 63 ++++++++++++----------------------------------- update_commits.sh | 11 --------- 3 files changed, 30 insertions(+), 58 deletions(-) delete mode 100755 update_commits.sh diff --git a/build.sh b/build.sh index e57801295..ccb18e336 100755 --- a/build.sh +++ b/build.sh @@ -17,6 +17,17 @@ source ./versions.inc.sh DOCKER_BUILD_CACHE_OPT="" +# ℹ️ Update Commit Hashes +function update_commit_hashes { + docker compose \ + --file test/docker-compose.yml \ + --env-file test/test-runner.env \ + run --rm --build test-runner -c " + cd .. + python3 -m pip install requests bs4 lxml + python3 update_commits.py + " +} # wikibase/wdqs -> wdqs function image_url_to_image_name { @@ -205,6 +216,9 @@ for arg in "$@"; do build_all build_target_set=true ;; + update_hashes) + update_commit_hashes + ;; -n|--no-cache) DOCKER_BUILD_CACHE_OPT="--no-cache" ;; diff --git a/update_commits.py b/update_commits.py index c19e4f656..38db785dd 100644 --- a/update_commits.py +++ b/update_commits.py @@ -2,9 +2,7 @@ from bs4 import BeautifulSoup -def get_commit( - variable: str, url: str, parse_commit: callable, previous_commit: str -): +def get_commit(variable: str, url: str, parse_commit: callable, previous_commit: str): print(f"Variable:\t{variable}") print(f"\tURL:\t{url}") try: @@ -22,11 +20,8 @@ def get_commit( return False -mediawiki_gerrit_pattern = re.compile( - r"# (https://gerrit.*/heads/REL\d+_\d+)[ \t\r\n]*([A-Z]+_COMMIT)=([0-9a-f]+)" -) -not_mediawiki_gerrit_pattern = re.compile( - r"# (https://gerrit.*/heads/master)[ \t\r\n]*([A-Z]+_COMMIT)=([0-9a-f]+)" +gerrit_pattern = re.compile( + r"# (https://gerrit.*)[ \t\r\n]*([A-Z]+_COMMIT)=([0-9a-f]+)" ) @@ -58,14 +53,6 @@ def parse_bitbucket_commit(response: requests.Response) -> str: return data["values"][0]["hash"] -def user_approves() -> bool: - try: - return "y" in input("Update Commit? Y/n ").lower() - except Exception as exc: - print(f"\tError:\t{exc}") - return False - - def run(): with open("variables.env", "r") as variable_file: variable_contents = variable_file.read() @@ -75,7 +62,7 @@ def run(): print(f"Mediawiki Version:\t{mediawiki_match.group(1)}.{mediawiki_match.group(2)}") variable_contents = re.sub(r"\bREL\d+_\d+", rel, variable_contents) - for gerrit_commit in re.findall(mediawiki_gerrit_pattern, variable_contents): + for gerrit_commit in re.findall(gerrit_pattern, variable_contents): if commit := get_commit( gerrit_commit[1], gerrit_commit[0], @@ -87,30 +74,14 @@ def run(): f"{gerrit_commit[1]}={commit}", variable_contents, ) - for gerrit_commit in re.findall(not_mediawiki_gerrit_pattern, variable_contents): - if ( - commit := get_commit( - gerrit_commit[1], - gerrit_commit[0], - parse_gerrit_commit, - gerrit_commit[2], - ) - ) and user_approves(): - variable_contents = re.sub( - f"{gerrit_commit[1]}=[0-9a-f]+", - f"{gerrit_commit[1]}={commit}", - variable_contents, - ) for github_commit in re.findall(github_pattern, variable_contents): - if ( - commit := get_commit( - github_commit[2], - f"https://api.github.com/repos/{github_commit[1]}", - parse_github_commit, - github_commit[3], - ) - ) and user_approves(): + if commit := get_commit( + github_commit[2], + f"https://api.github.com/repos/{github_commit[1]}", + parse_github_commit, + github_commit[3], + ): variable_contents = re.sub( f"{github_commit[2]}=[0-9a-f]+", f"{github_commit[2]}={commit}", @@ -118,14 +89,12 @@ def run(): ) for bitbucket_commit in re.findall(bitbucket_pattern, variable_contents): - if ( - commit := get_commit( - bitbucket_commit[2], - f"https://bitbucket.org/!api/2.0/repositories/{bitbucket_commit[1]}", - parse_bitbucket_commit, - bitbucket_commit[3], - ) - ) and user_approves(): + if commit := get_commit( + bitbucket_commit[2], + f"https://bitbucket.org/!api/2.0/repositories/{bitbucket_commit[1]}", + parse_bitbucket_commit, + bitbucket_commit[3], + ): variable_contents = re.sub( f"{bitbucket_commit[2]}=[0-9a-f]+", f"{bitbucket_commit[2]}={commit}", diff --git a/update_commits.sh b/update_commits.sh deleted file mode 100755 index c2473734b..000000000 --- a/update_commits.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -# ℹ️ Update Commit Hashes -docker compose \ ---file test/docker-compose.yml \ ---env-file test/test-runner.env \ -run --rm --build test-runner -c " -cd .. -python3 -m pip install requests bs4 lxml -python3 update_commits.py -"