diff --git a/scripts/deploy_res.py b/scripts/deploy_res.py index 2b30f76a840..1a0020715bc 100644 --- a/scripts/deploy_res.py +++ b/scripts/deploy_res.py @@ -31,7 +31,7 @@ def deploy_resources( file_content = read_file_from_path(file_path) page = ( f"MediaWiki:Common.{'js' if res_type == '.js' else 'css'}/" - + file_path.name + + "/".join(file_path.parts[2:]) ) print(f"...page = {page}") deploy_result = deploy_file_to_wiki( @@ -74,8 +74,8 @@ def main(): git_deploy_reason: str if len(sys.argv[1:]) == 0: resource_files = itertools.chain( - pathlib.Path("./javascript/").rglob("*.js"), - pathlib.Path("./stylesheets/").rglob("*.scss"), + pathlib.Path("./javascript/commons/").rglob("*.js"), + pathlib.Path("./stylesheets/commons/").rglob("*.scss"), ) git_deploy_reason = "Automated Weekly Re-Sync" else: diff --git a/scripts/deploy_util.py b/scripts/deploy_util.py index 32552af2238..dc4060f635e 100644 --- a/scripts/deploy_util.py +++ b/scripts/deploy_util.py @@ -21,6 +21,7 @@ ] DEPLOY_TRIGGER = os.getenv("DEPLOY_TRIGGER") +DRY_RUN = bool(int(os.getenv("DRY_RUN", 0))) GITHUB_STEP_SUMMARY_FILE = os.getenv("GITHUB_STEP_SUMMARY") USER_AGENT = f"GitHub Autodeploy Bot/2.0.0 ({os.getenv('WIKI_UA_EMAIL')})" WIKI_BASE_URL = os.getenv("WIKI_BASE_URL") @@ -64,20 +65,27 @@ def deploy_file_to_wiki( token: str, deploy_reason: str, ) -> tuple[bool, bool]: + payload = { + "title": target_page, + "text": file_content, + "summary": f"Git: {deploy_reason}", + "bot": "true", + "recreate": "true", + "token": token, + } + if DRY_RUN: + print(f"HEADER: {HEADER}") + print(f"PARAM: { {'format': 'json', 'action': 'edit'} }") + print(f"DATA: {payload}") + return True, False + change_made = False deployed = True response = session.post( get_wiki_api_url(wiki), headers=HEADER, params={"format": "json", "action": "edit"}, - data={ - "title": target_page, - "text": file_content, - "summary": f"Git: {deploy_reason}", - "bot": "true", - "recreate": "true", - "token": token, - }, + data=payload, ).json() edit_info = response.get("edit") error_info = response.get("error") diff --git a/scripts/login_and_get_token.py b/scripts/login_and_get_token.py index d91b92afd10..2f6afa81b33 100644 --- a/scripts/login_and_get_token.py +++ b/scripts/login_and_get_token.py @@ -8,6 +8,7 @@ __all__ = ["get_token"] +DRY_RUN = bool(int(os.getenv("DRY_RUN", 0))) WIKI_USER = os.getenv("WIKI_USER") WIKI_PASSWORD = os.getenv("WIKI_PASSWORD") @@ -19,6 +20,8 @@ def login(wiki: str): return cookie_jar = read_cookie_jar(wiki) print(f"...logging in on {wiki}") + if DRY_RUN: + return with requests.Session() as session: session.cookies = cookie_jar token_response = session.post( @@ -50,6 +53,9 @@ def login(wiki: str): def get_token(wiki: str) -> str: login(wiki) + if DRY_RUN: + return "DRY_RUN_DUMMY_TOKEN" + with requests.Session() as session: session.cookies = read_cookie_jar(wiki) token_response = session.post(