Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configure site url #106

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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:
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
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}")
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
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