Skip to content

Commit

Permalink
Merge branch '1.x' into feature/add-bats-test-ahoy-operation
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 committed May 7, 2024
2 parents 74be735 + 9362429 commit d35ab22
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 132 deletions.
42 changes: 29 additions & 13 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,51 @@ commands:
build:
usage: Build or rebuild the project.
cmd: |
ahoy build-codebase
ahoy start-server
ahoy assemble
ahoy start
ahoy provision
build-codebase:
usage: Build the codebase.
cmd: ./.devtools/build-codebase.sh
assemble:
usage: Assemble a codebase using project code and all required dependencies.
cmd: ./.devtools/assemble.sh

start-server:
usage: Start built-in PHP-server.
cmd: ./.devtools/start-server.sh
start:
usage: Start development environment.
cmd: ./.devtools/start.sh

provision:
usage: Provision a website.
usage: Provision application within assembled codebase.
cmd: ./.devtools/provision.sh

drush:
usage: Run Drush command.
cmd: build/vendor/bin/drush -l http://${WEBSERVER_HOST:-localhost}:${WEBSERVER_PORT:-8000} $*

login:
usage: Login to a website.
cmd: ahoy drush uli

lint:
usage: Lint code.
usage: Check coding standards for violations.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/phpcs
vendor/bin/phpstan
vendor/bin/rector --clear-cache --dry-run
vendor/bin/phpmd . text phpmd.xml
vendor/bin/twigcs
vendor/bin/twig-cs-fixer
popd >/dev/null || exit 1
lint-fix:
usage: Fix coding standards.
usage: Fix violations in coding standards.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/rector --clear-cache
vendor/bin/phpcbf
popd >/dev/null || exit 1
test:
usage: Run all tests.
usage: Run tests.
cmd: |
pushd "build" >/dev/null || exit 1
vendor/bin/phpunit
Expand All @@ -71,6 +79,14 @@ commands:
vendor/bin/phpunit --testsuite functional
popd >/dev/null || exit 1
reset:
usage: Reset project to the default state.
cmd: |
killall -9 php >/dev/null 2>&1 || true
chmod -Rf 777 build > /dev/null
rm -Rf build > /dev/null || true
rm -Rf .logs > /dev/null || true
# Override entrypoint to alter default behaviour of Ahoy.
entrypoint:
- bash
Expand Down
11 changes: 5 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ job-test: &job-test

- run:
name: Build the codebase
command: .devtools/build-codebase.sh
command: .devtools/assemble.sh

- run:
name: Start built-in PHP server
command: .devtools/start-server.sh
command: .devtools/start.sh

- run:
name: Provision site
Expand All @@ -52,8 +52,8 @@ job-test: &job-test
working_directory: build

- run:
name: Lint code with Twigcs
command: vendor/bin/twigcs || [ "${CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ]
name: Lint code with Twig CS Fixer
command: vendor/bin/twig-cs-fixer || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ]
working_directory: build

- run:
Expand Down Expand Up @@ -88,8 +88,7 @@ jobs:
docker:
- image: cimg/php:8.2-browsers
environment:
DRUPAL_VERSION: 9.5
DRUPAL_PROJECT_SHA: 9.x
DRUPAL_VERSION: 10.1
<<: *job-test

test-php-8.2-next:
Expand Down
3 changes: 3 additions & 0 deletions .devtools/README.nd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains scripts used for development.

These can be used locally and in the CI environment.
3 changes: 0 additions & 3 deletions .devtools/README.txt

This file was deleted.

19 changes: 10 additions & 9 deletions .devtools/build-codebase.sh → .devtools/assemble.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
##
# Build the codebase.
# Assemble a codebase using project code and all required dependencies.
#
# Allows to use the latest Drupal core as well as specified versions (for
# testing backward compatibility).
Expand Down Expand Up @@ -37,9 +37,10 @@ DRUPAL_PROJECT_REPO="${DRUPAL_PROJECT_REPO:-https://github.com/drupal-composer/d

#-------------------------------------------------------------------------------

echo "-------------------------------"
echo " Build codebase "
echo "-------------------------------"
echo "==============================="
echo " 🏗️ ASSEMBLE "
echo "==============================="
echo

