forked from y4code/hexo-deploy-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
81 lines (59 loc) · 1.77 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
79
80
81
#!/bin/sh -l
set -e
# check values
if [ -n "${PUBLISH_REPOSITORY}" ]; then
PRO_REPOSITORY=${PUBLISH_REPOSITORY}
else
PRO_REPOSITORY=${GITHUB_REPOSITORY}
fi
if [ -z "$PUBLISH_DIR" ]
then
echo "You must provide the action with the folder path in the repository where your compiled page generate at, example public."
exit 1
fi
if [ -z "$BRANCH" ]
then
echo "You must provide the action with a branch name it should deploy to, for example master."
exit 1
fi
if [ -z "$PERSONAL_TOKEN" ]
then
echo "You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy."
exit 1
fi
REPOSITORY_PATH="https://x-access-token:${PERSONAL_TOKEN}@github.com/${PRO_REPOSITORY}.git"
# deploy to
echo "Deploy to ${PRO_REPOSITORY}"
# Directs the action to the the Github workspace.
cd $GITHUB_WORKSPACE
echo "npm install ..."
npm install
echo "Clean folder ..."
./node_modules/hexo/bin/hexo clean
echo "Generate file ..."
./node_modules/hexo/bin/hexo generate
echo "copy CNAME if exists"
if [ -n "${CNAME}" ]; then
echo $CNAME > public
fi
cd $PUBLISH_DIR
echo "Config git ..."
# Configures Git.
git init
git config user.name "${GITHUB_ACTOR}"
git config user.email "${USER_EMAIL}"
git remote add origin "${REPOSITORY_PATH}"
# Checks to see if the remote exists prior to deploying.
# If the branch doesn't exist it gets created here as an orphan.
# if [ "$(git ls-remote --heads "$REPOSITORY_PATH" "$BRANCH" | wc -l)" -eq 0 ];
# then
# echo "Creating remote branch ${BRANCH} as it doesn't exist..."
# git checkout --orphan $BRANCH
# fi
git checkout --orphan $BRANCH
git add --all
echo 'Start Commit'
git commit --allow-empty -m "Deploying to ${BRANCH}"
echo 'Start Push'
git push origin "${BRANCH}" --force
echo "Deployment succesful!"