Skip to content

Commit a8633f5

Browse files
committed
Merge branch '1.x' into feature/add-bats-test-ahoy-operation
2 parents 635fa86 + d0709ff commit a8633f5

File tree

6 files changed

+148
-44
lines changed

6 files changed

+148
-44
lines changed

.ahoy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ commands:
88
build:
99
usage: Build or rebuild the project.
1010
cmd: |
11+
ahoy stop > /dev/null 2>&1 || true
1112
ahoy assemble
1213
ahoy start
1314
ahoy provision
@@ -20,6 +21,10 @@ commands:
2021
usage: Start development environment.
2122
cmd: ./.devtools/start.sh
2223

24+
stop:
25+
usage: Stop development environment.
26+
cmd: ./.devtools/stop.sh
27+
2328
provision:
2429
usage: Provision application within assembled codebase.
2530
cmd: ./.devtools/provision.sh

.devtools/assemble.sh

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ DRUPAL_PROJECT_REPO="${DRUPAL_PROJECT_REPO:-https://github.com/drupal-composer/d
3737

3838
#-------------------------------------------------------------------------------
3939

40+
# @formatter:off
41+
note() { printf " %s\n" "${1}"; }
42+
info() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[34m[INFO] %s\033[0m\n" "${1}" || printf "[INFO] %s\n" "${1}"; }
43+
pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[32m[ OK ] %s\033[0m\n" "${1}" || printf "[ OK ] %s\n" "${1}"; }
44+
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
45+
# @formatter:on
46+
47+
#-------------------------------------------------------------------------------
48+
4049
echo "==============================="
4150
echo " 🏗️ ASSEMBLE "
4251
echo "==============================="
@@ -45,11 +54,12 @@ echo
4554
# Make sure Composer doesn't run out of memory.
4655
export COMPOSER_MEMORY_LIMIT=-1
4756

48-
echo "> Validate tools."
57+
info "Validate tools."
4958
! command -v git >/dev/null && echo "ERROR: Git is required for this script to run." && exit 1
5059
! command -v php >/dev/null && echo "ERROR: PHP is required for this script to run." && exit 1
5160
! command -v composer >/dev/null && echo "ERROR: Composer (https://getcomposer.org/) is required for this script to run." && exit 1
5261
! command -v jq >/dev/null && echo "ERROR: jq (https://stedolan.github.io/jq/) is required for this script to run." && exit 1
62+
pass "Tools are valid."
5363

5464
# Extension name, taken from the .info file.
5565
extension="$(basename -s .info.yml -- ./*.info.yml)"
@@ -58,77 +68,95 @@ extension="$(basename -s .info.yml -- ./*.info.yml)"
5868
# Extension type.
5969
type=$(grep -q "type: theme" "${extension}.info.yml" && echo "themes" || echo "modules")
6070

61-
echo "> Validate Composer configuration."
71+
info "Validate Composer configuration."
6272
composer validate --ansi --strict
6373

6474
# Reset the environment.
65-
[ -d "build" ] && echo "> Remove existing build directory." && chmod -Rf 777 "build" && rm -rf "build"
75+
if [ -d "build" ]; then
76+
info "Removing existing build directory."
77+
chmod -Rf 777 "build" >/dev/null || true
78+
rm -rf "build" >/dev/null || true
79+
pass "Existing build directory removed."
80+
fi
6681

82+
info "Creating Drupal codebase."
6783
# Allow installing custom version of Drupal core from drupal-composer/drupal-project,
6884
# but only coupled with drupal-project SHA (required to get correct dependencies).
6985
if [ -n "${DRUPAL_VERSION:-}" ] && [ -n "${DRUPAL_PROJECT_SHA:-}" ]; then
70-
echo "> Initialise Drupal site from the scaffold repo ${DRUPAL_PROJECT_REPO} commit ${DRUPAL_PROJECT_SHA}."
86+
note "Initialising Drupal site from the scaffold repo ${DRUPAL_PROJECT_REPO} commit ${DRUPAL_PROJECT_SHA}."
7187

7288
# Clone Drupal core at the specific commit SHA.
7389
git clone -n "${DRUPAL_PROJECT_REPO}" "build"
7490
git --git-dir="build/.git" --work-tree="build" checkout "${DRUPAL_PROJECT_SHA}"
7591
rm -rf "build/.git" >/dev/null
7692

77-
echo "> Pin Drupal to a specific version ${DRUPAL_VERSION}."
93+
note "Pin Drupal to a specific version ${DRUPAL_VERSION}."
7894
sed_opts=(-i) && [ "$(uname)" == "Darwin" ] && sed_opts=(-i '')
7995
sed "${sed_opts[@]}" 's|\(.*"drupal\/core"\): "\(.*\)",.*|\1: '"\"$DRUPAL_VERSION\",|" "build/composer.json"
8096
cat "build/composer.json"
8197
else
82-
echo "> Initialise Drupal site from the latest scaffold."
98+
note "Initialising Drupal site from the latest scaffold."
8399
# There are no releases in "drupal-composer/drupal-project", so have to use "@dev".
84100
composer create-project drupal-composer/drupal-project:@dev "build" --no-interaction --no-install
85101
fi
102+
pass "Drupal codebase created."
86103

87-
echo "> Merge configuration from composer.dev.json."
104+
info "Merging configuration from composer.dev.json."
88105
php -r "echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.dev.json'), true),json_decode(file_get_contents('build/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" >"build/composer2.json" && mv -f "build/composer2.json" "build/composer.json"
89106

90-
echo "> Merge configuration from extension's composer.json."
107+
info "Merging configuration from extension's composer.json."
91108
php -r "echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.json'), true),json_decode(file_get_contents('build/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" >"build/composer2.json" && mv -f "build/composer2.json" "build/composer.json"
92109

93-
echo "> Create GitHub authentication token if provided."
94-
[ -n "${GITHUB_TOKEN:-}" ] && composer config --global github-oauth.github.com "${GITHUB_TOKEN}" && echo "Token: " && composer config --global github-oauth.github.com
110+
if [ -n "${GITHUB_TOKEN:-}" ]; then
111+
info "Adding GitHub authentication token if provided."
112+
composer config --global github-oauth.github.com "${GITHUB_TOKEN}"
113+
composer config --global github-oauth.github.com | grep -q "gh" || fail "GitHub token not added."
114+
pass "GitHub token added."
115+
fi
95116

96-
echo "> Create custom directories."
117+
info "Creating custom directories."
97118
mkdir -p build/web/modules/custom build/web/themes/custom
98119

99-
echo "> Install dependencies."
120+
info "Installing dependencies."
100121
composer --working-dir="build" install
122+
pass "Dependencies installed."
101123

102124
# Suggested dependencies allow to install them for testing without requiring
103125
# them in extension's composer.json.
104-
echo "> Install suggested dependencies from extension's composer.json."
126+
info "Installing suggested dependencies from extension's composer.json."
105127
composer_suggests=$(cat composer.json | jq -r 'select(.suggest != null) | .suggest | keys[]')
106128
for composer_suggest in $composer_suggests; do
107129
composer --working-dir="build" require "${composer_suggest}"
108130
done
131+
pass "Suggested dependencies installed."
109132

110-
echo "> Copy tools configuration files."
133+
info "Copying tools configuration files."
111134
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig-cs-fixer.php phpunit.xml "build/"
135+
pass "Tools configuration files copied."
112136

113-
echo "> Symlink extension's code."
137+
info "Symlinking extension's code."
114138
rm -rf "build/web/${type}/custom" >/dev/null && mkdir -p "build/web/${type}/custom/${extension}"
115139
ln -s "$(pwd)"/* "build/web/${type}/custom/${extension}" && rm "build/web/${type}/custom/${extension}/build"
140+
pass "Extension's code symlinked."
116141

117142
# If front-end dependencies are used in the project, package-lock.json is
118143
# expected to be committed to the repository.
119144
if [ -f "build/web/${type}/custom/${extension}/package-lock.json" ]; then
120145
pushd "build/web/${type}/custom/${extension}" >/dev/null || exit 1
121-
echo "> Install front-end dependencies."
146+
147+
info "Installing front-end dependencies."
122148
if [ -f ".nvmrc" ]; then nvm use; fi
123149
if [ ! -d "node_modules" ]; then npm ci; fi
124150
echo "> Build front-end dependencies."
125151
npm run build
152+
pass "Front-end dependencies installed."
153+
126154
popd >/dev/null || exit 1
127155
fi
128156

129157
echo
130158
echo "==============================="
131-
echo " 🏗 ASSEMBLE COMPLETE "
159+
echo " 🏗 ASSEMBLE COMPLETE "
132160
echo "==============================="
133161
echo
134162
echo "> Next steps:"

.devtools/deploy.sh

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ DEPLOY_SSH_KEY_FINGERPRINT="${DEPLOY_SSH_KEY_FINGERPRINT:-}"
3939

4040
#-------------------------------------------------------------------------------
4141

42+
# @formatter:off
43+
note() { printf " %s\n" "${1}"; }
44+
info() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[34m[INFO] %s\033[0m\n" "${1}" || printf "[INFO] %s\n" "${1}"; }
45+
pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[32m[ OK ] %s\033[0m\n" "${1}" || printf "[ OK ] %s\n" "${1}"; }
46+
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
47+
# @formatter:on
48+
49+
#-------------------------------------------------------------------------------
50+
4251
if [ -n "${DEPLOY_SSH_KEY_FINGERPRINT}" ]; then
4352
echo "-------------------------------"
4453
echo " Setup SSH "
@@ -63,7 +72,7 @@ if [ -n "${DEPLOY_SSH_KEY_FINGERPRINT}" ]; then
6372
file="${HOME}/.ssh/id_rsa_${file//\"/}"
6473

6574
if [ ! -f "${file:-}" ]; then
66-
echo "ERROR: Unable to find SSH key file ${file}."
75+
fail "ERROR: Unable to find SSH key file ${file}."
6776
exit 1
6877
fi
6978

@@ -81,34 +90,35 @@ echo " 🚚 DEPLOY "
8190
echo "==============================="
8291
echo
8392

84-
[ -z "${DEPLOY_USER_NAME}" ] && echo "ERROR: Missing required value for DEPLOY_USER_NAME" && exit 1
85-
[ -z "${DEPLOY_USER_EMAIL}" ] && echo "ERROR: Missing required value for DEPLOY_USER_EMAIL" && exit 1
86-
[ -z "${DEPLOY_REMOTE}" ] && echo "ERROR: Missing required value for DEPLOY_REMOTE" && exit 1
93+
[ -z "${DEPLOY_USER_NAME}" ] && fail "ERROR: Missing required value for DEPLOY_USER_NAME" && exit 1
94+
[ -z "${DEPLOY_USER_EMAIL}" ] && fail "ERROR: Missing required value for DEPLOY_USER_EMAIL" && exit 1
95+
[ -z "${DEPLOY_REMOTE}" ] && fail "ERROR: Missing required value for DEPLOY_REMOTE" && exit 1
8796

88-
[ "${DEPLOY_PROCEED}" != "1" ] && echo "> Skip deployment because $DEPLOY_PROCEED is not set to 1" && exit 0
97+
[ "${DEPLOY_PROCEED}" != "1" ] && pass "Skip deployment because $DEPLOY_PROCEED is not set to 1" && exit 0
8998

90-
echo "> Configure git user name and email, but only if not already set."
91-
[ "$(git config --global user.name)" == "" ] && echo "> Configure global git user name ${DEPLOY_USER_NAME}." && git config --global user.name "${DEPLOY_USER_NAME}"
92-
[ "$(git config --global user.email)" == "" ] && echo "> Configure global git user email ${DEPLOY_USER_EMAIL}." && git config --global user.email "${DEPLOY_USER_EMAIL}"
99+
[ "$(git config --global user.name)" == "" ] && note "Configuring global git user name ${DEPLOY_USER_NAME}." && git config --global user.name "${DEPLOY_USER_NAME}"
100+
[ "$(git config --global user.email)" == "" ] && note "Configuring global git user email ${DEPLOY_USER_EMAIL}." && git config --global user.email "${DEPLOY_USER_EMAIL}"
93101

94-
echo "> Set git to push to a matching remote branch."
102+
note "Setting git to push to a matching remote branch."
95103
git config --global push.default matching
96104

97-
echo "> Add remote ${DEPLOY_REMOTE}."
105+
note "> Adding remote ${DEPLOY_REMOTE}."
98106
git remote add deployremote "${DEPLOY_REMOTE}"
99107

100108
if [ -z "${DEPLOY_BRANCH}" ]; then
101109
DEPLOY_BRANCH="$(git symbolic-ref --short HEAD)"
102110
fi
103111

104-
echo "> Push code to branch ${DEPLOY_BRANCH}."
112+
info "Pushing code to branch ${DEPLOY_BRANCH}."
105113
git push --force deployremote HEAD:"${DEPLOY_BRANCH}"
114+
pass "Code pushed to ${DEPLOY_REMOTE}:${DEPLOY_BRANCH}."
106115

107-
echo "> Push tags."
116+
info "Pushing tags."
108117
git push --force --tags deployremote || true
118+
pass "Tags pushed to ${DEPLOY_REMOTE}."
109119

110120
echo "==============================="
111-
echo " 🚚 DEPLOY COMPLETE "
121+
echo " 🚚 DEPLOY COMPLETE "
112122
echo "==============================="
113123
echo
114124
echo "Remote URL : ${DEPLOY_REMOTE}"

.devtools/provision.sh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,25 @@ DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}"
2626

2727
#-------------------------------------------------------------------------------
2828

29+
# @formatter:off
30+
note() { printf " %s\n" "${1}"; }
31+
info() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[34m[INFO] %s\033[0m\n" "${1}" || printf "[INFO] %s\n" "${1}"; }
32+
pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[32m[ OK ] %s\033[0m\n" "${1}" || printf "[ OK ] %s\n" "${1}"; }
33+
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
34+
# @formatter:on
35+
36+
drush() { "build/vendor/bin/drush" -r "$(pwd)/build/web" -y "$@"; }
37+
38+
#-------------------------------------------------------------------------------
39+
2940
echo "==============================="
3041
echo " 🚀 PROVISION "
3142
echo "==============================="
3243
echo
3344

34-
drush() { "build/vendor/bin/drush" -r "$(pwd)/build/web" -y "$@"; }
35-
3645
# Extension name, taken from .info file.
3746
extension="$(basename -s .info.yml -- ./*.info.yml)"
38-
[ "${extension}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1
47+
[ "${extension}" == "*" ] && fail "ERROR: No .info.yml file found." && exit 1
3948
extension_type="module"
4049
if cat "${extension}.info.yml" | grep -Fq "type: theme"; then
4150
extension_type="theme"
@@ -44,30 +53,35 @@ fi
4453
# Database file path.
4554
db_file="/tmp/site_${extension}.sqlite"
4655

47-
echo "> Install Drupal into SQLite database ${db_file}."
56+
info "Installing Drupal into SQLite database ${db_file}."
4857
drush si "${DRUPAL_PROFILE}" -y --db-url "sqlite://${db_file}" --account-name=admin install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL
58+
pass "Drupal installed."
59+
4960
drush status
5061

51-
echo "> Enable extension ${extension}."
62+
info "Enabling extension ${extension}."
5263
if [ "${extension_type}" = "theme" ]; then
5364
drush theme:enable "${extension}" -y
5465
else
5566
drush pm:enable "${extension}" -y
5667
fi
68+
69+
info "Clearing caches."
5770
drush cr
5871

59-
echo "> Enable suggested modules, if any."
72+
info "Enabling suggested modules, if any."
6073
drupal_suggests=$(cat composer.json | jq -r 'select(.suggest != null) | .suggest | keys[]' | sed "s/drupal\///" | cut -f1 -d":")
6174
for drupal_suggest in $drupal_suggests; do
6275
drush pm:enable "${drupal_suggest}" -y
6376
done
77+
pass "Suggested modules enabled."
6478

65-
# Visit site to pre-warm caches.
79+
info "Pre-warming caches."
6680
curl -s "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" >/dev/null
6781

6882
echo
6983
echo "==============================="
70-
echo " 🚀 PROVISION COMPLETE "
84+
echo " 🚀 PROVISION COMPLETE "
7185
echo "==============================="
7286
echo
7387
echo "Site URL: http://${WEBSERVER_HOST}:${WEBSERVER_PORT}"

.devtools/start.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,43 @@ WEBSERVER_WAIT_TIMEOUT="${WEBSERVER_WAIT_TIMEOUT:-5}"
2222

2323
#-------------------------------------------------------------------------------
2424

25+
# @formatter:off
26+
note() { printf " %s\n" "${1}"; }
27+
info() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[34m[INFO] %s\033[0m\n" "${1}" || printf "[INFO] %s\n" "${1}"; }
28+
pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[32m[ OK ] %s\033[0m\n" "${1}" || printf "[ OK ] %s\n" "${1}"; }
29+
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
30+
# @formatter:on
31+
32+
#-------------------------------------------------------------------------------
33+
2534
echo "==============================="
2635
echo " 💻 START ENVIRONMENT "
2736
echo "==============================="
2837
echo
2938

30-
echo "> Stop previously started services, if any."
39+
info "Stopping previously started services, if any."
3140
killall -9 php >/dev/null 2>&1 || true
3241

33-
echo "> Start the PHP webserver."
42+
info "Starting the PHP webserver."
3443
nohup php -S "${WEBSERVER_HOST}:${WEBSERVER_PORT}" -t "$(pwd)/build/web" "$(pwd)/build/web/.ht.router.php" >/tmp/php.log 2>&1 &
3544

36-
echo "> Wait ${WEBSERVER_WAIT_TIMEOUT} seconds for the server to be ready."
45+
note "Waiting ${WEBSERVER_WAIT_TIMEOUT} seconds for the server to be ready."
3746
sleep "${WEBSERVER_WAIT_TIMEOUT}"
3847

39-
echo "> Check that the server was started."
48+
note "Checking that the server was started."
4049
netstat_opts='-tulpn'
4150
[ "$(uname)" == "Darwin" ] && netstat_opts='-anv' || true
4251
netstat "${netstat_opts[@]}" | grep -q "${WEBSERVER_PORT}" || (echo "ERROR: Unable to start inbuilt PHP server" && cat /tmp/php.log && exit 1)
4352

44-
echo "> Check that the server can serve content."
53+
pass "Server started successfully."
54+
55+
info "Checking that the server can serve content."
4556
curl -s -o /dev/null -w "%{http_code}" -L -I "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" | grep -q 200 || (echo "ERROR: Server is started, but site cannot be served" && exit 1)
57+
pass "Server can serve content."
4658

4759
echo
4860
echo "==============================="
49-
echo " 💻 ENVIRONMENT READY "
61+
echo " 💻 ENVIRONMENT READY "
5062
echo "==============================="
5163
echo
5264
echo "Directory : $(pwd)/build/web"

.devtools/stop.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
##
3+
# Stop development environment.
4+
#
5+
# shellcheck disable=SC2015,SC2094,SC2002
6+
7+
set -eu
8+
[ -n "${DEBUG:-}" ] && set -x
9+
10+
#-------------------------------------------------------------------------------
11+
12+
# @formatter:off
13+
note() { printf " %s\n" "${1}"; }
14+
info() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[34m[INFO] %s\033[0m\n" "${1}" || printf "[INFO] %s\n" "${1}"; }
15+
pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[32m[ OK ] %s\033[0m\n" "${1}" || printf "[ OK ] %s\n" "${1}"; }
16+
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
17+
# @formatter:on
18+
19+
#-------------------------------------------------------------------------------
20+
21+
echo "==============================="
22+
echo " 💻 STOP ENVIRONMENT "
23+
echo "==============================="
24+
echo
25+
26+
info "Stopping previously started services, if any."
27+
killall -9 php >/dev/null 2>&1 || true
28+
sleep 1
29+
pass "Services stopped."
30+
31+
echo
32+
echo "==============================="
33+
echo " 💻 ENVIRONMENT STOPPED ✅ "
34+
echo "==============================="
35+
echo

0 commit comments

Comments
 (0)