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 5 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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ You will need to create the following secret. Use the credentials generated in t
|--------------|------------------------------------------------------|
|zuliprc | The file content of the zuliprc obtained from step 2 |

### Step 4 - Enable GitHub Pages
### Step 4 - Enable GitHub Pages or set up base URL

Go to `https://github.com/<username>/<repo-name>/settings/pages`, select `main` (or a branch of your choosing), and `/` as the folder. Save the changes.
Go to `https://github.com/<username>/<repo-name>/settings/pages`, select `main` (or a branch of your choosing), and `/` as the folder. Save the changes. The base URL of the generated site will be resolved to GitHub Pages, i.e., `https://<username>.github.io/<repo-name>` or the configured custom domain name.

Alternatively, you can configure the `base_url` option to populate the base URL. This option could be useful in situation when you are not using GitHub Pages.

### Step 5 - Configure the streams you want to index

Expand Down Expand Up @@ -137,6 +139,7 @@ warned that the repository size may explode.

Finally, verify that everything is working as expected. You can track the status of the action by visiting `https://github.com/<github-username>/<repo-name>/actions`. Once the initial run is completed, you should be able to visit the archive by opening the link provided at the end of the action run log. The link will generally be of the form `<github-username>.github.io/<repo-name>`, or `<your-personal-domain>/<repo-name>` if you have configured your own personal domain to point to GitHub pages.

If you configure `base_url` option, you can track the status of the action by visiting the URL instead.

## Running zulip-archive without GitHub actions

Expand Down
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. If not configured, this action will try to resolve the base URL as GH pages.'
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