-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentrypoint.sh
More file actions
71 lines (60 loc) · 1.89 KB
/
entrypoint.sh
File metadata and controls
71 lines (60 loc) · 1.89 KB
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
#!/bin/bash
set -x
set -e
GITHUB_EMAIL=${GITHUB_EMAIL:-"me@xiexianbin.cn"}
GITHUB_USERNAME=${GITHUB_USERNAME:-"xiexianbin"}
PUBLISH_REPO=${PUBLISH_REPO:-}
PUBLISH_BRANCH=${PUBLISH_BRANCH:-}
PUBLISH_DIR="${PUBLISH_DIR:-}"
DEPLOY_PRIVATE_KEY=${DEPLOY_PRIVATE_KEY:-}
CNAME=${CNAME:-}
echo "## Check Package Version ##################"
bash --version
git version
git lfs version
echo "## Init Git Config ##################"
if ! git config --get user.name; then
git config --global user.name "${GITHUB_USERNAME}"
fi
if ! git config --get user.email; then
git config --global user.email "${GITHUB_EMAIL}"
fi
git config --global --add safe.directory /github/workspace/${PUBLISH_DIR}
echo "## Setup Deploy keys ##################"
mkdir /root/.ssh && \
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
if [ X"$DEPLOY_PRIVATE_KEY" = X"" ]; then
echo "## Skip ssh key deploy ##################"
else
echo ${DEPLOY_PRIVATE_KEY} > /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa && \
ls -lhart /root/.ssh/id_rsa && \
cat /root/.ssh/id_rsa
fi
echo "## Push to Github ##################"
rm -rf .git
cd ${PUBLISH_DIR}
if [[ -n "${CNAME}" ]]; then
echo 'Creating CNAME file'
echo "${CNAME}" > CNAME
fi
if [ ! -d ".git" ];then
git init
touch README.md
git add README.md
git commit -m "init README.md at $(date "+%Y-%m-%d %T") - by github actions"
else
git remote -v
git remote rm origin || true
fi
git remote add origin "${PUBLISH_REPO}"
git remote -v
git branch | grep ${PUBLISH_BRANCH} || git checkout ${PUBLISH_BRANCH} || git branch ${PUBLISH_BRANCH} && git checkout ${PUBLISH_BRANCH}
git add . && \
git commit -m "update at $(date "+%Y-%m-%d %T") - by github actions"
git push --set-upstream origin ${PUBLISH_BRANCH} --force -vvv
if [ $? -ne 0 ]; then
git pull --rebase origin ${PUBLISH_BRANCH}
git push --set-upstream origin ${PUBLISH_BRANCH} --force -vvv
fi
echo "## Done. ##################"