-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
164 lines (153 loc) · 4.87 KB
/
build.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
157
158
159
160
161
162
163
164
#!/bin/bash
# This script build a Cecil website (locally, on Netlify / Vercel / Cloudflare Pages / Render).
# It is intended to be used on CI / CD.
# Requirements
export PHP_MIN_VERSION="8.1"
# Specify the PHP version with `PHP_VERSION`
if [ -z "${PHP_VERSION}" ]; then
export PHP_VERSION="8.1"
fi
# Specify Cecil CLI options with `CECIL_CMD_OPTIONS` (e.g.: `--optimize`)
if [ -z "${CECIL_CMD_OPTIONS}" ]; then
export CECIL_CMD_OPTIONS=""
fi
# Enable installation of images optimization libraries on Vercel
if [ -z "${VERCEL_INSTALL_OPTIM}" ]; then
export VERCEL_INSTALL_OPTIM="false"
fi
# Running on?
RUNNING_ON="unknown"
URL=""
if [ "$NETLIFY" = "true" ]; then
RUNNING_ON="Netlify"
fi
if [ "$VERCEL" = "1" ]; then
RUNNING_ON="Vercel"
fi
if [ "$CF_PAGES" = "1" ]; then
RUNNING_ON="CFPages"
fi
if [ "$RENDER" = "true" ]; then
RUNNING_ON="Render"
fi
echo "Running on ${RUNNING_ON}"
case $RUNNING_ON in
"Netlify")
if [ "$CONTEXT" = "production" ]; then
URL=$URL
else
URL=$DEPLOY_PRIME_URL
fi
;;
"Vercel")
echo "Installing PHP ${PHP_VERSION}..."
amazon-linux-extras install -y php$PHP_VERSION
echo "Installing Gettext..."
yum install -y gettext
echo "Installing Sodium..."
yum install -y libsodium # required by Box
echo "Installing PHP extensions..."
yum install -y php-{cli,mbstring,dom,xml,intl,gettext,gd,imagick,sodium}
if [ "$VERCEL_INSTALL_OPTIM" = "true" ]; then
echo "Installing images optimization libraries..."
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y jpegoptim
yum install -y pngquant
yum install -y gifsicle
yum install -y libwebp-tools
fi
if [ "$VERCEL_ENV" = "production" ]; then
CONTEXT="production"
else
URL="https://$VERCEL_URL" # see https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables
fi
;;
"CFPages")
if [ "$CF_PAGES_BRANCH" = "master" ] || [ "$CF_PAGES_BRANCH" = "main" ]; then
CONTEXT="production"
else
URL=$CF_PAGES_URL
fi
;;
"Render")
CONTEXT="production"
URL=$RENDER_EXTERNAL_URL
if [ "$IS_PULL_REQUEST" = "true" ]; then
CONTEXT="preview"
fi
;;
esac
# Checks PHP version
php --version > /dev/null 2>&1
PHP_IS_INSTALLED=$?
if [ $PHP_IS_INSTALLED -ne 0 ]; then
echo "PHP is not installed. Please install PHP ${PHP_MIN_VERSION} or higher before running this script."
exit 1;
else
php -r 'echo "PHP " . PHP_VERSION . " is available." . PHP_EOL;'
fi
PHP_OK=$(php -r 'echo (bool) version_compare(phpversion(), getenv("PHP_MIN_VERSION"), ">=");')
if [ "$PHP_OK" != "1" ]; then
echo "PHP version is not compatible. Please install PHP ${PHP_MIN_VERSION} or higher."
exit 1;
fi
# Download Cecil if needed
cecil --version > /dev/null 2>&1
CECIL_IS_INSTALLED=$?
CECIL_CMD="cecil"
if [ $CECIL_IS_INSTALLED -ne 0 ]; then
if [ -z $CECIL_VERSION ]; then
echo "Downloading Cecil..."
curl -sSOL https://cecil.app/cecil.phar
else
echo "Downloading Cecil ${CECIL_VERSION}..."
if [ $(curl -LI https://cecil.app/download/$CECIL_VERSION/cecil.phar -o /dev/null -w '%{http_code}\n' -s) == '200' ]; then
curl -sSOL https://cecil.app/download/$CECIL_VERSION/cecil.phar
else
echo "Can't download Cecil $CECIL_VERSION from Cecil.app. Trying from GitHub's release.";
if [ $(curl -LI https://github.com/Cecilapp/Cecil/releases/download/$CECIL_VERSION/cecil.phar -o /dev/null -w '%{http_code}\n' -s) != '200' ]; then
echo "Can't download Cecil $CECIL_VERSION from GitHub"; exit 1
fi
curl -sSOL https://github.com/Cecilapp/Cecil/releases/download/$CECIL_VERSION/cecil.phar
fi
fi
CECIL_CMD="php cecil.phar"
echo "$($CECIL_CMD --version) is available."
else
echo "$($CECIL_CMD --version) is available."
fi
# Installs Cecil components if needed
if [ -f "./composer.json" ]; then
composer --version > /dev/null 2>&1
COMPOSER_IS_INSTALLED=$?
COMPOSER_CMD="composer"
if [ $COMPOSER_IS_INSTALLED -ne 0 ]; then
echo "Composer is required. Downloading..."
curl -sS https://getcomposer.org/installer | php
COMPOSER_CMD="php composer.phar"
else
echo "$($COMPOSER_CMD --version) is available."
fi
echo "Installing themes..."
$COMPOSER_CMD install --prefer-dist --no-dev --no-progress --no-interaction --quiet
fi
# Adds CLI options
if [ ! -z "${URL}" ]; then
CECIL_CMD_OPTIONS="--baseurl=${URL} ${CECIL_CMD_OPTIONS}"
fi
if [ "$CONTEXT" = "production" ]; then
export CECIL_ENV="production"
CECIL_CMD_OPTIONS="-v ${CECIL_CMD_OPTIONS}"
else
CECIL_CMD_OPTIONS="-vv ${CECIL_CMD_OPTIONS}"
fi
# Run build
CECIL_CMD_OPTIONS="${CECIL_CMD_OPTIONS%[[:space:]]}"
echo "Running \"${CECIL_CMD} build ${CECIL_CMD_OPTIONS}\"";
$CECIL_CMD build $CECIL_CMD_OPTIONS
BUILD_SUCCESS=$?
# Build success? Can deploy?
if [ $BUILD_SUCCESS -ne 0 ]; then
echo "Build fail."; exit 1
fi
exit 0