-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
entrypoint.sh
executable file
·76 lines (58 loc) · 1.54 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
#!/bin/bash
set -e
echo ''
# env
echo "node version: $(node -v)"
echo "npm version: $(npm -v)"
# Build vuepress project
echo "==> Start building \n $BUILD_SCRIPT"
eval "$BUILD_SCRIPT"
echo "Build success"
# Change directory to the dest
echo "==> Changing directory to '$BUILD_DIR' ..."
cd $BUILD_DIR
# workaround for 'fatal: unsafe repository' error
git config --global --add safe.directory "*"
# Get respository
if [[ -z "$TARGET_REPO" ]]; then
REPOSITORY_NAME="${GITHUB_REPOSITORY}"
else
REPOSITORY_NAME="$TARGET_REPO"
fi
# Get branch
if [[ -z "$TARGET_BRANCH" ]]; then
DEPLOY_BRAN="gh-pages"
else
DEPLOY_BRAN="$TARGET_BRANCH"
fi
# Final repository
DEPLOY_REPO="https://username:${ACCESS_TOKEN}@github.com/${REPOSITORY_NAME}.git"
if [ "$TARGET_LINK" ]; then
DEPLOY_REPO="$TARGET_LINK"
fi
echo "==> Prepare to deploy"
git init
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
if [ -z "$(git status --porcelain)" ]; then
echo "The BUILD_DIR is setting error or nothing produced" && \
echo "Exiting..."
exit 0
fi
# Generate a CNAME file
if [ "$CNAME" ]; then
echo "Generating a CNAME file..."
echo $CNAME > CNAME
fi
echo "==> Starting deploying"
# Final repository
if [[ -z "$COMMIT_MESSAGE" ]]; then
COMMIT_MESSAGE="Auto deploy from Github Actions"
fi
git add .
git commit -m "$COMMIT_MESSAGE"
git push --force $DEPLOY_REPO master:$DEPLOY_BRAN
rm -fr .git
cd $GITHUB_WORKSPACE
echo "Successfully deployed!" && \
echo "See: https://github.com/$REPOSITORY_NAME/tree/$DEPLOY_BRAN"