-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy
executable file
·60 lines (44 loc) · 1.7 KB
/
deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -euo pipefail
# TODO: Find a way to eliminate these hardcoded values.
FNM="/opt/homebrew/bin/fnm"
ENVIRONMENT_FILE="$HOME/Development/landonschropp.com/.envrc"
# Display a notification if the script fails.
trap 'osascript -e "display notification \"😵 Failed to deploy.\" with title \"landonschropp.com\""' ERR
# Wait a minute before attempting to deploy to ensure a network is present.
sleep 60
# Clone the repo to a temporary directory.
TEMP_DIR=$(mktemp -d)
git clone --depth 1 [email protected]:LandonSchropp/landonschropp.github.io.git "$TEMP_DIR"
cd "$TEMP_DIR"
# Source the environment variables used by the build.
# shellcheck disable=SC1090
source "$ENVIRONMENT_FILE"
# Check if the latest SHA for the content has already been deployed. Given how simple this check is
# and that it relies on a temporary file, it's likely to occasionally miss. However, if that happens
# the site simply deploys, which is fine.
SHA=$(
(
ls -alR "$NOTES_PATH" "$ARTICLES_PATH" "$TODAY_I_LEARNED_PATH"
git rev-parse HEAD
) | sha1sum
)
SHA_PATH="/tmp/com.landonschropp.deploy.sha"
if [ -f "$SHA_PATH" ] && [ "$SHA" = "$(cat "$SHA_PATH")" ]; then
osascript -e 'display notification "😎 Nothing to deploy" with title "landonschropp.com"'
exit 0
fi
# Set up pnpm and node
eval "$($FNM env --corepack-enabled)"
$FNM use --install-if-missing
corepack enable pnpm
# Install the dependencies
pnpm install
# Build the project
pnpm build
# Deploy the build
pnpm gh-pages --dist dist
# Write the SHA after a successful deployment.
echo "$SHA" >"$SHA_PATH"
# Display a notification if the deployment succeeds.
osascript -e 'display notification "🥳 Deployed successfully!" with title "landonschropp.com"'