forked from theme-keep/hexo-deploy-github-pages-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
91 lines (65 loc) · 2.12 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
#!/bin/sh -l
set -e
# check values
if [ -n "${PUBLISH_REPOSITORY}" ]; then
TARGET_REPOSITORY=${PUBLISH_REPOSITORY}
else
TARGET_REPOSITORY=${GITHUB_REPOSITORY}
fi
if [ -n "${BRANCH}" ]; then
TARGET_BRANCH=${BRANCH}
else
TARGET_BRANCH="gh-pages"
fi
if [ -n "${PUBLISH_DIR}" ]; then
TARGET_PUBLISH_DIR=${PUBLISH_DIR}
else
TARGET_PUBLISH_DIR="./public"
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/${TARGET_REPOSITORY}.git"
# start deploy
echo ">>>>> Start deploy to ${TARGET_REPOSITORY} <<<<<"
# Installs Git.
echo ">>> Install Git ..."
apt-get update && \
apt-get install -y git && \
# Directs the action to the the Github workspace.
cd "${GITHUB_WORKSPACE}"
echo ">>> Install NPM dependencies ..."
npm uninstall hexo-generator-index --save
npm install hexo-generator-index-pin-top --save
npm install hexo-renderer-pug hexo-renderer-stylus hexo-wordcount hexo-helper-live2d live2d-widget-model-koharu --save
npm install hexo-generator-sitemap --save
npm install hexo-baidu-url-submit --save
npm install
echo ">>> Clean cache files ..."
npx hexo clean
echo ">>> Generate file ..."
npx hexo generate
cd "${TARGET_PUBLISH_DIR}"
# Configures Git.
echo ">>> Config git ..."
CURRENT_DIR=$(pwd)
git init
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global --add safe.directory "${CURRENT_DIR}"
git remote add origin "${REPOSITORY_PATH}"
git checkout --orphan "${TARGET_BRANCH}"
if [ -n "${CNAME}" ]; then
echo ${CNAME} > CNAME
fi
mkdir -p .github/workflows && cd .github/workflows
wget https://github.com/LostPear/lostpear.github.io/raw/main/.github/workflows/azure-static-web-apps-witty-wave-04fbfe900.yml
cd ../../
git add .
echo '>>> Start Commit ...'
git commit --allow-empty -m "Building and deploying Hexo project from Github Action"
echo '>>> Start Push ...'
git push -u origin "${TARGET_BRANCH}" --force
echo ">>> Deployment successful!"