-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·156 lines (131 loc) · 4.89 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
set -e
echo "Starting the Jekyll Action"
if [ -n "$INPUT_PRE_BUILD_COMMANDS" ]; then
echo "Execute pre-build commands specified by the user."
eval "$INPUT_PRE_BUILD_COMMANDS"
fi
if [ -z "${INPUT_TOKEN}" ] && [ -n "${JEKYLL_PAT}" ]; then
echo "::warning::The JEKYLL_PAT environment variable is deprecated. Please use the token parameter"
INPUT_TOKEN=${JEKYLL_PAT}
fi
if [ -z "${INPUT_TOKEN}" ] && [ "${INPUT_BUILD_ONLY}" != true ]; then
echo "::error::No token provided. Please set the token parameter."
exit 1
fi
if [ -n "${INPUT_JEKYLL_SRC}" ]; then
JEKYLL_SRC="${INPUT_JEKYLL_SRC}"
echo "::debug::Source directory is set via input parameter"
elif [ -n "${SRC}" ]; then
JEKYLL_SRC=${SRC}
echo "::debug::Source directory is set via SRC environment var"
else
JEKYLL_SRC=$(find . -path '*/vendor/bundle' -prune -o -name '_config.yml' -exec dirname {} \;)
JEKYLL_FILES_COUNT=$(echo "$JEKYLL_SRC" | wc -l)
if [ "$JEKYLL_FILES_COUNT" != "1" ]; then
echo "::error::Found $JEKYLL_FILES_COUNT Jekyll sites from $JEKYLL_SRC! Please define which to use with input variable \"jekyll_src\""
exit 1
fi
JEKYLL_SRC=$(echo $JEKYLL_SRC | tr -d '\n')
echo "::debug::Source directory is found in file system"
fi
echo "::debug::Using \"${JEKYLL_SRC}\" as a source directory"
if [ -n "${INPUT_GEM_SRC}" ]; then
GEM_SRC="${INPUT_GEM_SRC}"
echo "::debug::Gem directory is set via input parameter"
elif [ -f "${JEKYLL_SRC}/Gemfile" ]; then
GEM_SRC="${JEKYLL_SRC}"
echo "::debug::Gem directory is set via source directory"
fi
if [ -z "${GEM_SRC}" ]; then
GEM_SRC=$(find . -path '*/vendor/bundle' -prune -o -name Gemfile -exec dirname {} \;)
GEM_FILES_COUNT=$(echo "$GEM_SRC" | wc -l)
if [ "$GEM_FILES_COUNT" != "1" ]; then
echo "::error::Found $GEM_FILES_COUNT Gemfiles! Please define which to use with input variable \"gem_src\""
echo "$GEM_SRC"
exit 1
fi
GEM_SRC=$(echo $GEM_SRC | tr -d '\n')
echo "::debug::Gem directory is found in file system"
fi
echo "::debug::Using \"${GEM_SRC}\" as Gem directory"
if [ -n "${INPUT_JEKYLL_ENV}" ]; then
echo "::debug::Environment is set via input parameter"
else
echo "::debug::Environment default in use - production"
INPUT_JEKYLL_ENV="production"
fi
if [ -n "${INPUT_TARGET_BRANCH}" ]; then
remote_branch="${INPUT_TARGET_BRANCH}"
echo "::debug::target branch is set via input parameter"
else
response=$(curl -sH "Authorization: token ${INPUT_TOKEN}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pages")
remote_branch=$(echo "$response" | awk -F'"' '/\"branch\"/ { print $4 }')
if [ -z "${remote_branch}" ]; then
echo "::error::Cannot get GitHub Pages source branch via API."
echo "::error::${response}"
exit 1
fi
fi
REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
echo "::debug::Remote is ${REMOTE_REPO}"
BUILD_DIR="${GITHUB_WORKSPACE}/../jekyll_build"
echo "::debug::Build dir is ${BUILD_DIR}"
mkdir -p $BUILD_DIR # Original: mkdir $BUILD_DIR
cd $BUILD_DIR
if [ -n "${INPUT_TARGET_PATH}" ] && [ "${INPUT_TARGET_PATH}" != '/' ]; then
TARGET_DIR="${BUILD_DIR}/${INPUT_TARGET_PATH}"
echo "::debug::target path is set to ${INPUT_TARGET_PATH}"
else
TARGET_DIR=$BUILD_DIR
fi
if [ "${INPUT_KEEP_HISTORY}" = true ]; then
echo "::debug::Cloning ${remote_branch} from repo ${REMOTE_REPO}"
git clone --branch $remote_branch $REMOTE_REPO .
LOCAL_BRANCH=$remote_branch
PUSH_OPTIONS=""
COMMIT_OPTIONS="--allow-empty"
else
echo "::debug::Initializing new repo"
LOCAL_BRANCH="main"
git init -b $LOCAL_BRANCH
PUSH_OPTIONS="--force"
COMMIT_OPTIONS=""
fi
echo "::debug::Local branch is ${LOCAL_BRANCH}"
cd "${GITHUB_WORKSPACE}/${GEM_SRC}"
echo "::debug::ChangeDir to ${GITHUB_WORKSPACE}/${GEM_SRC}" # ADDED!!
bundle config path "$PWD/vendor/bundle"
echo "::debug::Bundle config set succesfully"
bundle install
echo "::debug::Completed bundle install"
VERBOSE=""
if [ "${JEKYLL_DEBUG}" = true ]; then
# Activating debug for Jekyll
echo "::debug::Jekyll debug is on"
VERBOSE="--verbose"
else
echo "::debug::Jekyll debug is off"
fi
JEKYLL_ENV=${INPUT_JEKYLL_ENV} bundle exec ${BUNDLE_ARGS} jekyll build -s ${GITHUB_WORKSPACE}/${JEKYLL_SRC} -d ${TARGET_DIR} ${INPUT_JEKYLL_BUILD_OPTIONS} ${VERBOSE}
echo "Jekyll build done"
if [ "${INPUT_BUILD_ONLY}" = true ]; then
exit $?
fi
if [ "${GITHUB_REF}" = "refs/heads/${remote_branch}" ]; then
echo "::error::Cannot publish on branch ${remote_branch}"
exit 1
fi
cd ${BUILD_DIR}
# No need to have GitHub Pages to run Jekyll
touch .nojekyll
echo "Publishing to ${GITHUB_REPOSITORY} on branch ${remote_branch}"
git config user.name "${GITHUB_ACTOR}" && \
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" && \
git add . && \
git commit $COMMIT_OPTIONS -m "jekyll build from Action ${GITHUB_SHA}" && \
git push $PUSH_OPTIONS $REMOTE_REPO $LOCAL_BRANCH:$remote_branch && \
rm -fr .git && \
cd ..
exit $?