-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy
executable file
·59 lines (47 loc) · 1.16 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
#!/bin/bash
# Stop on error
set -e
# Fail on pipe errors
set -o pipefail
# Variables
BRANCH="gh-pages"
BRANCH_FROM="master"
DEPLOY_CONFIG="_config-deploy.yml"
# Get the current Git repository URL
URL=$(git config --get remote.origin.url)
if [ -z "$URL" ]; then
echo "Error: Not a Git repository or no remote set."
exit 1
fi
# Get the current working directory as the source
SRC=$(pwd)
# Create a temporary directory
TEMP=$(mktemp -d -t jgd-XXX)
# Function to clean up temporary directory on exit
function cleanup {
rm -rf "$TEMP"
}
trap cleanup EXIT
# Clone and copy directories
CLONE="$TEMP/clone"
# echo -e 'Cloning Github repository:'
# git clone -b "$BRANCH_FROM" "$URL" "$CLONE"
# Build Jekyll site
echo -e '\nBuilding Jekyll site:'
# rm -rf _site
if [ -r "$SRC/$DEPLOY_CONFIG" ]; then
bundle exec jekyll build --config "$SRC/$DEPLOY_CONFIG"
else
bundle exec jekyll build
fi
cp -r _site "$CLONE"
cd "$CLONE"
# Push _site to gh-pages branch
touch .nojekyll
git init
git remote add origin "$URL"
git checkout -b "$BRANCH"
git add .
git commit -m "Deploy Jekyll site"
git push -u origin "$BRANCH" --force
# echo "Jekyll site deployed to $BRANCH branch."