2023-05-05 08:55:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-05-05 09:24:28 +00:00
|
|
|
set -ea
|
2023-05-05 08:55:24 +00:00
|
|
|
if [[ $DEBUG != "" ]]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
## source vars from .env first ##
|
|
|
|
_root_directory_git=$(git rev-parse --show-toplevel)
|
2023-05-05 09:24:28 +00:00
|
|
|
# shellcheck file=/dev/null
|
|
|
|
source "$_root_directory_git/.env"
|
2023-05-05 08:55:24 +00:00
|
|
|
|
|
|
|
_branch_name_git=$(git rev-parse --abbrev-ref HEAD)
|
|
|
|
_commit_sha=$(git rev-parse HEAD)
|
|
|
|
_commit_sha_short=$(git rev-parse --short HEAD)
|
|
|
|
_command_prefix="npx wrangler pages publish $_root_directory_git/public --project-name $CF_PAGES_PROJECT_NAME --branch $_branch_name_git --commit-hash $_commit_sha"
|
|
|
|
|
|
|
|
warn() {
|
|
|
|
echo "warning: $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
echo "error: $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
info() {
|
|
|
|
echo "info: $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $_branch_name_git == "main" ]]; then
|
|
|
|
DEPLOY_COMMAND="$_command_prefix --env production"
|
|
|
|
elif [[ $CI_PIPELINE_SOURCE == "merge_request" ]]; then
|
|
|
|
DEPLOY_COMMAND="$_command_prefix --env pr-#CI_MERGE_REQUEST_ID"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! git diff-index --quiet HEAD -- && [[ $FF_DIRTY_DEPLOY != "true" ]]; then
|
|
|
|
error Possible dirty working directory, aborting for safety reasons...
|
|
|
|
info To deploy while still dirty, set FF_DIRTY_DEPLOY=true on next invocation.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -d "$_root_directory_git/public" ]]; then
|
|
|
|
bash "$_root_directory_git/bin/build.sh"
|
2023-07-15 16:56:29 +00:00
|
|
|
cp markdown/.well-known public/ -rv
|
2023-05-05 08:55:24 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $FF_DIRTY_DEPLOY == "true" ]]; then
|
|
|
|
$DEPLOY_COMMAND --commit-dirty
|
|
|
|
else
|
|
|
|
${DEPLOY_COMMAND:-"$_command_prefix"}
|
|
|
|
fi
|
|
|
|
|
2023-07-15 16:49:46 +00:00
|
|
|
if [[ $_branch_name_git == "main" ]]; then
|
|
|
|
tar -C public -cvz . -f site-build.tar.gz
|
|
|
|
curl --oauth2-bearer "$SOURCEHUT_PAGES_TOKEN" \
|
|
|
|
-Fcontent=@site-build.tar.gz \
|
|
|
|
"https://pages.sr.ht/publish/ajhalili2006.srht.site"
|
|
|
|
fi
|
|
|
|
|
2023-05-05 08:55:24 +00:00
|
|
|
if [[ $DEBUG != "" ]]; then
|
|
|
|
set +x
|
2023-05-05 09:24:28 +00:00
|
|
|
fi
|
|
|
|
set +a
|