-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
entrypoint.sh
executable file
·99 lines (80 loc) · 2.5 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
#!/bin/bash
set -e
# Get script directory
SCRIPT_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
WORKING_DIR=${PWD}
# Initial default value
PROVIDER=${INPUT_PROVIDER:=github}
TOKEN=${INPUT_TOKEN}
ACTOR=${INPUT_ACTOR}
REPOSITORY=${INPUT_REPOSITORY}
BRANCH=${INPUT_BRANCH}
BUNDLER_VER=${INPUT_BUNDLER_VER:=>=0}
JEKYLL_SRC=${INPUT_JEKYLL_SRC:=./}
JEKYLL_CFG=${INPUT_JEKYLL_CFG:=./_config.yml}
JEKYLL_BASEURL=${INPUT_JEKYLL_BASEURL:=}
PRE_BUILD_COMMANDS=${INPUT_PRE_BUILD_COMMANDS:=}
# Set default bundle path and cache
BUNDLE_PATH=${WORKING_DIR}/vendor/bundle
echo "Starting the Jekyll Deploy Action"
if [ -z "${TOKEN}" ]; then
echo "Please set the TOKEN environment variable."
exit 1
fi
# Check parameters and assign default values
if [[ "${PROVIDER}" == "github" ]]; then
: ${ACTOR:=${GITHUB_ACTOR}}
: ${REPOSITORY:=${GITHUB_REPOSITORY}}
: ${BRANCH:=gh-pages}
# Check if repository is available
if ! echo "${REPOSITORY}" | grep -Eq ".+/.+"; then
echo "The repository ${REPOSITORY} doesn't match the pattern <author>/<repos>"
exit 1
fi
fi
# Initialize environment
echo "Initialize environment"
${SCRIPT_DIR}/script/init_environment.sh
cd ${JEKYLL_SRC}
# Check and execute pre_build_commands commands
if [[ ${PRE_BUILD_COMMANDS} ]]; then
echo "Executing pre-build commands"
eval "${PRE_BUILD_COMMANDS}"
fi
echo "Initial comptible bundler"
${SCRIPT_DIR}/script/cleanup_bundler.sh
gem install bundler -v "${BUNDLER_VER}"
# If the vendor/bundle folder is cached in a differnt OS (e.g. Ubuntu),
# it would cause `jekyll build` failed, we should clean up the uncompatible
# cache firstly.
OS_NAME_FILE=${BUNDLE_PATH}/os-name
os_name=$(cat /etc/os-release | grep '^NAME=')
os_name=${os_name:6:-1}
if [ "$os_name" != "$(cat $OS_NAME_FILE 2>/dev/null)" ]; then
echo "Cleaning up incompatible bundler cache"
rm -rf ${BUNDLE_PATH}
mkdir -p ${BUNDLE_PATH}
echo $os_name > $OS_NAME_FILE
fi
echo "Starting bundle install"
bundle config cach_all true
bundle config path ${WORKING_DIR}/vendor/bundle
bundle install
# Pre-handle Jekyll baseurl
if [ -n "${JEKYLL_BASEURL-}" ]; then
JEKYLL_BASEURL="--baseurl ${JEKYLL_BASEURL}"
fi
echo "Starting jekyll build"
JEKYLL_ENV=production bundle exec jekyll build \
${JEKYLL_BASEURL} \
-c ${JEKYLL_CFG} \
-d ${WORKING_DIR}/build
cd ${WORKING_DIR}/build
# Check if deploy on the same repository branch
if [[ "${PROVIDER}" == "github" ]]; then
source "${SCRIPT_DIR}/providers/github.sh"
else
echo "${PROVIDER} is an unsupported provider."
exit 1
fi
exit $?