# Make sure Composer doesn't run out of memory.
export COMPOSER_MEMORY_LIMIT=-1
Expand Down Expand Up @@ -107,7 +108,7 @@ for composer_suggest in $composer_suggests; do
done

echo "> Copy tools configuration files."
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig_cs.php phpunit.xml "build/"
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig-cs-fixer.php phpunit.xml "build/"

echo "> Symlink extension's code."
rm -rf "build/web/${type}/custom" >/dev/null && mkdir -p "build/web/${type}/custom/${extension}"
Expand All @@ -126,11 +127,11 @@ if [ -f "build/web/${type}/custom/${extension}/package-lock.json" ]; then
fi

echo
echo "-------------------------------"
echo " Codebase built 🚀 "
echo "-------------------------------"
echo "==============================="
echo " 🏗 ASSEMBLE COMPLETE "
echo "==============================="
echo
echo "> Next steps:"
echo " .devtools/start-server.sh # Start the webserver"
echo " .devtools/start.sh # Start the webserver"
echo " .devtools/provision.sh # Provision the website"
echo
13 changes: 7 additions & 6 deletions .devtools/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ if [ -n "${DEPLOY_SSH_KEY_FINGERPRINT}" ]; then
ssh-add -l
fi

echo "-------------------------------"
echo " Deploy code "
echo "-------------------------------"
echo "==============================="
echo " 🚚 DEPLOY "
echo "==============================="
echo

[ -z "${DEPLOY_USER_NAME}" ] && echo "ERROR: Missing required value for DEPLOY_USER_NAME" && exit 1
[ -z "${DEPLOY_USER_EMAIL}" ] && echo "ERROR: Missing required value for DEPLOY_USER_EMAIL" && exit 1
Expand Down Expand Up @@ -106,9 +107,9 @@ git push --force deployremote HEAD:"${DEPLOY_BRANCH}"
echo "> Push tags."
git push --force --tags deployremote || true

echo "-------------------------------"
echo " Deployed code "
echo "-------------------------------"
echo "==============================="
echo " 🚚 DEPLOY COMPLETE "
echo "==============================="
echo
echo "Remote URL : ${DEPLOY_REMOTE}"
echo "Remote branch : ${DEPLOY_BRANCH}"
Expand Down
13 changes: 7 additions & 6 deletions .devtools/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}"

#-------------------------------------------------------------------------------

echo "----------------------------------"
echo " Install Drupal and extensions "
echo "----------------------------------"
echo "==============================="
echo " 🚀 PROVISION "
echo "==============================="
echo

drush() { "build/vendor/bin/drush" -r "$(pwd)/build/web" -y "$@"; }

Expand Down Expand Up @@ -65,9 +66,9 @@ done
curl -s "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" >/dev/null

echo
echo "-------------------------------"
echo " Install finished 🚀🚀🚀 "
echo "-------------------------------"
echo "==============================="
echo " 🚀 PROVISION COMPLETE "
echo "==============================="
echo
echo "Site URL: http://${WEBSERVER_HOST}:${WEBSERVER_PORT}"
echo -n "One-time login link: "
Expand Down
15 changes: 8 additions & 7 deletions .devtools/start-server.sh → .devtools/start.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
##
# Start built-in PHP-server.
# Start development environment.
#
# shellcheck disable=SC2015,SC2094,SC2002

Expand All @@ -22,9 +22,10 @@ WEBSERVER_WAIT_TIMEOUT="${WEBSERVER_WAIT_TIMEOUT:-5}"

#-------------------------------------------------------------------------------

echo "-------------------------------"
echo " Start built-in PHP server "
echo "-------------------------------"
echo "==============================="
echo " 💻 START ENVIRONMENT "
echo "==============================="
echo

echo "> Stop previously started services, if any."
killall -9 php >/dev/null 2>&1 || true
Expand All @@ -44,9 +45,9 @@ echo "> Check that the server can serve content."
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)

