forked from Cecilapp/GitHub-Pages-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
61 lines (57 loc) · 1.69 KB
/
entrypoint.sh
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
#!/bin/sh
set -e
# commiter email
if [ -z "$EMAIL" ]; then
echo "A verified email is required"
exit 1
fi
REPONAME="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 2)"
OWNER="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 1)"
GHIO="${OWNER}.github.io"
TARGET_BRANCH="gh-pages"
BUILD_DIR="_book"
echo "### Started deploy to $GITHUB_REPOSITORY/$TARGET_BRANCH"
# remove the ending slash if exists
BUILD_DIR=${BUILD_DIR%/}
mkdir -p $HOME/$BUILD_DIR
cp -R $BUILD_DIR/* $HOME/$BUILD_DIR/
cd $HOME
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$EMAIL"
if [ -z "$(git ls-remote --heads https://${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git ${TARGET_BRANCH})" ]; then
git clone --quiet https://${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git $TARGET_BRANCH > /dev/null
cd $TARGET_BRANCH
git checkout --orphan $TARGET_BRANCH
git rm -rf .
echo "$REPONAME" > README.md
git add README.md
git commit -a -m "Create $TARGET_BRANCH branch"
git push origin $TARGET_BRANCH
cd ..
else
git clone --quiet --branch=$TARGET_BRANCH https://${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git $TARGET_BRANCH > /dev/null
fi
cp -R $TARGET_BRANCH/.git $HOME/.git
rm -rf $TARGET_BRANCH/*
cp -R $HOME/.git $TARGET_BRANCH/.git
cd $TARGET_BRANCH
cp -Rf $HOME/${BUILD_DIR}/* .
# custom domain?
if [ ! -z "$CNAME" ]; then
echo "Add custom domain file"
echo "$CNAME" > CNAME
fi
# .nojekyll
if [ "$JEKYLL_SITE" != "YES" ]; then
echo "Disable Jekyll"
touch .nojekyll
fi
# Nothing to deploy?
if [ -z "$(git status --porcelain)" ]; then
echo "Nothing to deploy"
else
git add -Af .
git commit -m "$GITHUB_ACTOR published a site update"
git push -fq origin $TARGET_BRANCH > /dev/null
fi
echo "### Finished deploy"