-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·56 lines (43 loc) · 1.5 KB
/
deploy.sh
File metadata and controls
executable file
·56 lines (43 loc) · 1.5 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
#!/bin/bash
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"
# Initialize and update the public submodule if needed
if [ ! -d "public/.git" ]; then
echo "Initializing and updating public submodule..."
git submodule update --init --recursive
else
echo "Updating public submodule..."
git submodule update --recursive
fi
# Go to public folder
cd public || { echo "Failed to cd into public"; exit 1; }
# Ensure we’re on the correct branch and discard any local changes
git fetch origin
git checkout master || git checkout -B master origin/master
git reset --hard origin/master
# Return to project root to build site
cd .. || { echo "Failed to return to project root"; exit 1; }
# Clean the public folder except .git
echo "Cleaning public folder..."
find public -mindepth 1 ! -name '.git' -exec rm -rf {} +
# Build the Hugo site into public/
echo "Building site with Hugo..."
hugo --environment production
# Go back to public folder to commit changes
cd public || { echo "Failed to cd into public"; exit 1; }
# Stage all changes, including deletions
git add -A
# Commit changes
msg="rebuilding site $(date)"
if [ $# -eq 1 ]; then
msg="$1"
fi
git commit -m "$msg" || echo "No changes to commit"
# Push to GitHub
git push origin master || echo "Push failed"
# Return to project root
cd ..
echo -e "\033[0;32mDeployment complete!\033[0m"
# Update submodule reference
git add public
git commit -m "$msg (Submodule Reference Update)" || echo "No submodule reference change to commit"
git push origin master