build-configs/templates/php/drupal/run.twig
Oliver Davies 4e255cd667 Ensure run.local files are located relative to the
...run file

Prevent erroring if `run` is being executed within a sub-directory, like
`assets`.
2024-07-31 01:20:30 +01:00

169 lines
3.3 KiB
Twig
Executable file

#!/usr/bin/env bash
# {{ managedText | raw }}
set -o errexit
set -o pipefail
# If we're running in CI we need to disable TTY allocation for docker compose
# commands that enable it by default, such as exec and run.
TTY="${TTY:-}"
if [[ ! -t 1 ]]; then
TTY="-T"
fi
# Run automated tests as part of the Continuous Integration (CI) pipeline.
function ci:test {
lint:dockerfile
docker compose version
docker network create traefik_proxy || true
cp --no-clobber .env.example .env || true
docker compose build --progress plain
docker compose up --detach
docker compose logs
composer install --quiet --no-progress
{% if not php.phpcs is same as false %}
test --testdox
{% endif %}
{% if not php.phpcs is same as false and not php.phpstan is same as false %}
quality
{% endif %}
}
# Run a command within the php container.
function cmd {
docker compose exec php "${@}"
}
{% if not php.phpcs is same as false %}
# Run coding standards checks.
function coding-standards {
cmd phpcs "${@}"
}
{% endif %}
# Execute any Composer command.
function composer {
_exec php composer "${@}"
}
# Connect to the database.
function db {
[[ -f ".env" ]] && source .env
docker compose exec database mysql -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME"
}
# Execute any Drush command.
function drush {
_exec php drush "${@}"
}
# Disable Git hooks.
function git-hooks:off {
git config --unset core.hooksPath
}
# Enable Git hooks.
function git-hooks:on {
git config core.hooksPath .githooks
}
# Display a list of all available commands.
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# Install Drupal.
function install {
drush site:install -y "${@}"
}
# Lint the Dockerfile.
function lint:dockerfile {
docker container run --rm -i \
hadolint/hadolint hadolint --ignore DL3008 --ignore DL3022 --ignore DL3059 -t style "${@}" - < Dockerfile
}
{% if not php.phpcs is same as false and not php.phpstan is same as false %}
# Run code quality checks.
function quality {
{% if not php.phpcs is same as false %}
coding-standards
{% endif %}
{% if not php.phpstan is same as false %}
static-analysis
{% endif %}
}
{% endif %}
# Start the project.
function start {
cp -v --no-clobber .env.example .env || true
docker compose up -d
}
{% if not php.phpstan is same as false %}
function static-analysis {
cmd phpstan --memory-limit=-1 --no-progress "${@}"
}
{% endif %}
function stop {
docker compose down
}
{% if not php.phpunit is same as false %}
function test {
_exec php phpunit --colors=always "${@}"
}
{% endif %}
function test:commit {
{% if not php.phpunit is same as false %}
test --testdox --testsuite functional
test --testdox --testsuite kernel
test --testdox --testsuite unit
{% endif %}
quality
}
function _exec {
docker compose exec ${TTY} "${@}"
}
function _run {
local service="${1}"
local command="${2}"
docker compose run \
--entrypoint "${command}" \
--no-deps \
--rm \
${TTY} \
"${service}" "${@}"
}
# Include any local tasks.
# https://stackoverflow.com/a/6659698
[[ -e "${BASH_SOURCE%/*}/run.local" ]] && source "${BASH_SOURCE%/*}/run.local"
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"
# vim: ft=bash