Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/deploy_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 16 additions & 8 deletions scripts/deploy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions scripts/login_and_get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading