-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.sh
78 lines (52 loc) · 1.57 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/sh -l
#! /bin/bash
set -e
if [ -z "$ACCESS_TOKEN" ]
then
echo "ACCESS_TOKEN is required"
exit 1
fi
if [ -z "$COMMIT_EMAIL" ]
then
echo "COMMIT_EMAIL is required"
exit 1
fi
if [ -z "$FOLDER" ]
then
echo "deploy FOLDER is required"
exit 1
fi
apt-get update && \
apt-get install -y git && \
if [ -z "$COMMIT_NAME" ]
then
COMMIT_NAME="${GITHUB_ACTOR}"
fi
cd $GITHUB_WORKSPACE && \
git init && \
git config --global user.email "${COMMIT_EMAIL}" && \
git config --global user.name "${COMMIT_NAME}" && \
REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \
git checkout "${BASE_BRANCH:-master}"
echo "----------------Running build scripts ---------------"
eval "$BUILD_SCRIPT" && \
echo "---------checkout---to---${DEPLOY_BRANCH:-gh-pages}-----"
git checkout --orphan "${DEPLOY_BRANCH:-gh-pages}" && \
git rm -rf . && \
if [ "$(git ls-remote --heads "$REPOSITORY_PATH" "${DEPLOY_BRANCH:-gh-pages}" | wc -l)" -ne 0 ];
then
echo "----- ${DEPLOY_BRANCH:-gh-pages} already exist-----sync origin----"
git pull origin "${DEPLOY_BRANCH:-gh-pages}"
fi
echo "---------remove node_modules && other useless files------"
shopt -s extglob
rm -rf !($FOLDER) && cp -r $FOLDER/. ./ && rm -r $FOLDER && \
echo "---------generate commit && push------"
if [ -z "$(git status --porcelain)" ]; then
echo "Nothing to deploy"
else
git add . && \
git commit -m "Deploying ${DEPLOY_BRANCH:-gh-pages} from ${BASE_BRANCH:-master} ${GITHUB_SHA}"
git push $REPOSITORY_PATH "${DEPLOY_BRANCH:-gh-pages}"
fi
echo "------- deploy successful ----------- "