From 877fd184b500a1aa53aed7b14cf94392c653d765 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 20 Jul 2023 15:11:54 +0800 Subject: [PATCH] Support configure site url Signed-off-by: tison --- action.yml | 3 +++ default_settings.py | 2 +- entrypoint.sh | 32 +++++++++++++++++++------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index f4bb8b26a39625..4666d06f8d2cbc 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,9 @@ inputs: zuliprc: description: 'zuliprc of the Zulip bot' required: true + site_url: + description: 'Base URL for the site' + required: false runs: using: 'docker' image: 'Dockerfile' diff --git a/default_settings.py b/default_settings.py index 38b65fb20d0c48..f8f651a3363a8e 100644 --- a/default_settings.py +++ b/default_settings.py @@ -33,7 +33,7 @@ site_url = "http://127.0.0.1:4000" else: site_url = os.getenv("SITE_URL") - if not site_url: + if site_url is None: raise Exception("You need to configure site_url for prod") """ diff --git a/entrypoint.sh b/entrypoint.sh index b26bd0fc601014..1370fe07c5df3d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,6 +9,7 @@ delete_history=$5 archive_branch=$6 github_personal_access_token=$7 zuliprc=$INPUT_ZULIPRC +site_url=$INPUT_SITE_URL github_personal_access_token=${github_personal_access_token:-NOT_SET} @@ -48,17 +49,22 @@ pip3 install -r requirements.txt # crudini is not available as an Alpine pkg, so we install via pip. pip3 install crudini -# Uses GitHub pages API -# https://docs.github.com/en/rest/pages -auth_header="Authorization: Bearer ${github_token}" -accept_header="Accept: application/vnd.github+json" -version_header="X-GitHub-Api-Version: 2022-11-28" -page_api_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/pages" - -print_site_url_code="import sys, json; print(json.load(sys.stdin)['html_url'])" -# Get the GitHub pages URL -github_pages_url_with_trailing_slash=$(curl -L -H "$accept_header" -H "$auth_header" -H "$version_header" "$page_api_url" | python3 -c "${print_site_url_code}") -github_pages_url=${github_pages_url_with_trailing_slash%/} +if [ -z "$site_url" ]; then + echo "Setting up site URL from GitHub pages API" + # Uses GitHub pages API + # https://docs.github.com/en/rest/pages + auth_header="Authorization: Bearer ${github_token}" + accept_header="Accept: application/vnd.github+json" + version_header="X-GitHub-Api-Version: 2022-11-28" + page_api_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/pages" + + print_site_url_code="import sys, json; print(json.load(sys.stdin)['html_url'])" + # Get the GitHub pages URL + github_pages_url_with_trailing_slash=$(curl -L -H "$accept_header" -H "$auth_header" -H "$version_header" "$page_api_url" | python3 -c "${print_site_url_code}") + site_url=${github_pages_url_with_trailing_slash%/} +else + site_url=${site_url%/} +fi cp default_settings.py settings.py cp $streams_config_file_path . @@ -74,11 +80,11 @@ else fi export PROD_ARCHIVE=true -export SITE_URL=$github_pages_url +export SITE_URL=$site_url export HTML_DIRECTORY=$html_dir_path export JSON_DIRECTORY=$json_dir_path export HTML_ROOT="" -export ZULIP_ICON_URL="${github_pages_url}/assets/img/zulip.svg" +export ZULIP_ICON_URL="${site_url}/assets/img/zulip.svg" if [ ! -d $json_dir_path ]; then mkdir -p $json_dir_path