Skip to content

Commit

Permalink
Support configure site url
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Jul 20, 2023
1 parent b5561fd commit 877fd18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

"""
Expand Down
32 changes: 19 additions & 13 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

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

0 comments on commit 877fd18

Please sign in to comment.