-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
entrypoint.sh
executable file
·108 lines (82 loc) · 2.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
set -e
set -o pipefail
# For backwards compatibility
if [[ -n "$TOKEN" ]]; then
GITHUB_TOKEN=$TOKEN
fi
if [[ -z "$PAGES_BRANCH" ]]; then
PAGES_BRANCH="gh-pages"
fi
if [[ -z "$BUILD_DIR" ]]; then
BUILD_DIR="."
fi
if [[ -z "$OUT_DIR" ]]; then
OUT_DIR="public"
fi
if [[ -n "$REPOSITORY" ]]; then
TARGET_REPOSITORY=$REPOSITORY
else
if [[ -z "$GITHUB_REPOSITORY" ]]; then
echo "Set the GITHUB_REPOSITORY env variable."
exit 1
fi
TARGET_REPOSITORY=${GITHUB_REPOSITORY}
fi
if [[ -z "$BUILD_ONLY" ]]; then
BUILD_ONLY=false
fi
if [[ -z "$BUILD_THEMES" ]]; then
BUILD_THEMES=true
fi
if [[ -z "$CHECK_LINKS" ]]; then
CHECK_LINKS=false
fi
if [[ -z "$GITHUB_TOKEN" ]] && [[ "$BUILD_ONLY" == false ]]; then
echo "Set the GITHUB_TOKEN or TOKEN env variables."
exit 1
fi
if [[ -z "$GITHUB_HOSTNAME" ]]; then
GITHUB_HOSTNAME="github.com"
fi
main() {
echo "Starting deploy..."
echo "Building in $BUILD_DIR directory"
cd "$BUILD_DIR"
git config --global url."https://".insteadOf git://
## $GITHUB_SERVER_URL is set as a default environment variable in all workflows, default is https://github.com
git config --global url."$GITHUB_SERVER_URL/".insteadOf "git@${GITHUB_HOSTNAME}":
# needed or else we get 'doubious ...' error
echo "Disable safe directory check"
git config --global --add safe.directory '*'
if ${BUILD_THEMES}; then
echo "Fetching themes"
git submodule update --init --recursive
fi
version=$(zola --version)
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${GITHUB_HOSTNAME}/${TARGET_REPOSITORY}.git"
remote_branch=$PAGES_BRANCH
echo "Using $version"
echo Building with flags: ${BUILD_FLAGS:+"$BUILD_FLAGS"}
zola build ${BUILD_FLAGS:+$BUILD_FLAGS}
if ${CHECK_LINKS}; then
echo "Checking links with flags: ${CHECK_FLAGS:+$CHECK_FLAGS}"
zola check ${CHECK_FLAGS:+$CHECK_FLAGS}
fi
if ${BUILD_ONLY}; then
echo "Build complete. Deployment skipped by request"
exit 0
else
echo "Pushing artifacts to ${TARGET_REPOSITORY}:$remote_branch"
cd "${OUT_DIR}"
touch .nojekyll
git init
git config user.name "GitHub Actions"
git config user.email "github-actions-bot@users.noreply.${GITHUB_HOSTNAME}"
git add .
git commit -m "Deploy ${TARGET_REPOSITORY} to ${TARGET_REPOSITORY}:$remote_branch"
git push --force "${remote_repo}" master:"${remote_branch}"
echo "Deploy complete"
fi
}
main "$@"