-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathentrypoint.sh
executable file
·100 lines (81 loc) · 2.9 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
###
# @Author: 付国强
# @Date: 2019-10-28 14:26:56
# @LastEditors: 付国强
# @LastEditTime: 2019-10-28 15:45:22
# @Description:
###
#!/bin/sh -l
set -e
if [ -z "$ACCESS_TOKEN" ] && [ -z "$GITHUB_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
if [ -z "$BRANCH" ]
then
echo "You must provide the action with a branch name it should deploy to, for example gh-pages or docs."
exit 1
fi
if [ -z "$FOLDER" ]
then
echo "You must provide the action with the folder name in the repository where your compiled page lives."
exit 1
fi
case "$FOLDER" in /*|./*)
echo "The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly."
exit 1
esac
# Installs Git and jq.
apt-get update && \
apt-get install -y git && \
apt-get install -y jq && \
# Gets the commit email/name if it exists in the push event payload.
COMMIT_EMAIL=`jq '.pusher.email' ${GITHUB_EVENT_PATH}`
COMMIT_NAME=`jq '.pusher.name' ${GITHUB_EVENT_PATH}`
# If the commit email/name is not found in the event payload then it falls back to the actor.
if [ -z "$COMMIT_EMAIL" ]
then
COMMIT_EMAIL="${GITHUB_ACTOR:-github-pages-deploy-action}@users.noreply.github.com"
fi
if [ -z "$COMMIT_NAME" ]
then
COMMIT_NAME="${GITHUB_ACTOR:-GitHub Pages Deploy Action}"
fi
# Directs the action to the the Github workspace.
cd $GITHUB_WORKSPACE && \
# Configures Git.
git init && \
git config --global user.email "${COMMIT_EMAIL}" && \
git config --global user.name "${COMMIT_NAME}" && \
## Initializes the repository path using the access token.
REPOSITORY_PATH="https://${ACCESS_TOKEN:-"x-access-token:$GITHUB_TOKEN"}@github.com/${GITHUB_REPOSITORY}.git" && \
# 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 "${BASE_BRANCH:-master}" && \
git checkout --orphan $BRANCH && \
git rm -rf . && \
touch README.md && \
git add README.md && \
git commit -m "Initial ${BRANCH} commit" && \
git push $REPOSITORY_PATH $BRANCH
fi
# Checks out the base branch to begin the deploy process.
git checkout "${BASE_BRANCH:-master}" && \
# Builds the project if a build script is provided.
echo "Running build scripts... $BUILD_SCRIPT" && \
eval "$BUILD_SCRIPT" && \
if [ "$CNAME" ]; then
echo "Generating a CNAME file in in the $FOLDER directory..."
echo $CNAME > $FOLDER/CNAME
fi
# Commits the data to Github.
echo "Deploying to GitHub..." && \
cd "./${FOLDER}"
git add -A . && \
git commit -m "Deploying to ${BRANCH} from ${BASE_BRANCH:-master} ${GITHUB_SHA}" --quiet && \
git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER ${BASE_BRANCH:-master}`:$BRANCH --force && \
echo "Deployment succesful!"