echo
echo "-----------------------------------"
echo " Started built-in PHP server 🚀🚀 "
echo "-----------------------------------"
echo "==============================="
echo " 💻 ENVIRONMENT READY "
echo "==============================="
echo
echo "Directory : $(pwd)/build/web"
echo "URL : http://${WEBSERVER_HOST}:${WEBSERVER_PORT}"
Expand Down
30 changes: 15 additions & 15 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Ignore files for distribution archives.

# Uncomment the lines below in your project.
# .ahoy.yml export-ignore
# .circleci export-ignore
# .devtools export-ignore
# .editorconfig export-ignore
# .gitattributes export-ignore
# .github export-ignore
# .gitignore export-ignore
# .twig_cs.php export-ignore
# composer.dev.json export-ignore
# phpcs.xml export-ignore
# phpmd.xml export-ignore
# phpstan.neon export-ignore
# rector.php export-ignore
# renovate.json export-ignore
# tests export-ignore
# .ahoy.yml export-ignore
# .circleci export-ignore
# .devtools export-ignore
# .editorconfig export-ignore
# .gitattributes export-ignore
# .github export-ignore
# .gitignore export-ignore
# .twig-cs-fixer.php export-ignore
# composer.dev.json export-ignore
# phpcs.xml export-ignore
# phpmd.xml export-ignore
# phpstan.neon export-ignore
# rector.php export-ignore
# renovate.json export-ignore
# tests export-ignore

# Remove the lines below in your project.
.github/FUNDING.yml export-ignore
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:

- name: test-php-8.2-legacy
php-version: 8.2
drupal-version: 9.5
drupal-project-sha: 9.x
drupal-version: 10.1
drupal-project-sha: 10.x
drupal-version-alias: legacy

- name: test-php-8.2-next
Expand Down Expand Up @@ -65,10 +65,10 @@ jobs:
php-version: ${{ matrix.php-version }}

- name: Build the codebase
run: .devtools/build-codebase.sh
run: .devtools/assemble.sh

- name: Start built-in PHP server
run: .devtools/start-server.sh
run: .devtools/start.sh

- name: Provision site
run: .devtools/provision.sh
Expand All @@ -89,9 +89,9 @@ jobs:
working-directory: build
run: vendor/bin/phpmd . text phpmd.xml || [ "${CI_PHPMD_IGNORE_FAILURE:-0}" -eq 1 ]

- name: Lint code with Twigcs
- name: Lint code with Twig CS Fixer
working-directory: build
run: vendor/bin/twigcs || [ "${CI_TWIGCS_IGNORE_FAILURE:-0}" -eq 1 ]
run: vendor/bin/twig-cs-fixer || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ]

- name: Run tests
working-directory: build
Expand Down
27 changes: 4 additions & 23 deletions .scaffold/tests/bats/_assert_init.bash
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,10 @@ assert_workflow() {

pushd "${dir}" >/dev/null || exit 1

./.devtools/build-codebase.sh
./.devtools/start-server.sh
./.devtools/provision.sh

# Lint.
pushd "build" >/dev/null || exit 1

vendor/bin/phpcs
vendor/bin/phpstan
vendor/bin/rector --clear-cache --dry-run
vendor/bin/phpmd . text phpmd.xml
vendor/bin/twigcs

popd >/dev/null || exit 1

# Test.
./.devtools/test.sh

# Change mode to make bats have enough permission to clean tmp test directory.
chmod -R 777 "build/web/sites/default"

# Allow bats finish this assert, we need kill php process because it run in background in start server step.
killall -9 php >/dev/null 2>&1 || true
ahoy build
ahoy lint
ahoy test
ahoy reset

popd >/dev/null || exit 1
}
16 changes: 16 additions & 0 deletions .twig-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types = 1);

$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->addStandard(new TwigCsFixer\Standard\Twig());

$finder = new TwigCsFixer\File\Finder();
$finder->in(__DIR__ . '/web/modules/custom');
$finder->in(__DIR__ . '/web/themes/custom');

$config = new TwigCsFixer\Config\Config();
$config->setRuleset($ruleset);
$config->setFinder($finder);

return $config;
15 changes: 0 additions & 15 deletions .twig_cs.php

This file was deleted.

Loading

0 comments on commit d35ab22

Please sign in to comment.