diff --git a/README.md b/README.md index 3c1e3fe4e0dedd..9d846c24145df7 100644 --- a/README.md +++ b/README.md @@ -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///settings/pages`, select `main` (or a branch of your choosing), and `/` as the folder. Save the changes. +Go to `https://github.com///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://.github.io/` 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 @@ -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///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.io/`, or `/` 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 diff --git a/action.yml b/action.yml index f4bb8b26a39625..2b82c630dc51c1 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. If not configured, this action will try to resolve the base URL as GH pages.' + required: false runs: using: 'docker' image: 'Dockerfile' 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