forked from gradientiiits/hugo-remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.sh
executable file
·57 lines (46 loc) · 1.38 KB
/
action.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
#!/bin/bash
set -v
# Fail if variables are unset
set -eu -o pipefail
echo '🔧 Install tools'
npm init -y && npm install -y postcss-cli autoprefixer
echo '🤵 Install Hugo'
HUGO_VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.tag_name')
mkdir tmp/ && cd tmp/
curl -sSL https://github.com/gohugoio/hugo/releases/download/${HUGO_VERSION}/hugo_extended_${HUGO_VERSION: -6}_Linux-64bit.tar.gz | tar -xvzf-
mv hugo /usr/local/bin/
cd .. && rm -rf tmp/
cd ${GITHUB_WORKSPACE}
cd ${BUILD_DIR}
hugo version || exit 1
echo '👯 Clone remote repository'
git clone https://github.com/${REMOTE} ${DEST} --branch main
echo '🧹 Clean site'
if [ -d "${DEST}" ]; then
rm -rf ${DEST}/*
fi
echo '🍳 Build site'
hugo -d ${DEST} ${ARGS}
set +eu
if [[ ! -z "${CNAME}" ]]; then
if [[ ! -f "${DEST}/CNAME" ]]; then
exit 1
fi
if [[ ! "${CNAME}" == "$(cat ${DEST}/CNAME)" ]]; then
exit 1
fi
fi
set -eu
echo '🎁 Publish to remote repository'
cd ${DEST}
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -am "🚀 Deploy with ${GITHUB_WORKFLOW}"
git remote add publisher "https://${USER}:${TOKEN}@github.com/${REMOTE}"
git remote -v
git push -fq publisher main
else
echo 'No changes to build :)'
fi