From a9f5ed7470ed6e052979b9df2fd7be062745c3e9 Mon Sep 17 00:00:00 2001 From: sdarwin Date: Fri, 22 Nov 2024 10:06:20 -0700 Subject: [PATCH] publish_release.py: alert websites via webhook --- publish_release.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/publish_release.py b/publish_release.py index f199d37..197248c 100755 --- a/publish_release.py +++ b/publish_release.py @@ -39,6 +39,7 @@ from pathlib import Path import subprocess import pathlib +import time # run: pip3 install python-dotenv from dotenv import load_dotenv @@ -50,6 +51,7 @@ # git tag settings: # webhook settings: +boost_websites = ["https://www.boost.io", "https://www.stage.boost.cppalliance.org"] # defaults, used later stagingPath2 = "" @@ -198,6 +200,93 @@ def preflight(): # github verification: # webhook verification: + print("Checking admin login to boost.io") + WEB_USER = os.getenv("WEB_USER", "marshall@idio.com") + WEB_PASSWORD = os.getenv("WEB_USER", "qqq") + WEBSITE_URL = boost_websites[0] + BASE_ADMIN = f"{WEBSITE_URL}/admin/" + LOGIN = f"{BASE_ADMIN}login/" + NEW_RELEASE = f"{BASE_ADMIN}versions/version/new_versions/" + + session = requests.session() + # do a request just to get a csrftoken + response = session.get(LOGIN) + response.raise_for_status() + response = session.post( + LOGIN, + data={ + "csrfmiddlewaretoken": session.cookies["csrftoken"], + "username": WEB_USER, + "password": WEB_PASSWORD, + }, + ) + response.raise_for_status() + if "errornote" in response.text: + print( + "An 'errornote' was found in the attempt to log into boost.io with your WEB_USER and WEB_PASSWORD. Review those values in the .env file, and try manually logging into the admin panel" + ) + answer = input("Do you want to continue anyway: [y/n]") + if not answer or answer[0].lower() != "y": + print("Exiting.") + exit(1) + + +def import_new_releases(): + print( + "\nThe last step is to trigger a version import on boost.io. This can also be done by visiting https://www.boost.io/admin/versions/version/ and clicking Import New Releases. publish_release.py will remotely contact that webpage with a GET request.\n" + ) + print("Waiting 2 minutes for the CDN to update, before proceeding.\n") + time.sleep(120) + + for s in suffixes: + for appended in ["", ".json"]: + archiveFilename = actualName + s + appended + archivePathRemote = re.sub("^main/", "", destRepo) + url = f"{fastlyURL}{archivePathRemote}{archiveFilename}" + + result = subprocess.run( + f"curl --output /dev/null --silent --head --fail {url}", + capture_output=True, + shell=True, + text=True, + ) + + if result.returncode != 0: + print( + f"\n{archiveFilename} is not present on the CDN, when it was expected. Check all the release files are available for download, and then manually log into the website to import releases. Exiting.\n" + ) + print(result) + exit(1) + else: + print( + "Expected archive file is present. See debug output below. continuing." + ) + print(result) + + for boost_website in boost_websites: + WEB_USER = os.getenv("WEB_USER", "marshall@idio.com") + WEB_PASSWORD = os.getenv("WEB_USER", "qqq") + BASE_ADMIN = f"{boost_website}/admin/" + LOGIN = f"{BASE_ADMIN}login/" + NEW_RELEASE = f"{BASE_ADMIN}versions/version/new_versions/" + session = requests.session() + # do a request just to get a csrftoken + response = session.get(LOGIN) + response.raise_for_status() + response = session.post( + LOGIN, + data={ + "csrfmiddlewaretoken": session.cookies["csrftoken"], + "username": WEB_USER, + "password": WEB_PASSWORD, + }, + ) + response.raise_for_status() + print(f"Contacting {NEW_RELEASE}") + response = session.get(NEW_RELEASE) + response.raise_for_status() + + # End of function import_new_releases ##### @@ -462,3 +551,5 @@ def preflight(): if result.returncode != 0: print("SSH FAILED") print(result) + +import_new_releases()