~ajhalili2006's personal website, built with Zensical (successor of Material for Mkdocs) [old repo name got bugged while attempting to do manual knot migration via repo deletion]
andreijiroh.dev
zensical
mkdocs-material
website
1#!/usr/bin/env bash
2set -ea
3if [[ $DEBUG != "" ]]; then
4 set -x
5fi
6
7## source vars from .env first ##
8_root_directory_git=$(git rev-parse --show-toplevel)
9# shellcheck file=/dev/null
10if [[ -f "$_root_directory_git/.env" ]]; then
11 source "$_root_directory_git/.env"
12fi
13
14_branch_name_git=$(git rev-parse --abbrev-ref HEAD)
15_commit_sha=$(git rev-parse HEAD)
16_commit_sha_short=$(git rev-parse --short HEAD)
17
18warn() {
19 echo "warning: $*"
20}
21
22error() {
23 echo "error: $*"
24}
25
26info() {
27 echo "info: $*"
28}
29
30if [[ $_branch_name_git == "main" ]] || [[ $_branch_name_git == "HEAD" ]]; then
31 export DEPLOY_COMMAND="npx wrangler pages deploy ${_root_directory_git}/public --project-name ${CF_PAGES_PROJECT_NAME} --branch main --commit-hash ${_commit_sha} --env production"
32elif [[ $CI_PIPELINE_SOURCE == "merge_request" ]]; then
33 export DEPLOY_COMMAND="npx wrangler pages deploy ${_root_directory_git}/public --project-name ${CF_PAGES_PROJECT_NAME} --branch ${_branch_name_git} --commit-hash ${_commit_sha} --env pr-$CI_MERGE_REQUEST_ID"
34fi
35
36if ! git diff-index --quiet HEAD -- && [[ $FF_DIRTY_DEPLOY != "true" ]]; then
37 error Possible dirty working directory, aborting for safety reasons...
38 info To deploy while still dirty, set FF_DIRTY_DEPLOY=true on next invocation.
39 exit 1
40fi
41
42if [[ ! -d "$_root_directory_git/public" ]]; then
43 bash "$_root_directory_git/bin/build.sh"
44 cp markdown/.well-known public/ -rv
45fi
46
47if [[ $FF_DIRTY_DEPLOY == "true" ]]; then
48 $DEPLOY_COMMAND --commit-dirty=true
49else
50 DEFAULT_COMMAND="npx wrangler pages publish ${_root_directory_git}/public --project-name ${CF_PAGES_PROJECT_NAME} --branch main --env production"
51 ${DEPLOY_COMMAND:-$DEFAULT_COMMAND}
52fi
53unset DEPLOY_COMMAND
54
55if [[ $_branch_name_git == "main" ]] || [[ $_branch_name_git == "HEAD" ]]; then
56 tar -C public -cvz . -f site-build.tar.gz
57 curl --oauth2-bearer "$SOURCEHUT_PAGES_TOKEN" \
58 -Fcontent=@site-build.tar.gz \
59 "https://pages.sr.ht/publish/ajhalili2006.srht.site"
60fi
61
62if [[ $DEBUG != "" ]]; then
63 set +x
64fi
65set +a