-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·106 lines (81 loc) · 2.15 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·106 lines (81 loc) · 2.15 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
ACTOR=futureimperfect
CNAME=everythingisgray.com
HUGO=hugo
HUGO_VERSION=0.79.0
TARGET_REPO=futureimperfect/futureimperfect.github.io
THEME=cactus
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd -P)
# If a command fails then the deploy stops.
set -e
printf "\033[0;32mDeploying updates to GitHub...\033[0m\n"
REF="$1"
if [ -z "$1" ]; then
REF="master"
fi
if [ -z "$TOKEN" ]; then
TOKEN="$GITHUB_TOKEN"
fi
if [ -z "$GITHUB_ACTOR" ]; then
GITHUB_ACTOR="$ACTOR"
fi
if [ -z "$TARGET_REPO" ]; then
TARGET_REPO="$GITHUB_REPOSITORY"
fi
if [ "$CI" = "true" ]; then
cd "$GITHUB_WORKSPACE" || exit 1
fi
REMOTE_REPO="git@github.com:${TARGET_REPO}.git"
# Themes use submodules. We need them. Don't include the GitHub Pages repo in the updates, though.
git -c submodule."public".update=none submodule update --init --recursive
if [ "$CI" = "true" ]; then
echo "Installing Hugo..."
curl -fsSL "https://github.com/spf13/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz" > hugo.tar.gz && tar -zxvf hugo.tar.gz
HUGO=./hugo
elif [ -z "$(command -v hugo)" ]; then
echo "You must install Hugo before continuing."
exit 1
fi
# Print the Hugo version.
echo "Hugo version: " && "$HUGO" version
# Build the project.
if [ -z "$THEME" ]; then
"$HUGO"
else
"$HUGO" -t "$THEME"
fi
# Go to the public folder.
if [ "$CI" = "true" ]; then
PUBLIC_DIR="${GITHUB_WORKSPACE}/public"
else
PUBLIC_DIR="${SCRIPT_DIR}/public"
fi
cd "$PUBLIC_DIR"
# Remove the existing public .git dir.
rm -rf .git
# Create CNAME file.
if [ -z "$CNAME" ]; then
echo "${GITHUB_ACTOR}.github.io" > CNAME
else
echo "$CNAME" > CNAME
fi
# Add a README.md.
echo "# ${GITHUB_ACTOR}.github.io" > "${PUBLIC_DIR}/README.md"
# Create a new Git repo.
git init
git config user.name "$GITHUB_ACTOR"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
# Add changes to git.
git add .
# Set the commit message.
msg="Rebuilding site on $(date)"
if [ -n "$*" ]; then
msg="$*"
fi
# Commit changes.
git commit -m "$msg"
# Push source and build repos.
git push --force "$REMOTE_REPO" "master:${REF}"
# Go back to the original directory.
cd -
exit 0