Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run project-specific Drall during tests #98

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker/main/.profile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PATH=$(echo "$PATH" | sed -e "s/:\/opt\/drupal\/vendor\/bin//")
8 changes: 5 additions & 3 deletions .docker/main/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ RUN cp "$PHP_INI_DIR/php.ini-development" "$PHP_INI_PATH" \
RUN docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-install pcntl

# Provision Drall.
COPY . /opt/drall

# Provision Drupal.
COPY Makefile /opt/drupal/Makefile
COPY Makefile /opt/no-drupal/Makefile
COPY Makefile /opt/empty-drupal/Makefile

RUN echo ". /opt/drall/.docker/main/.profile" >> /root/.profile
RUN echo ". /opt/drall/.docker/main/.profile" >> /root/.bashrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{
"name": "jigarius/drall-demo",
"description": "A Drupal demo site for developing and testing Drall.",
"description": "A Drupal multi-site installation for developing and testing Drall.",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
"docs": "https://www.drupal.org/docs/user_guide/en/index.html",
"chat": "https://www.drupal.org/node/314178"
},
"repositories": [
{
"type": "composer",
Expand Down
9 changes: 9 additions & 0 deletions .docker/main/drupal/web/sites/sites.bad.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* @file
* Site group containing sites that don't exist.
*/

$sites['shredder.com'] = 'shredder';
$sites['foot.com'] = 'foot';
File renamed without changes.
76 changes: 76 additions & 0 deletions .docker/main/empty-drupal/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"description": "A Drupal installation with no sites.",
"type": "project",
"license": "GPL-2.0-or-later",
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "path",
"url": "/opt/drall",
"options": {
"symlink": false
}
}
],
"require": {
"composer/installers": "^2",
"drupal/core-composer-scaffold": "*",
"drupal/core-recommended": "^11",
"drupal/core-vendor-hardening": "*",
"jigarius/drall": "*"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/installers": true,
"drupal/core-composer-scaffold": true,
"drupal/core-project-message": true,
"drupal/core-vendor-hardening": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
},
"installer-paths": {
"web/core": [
"type:drupal-core"
],
"web/libraries/{$name}": [
"type:drupal-library"
],
"web/modules/contrib/{$name}": [
"type:drupal-module"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/contrib/{$name}": [
"type:drupal-theme"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
],
"web/modules/custom/{$name}": [
"type:drupal-custom-module"
],
"web/profiles/custom/{$name}": [
"type:drupal-custom-profile"
],
"web/themes/custom/{$name}": [
"type:drupal-custom-theme"
]
}
}
}
3 changes: 3 additions & 0 deletions .docker/main/empty-drupal/web/sites/sites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$sites = [];
29 changes: 29 additions & 0 deletions .docker/main/no-drupal/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"description": "Project that contains Drall without Drupal.",
"type": "project",
"license": "GPL-2.0-or-later",
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "path",
"url": "/opt/drall",
"options": {
"symlink": false
}
}
],
"require": {
"jigarius/drall": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/installers": true
}
}
}
5 changes: 1 addition & 4 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
php-versions: ['8.3']
php-versions: ['8.3', '8.4']
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Path Setup
run: |
echo "/opt/drupal/vendor/bin" >> $GITHUB_PATH
- name: Determine Composer Cache Directory
id: composer-cache
run: |
Expand Down
53 changes: 32 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ ssh:


.PHONY: provision
provision: provision/drall provision/drupal
provision: provision/env provision/drall provision/no-drupal provision/empty-drupal provision/drupal


.PHONY: provision/env
provision/env:
cp /opt/drall/bin/drall-launcher /usr/local/bin/drall


.PHONY: provision/drupal
provision/drupal:
mkdir -p /opt/drupal
cp /opt/drall/.docker/main/composer.json /opt/drupal/ || echo "Skipping drupal/composer.json"

cp /opt/drall/.docker/main/drupal/composer.json /opt/drupal/ || echo "Skipping: drupal/composer.json"
rm -f /opt/drupal/composer.lock
composer --working-dir=/opt/drupal install --no-progress

cp -r /opt/drall/.docker/main/drush /opt/drupal/ || echo "Skipping drush directory."
cp -r /opt/drall/.docker/main/sites /opt/drupal/web/ || echo "Skipping sites directory."
cp -r /opt/drall/.docker/main/drupal/drush /opt/drupal/ || echo "Skipping: drupal/drush"
cp -r /opt/drall/.docker/main/drupal/web/sites /opt/drupal/web/ || echo "Skipping: drupal/web/sites"

mkdir -p /opt/drupal/web/sites/default
mkdir -p /opt/drupal/web/sites/donnie
Expand All @@ -29,9 +34,27 @@ provision/drupal:
cp /opt/drupal/web/sites/default/default.settings.php /opt/drupal/web/sites/mikey/settings.php
cp /opt/drupal/web/sites/default/default.settings.php /opt/drupal/web/sites/ralph/settings.php

@echo ''
@echo 'Drupal databases can be provisioned with: make provision/drupal/database'


.PHONY: provision/no-drupal
provision/no-drupal:
mkdir -p /opt/no-drupal
cp /opt/drall/.docker/main/no-drupal/composer.json /opt/no-drupal/ || echo "Skipping: no-drupal/composer.json"
rm -f /opt/no-drupal/composer.lock
composer --working-dir=/opt/no-drupal install --no-progress


.PHONY: provision/empty-drupal
provision/empty-drupal:
mkdir -p /opt/empty-drupal
cp /opt/drall/.docker/main/empty-drupal/composer.json /opt/empty-drupal/ || echo "Skipping: empty-drupal/composer.json"
rm -f /opt/empty-drupal/composer.lock
composer --working-dir=/opt/empty-drupal install --no-progress
cp /opt/drall/.docker/main/empty-drupal/web/sites/sites.php /opt/empty-drupal/web/sites/sites.php


.PHONY: provision/drupal/database
provision/drupal/database:
rm -f web/sites/*/settings.php
Expand All @@ -56,17 +79,14 @@ provision/drupal/database:
provision/drall:
composer install --working-dir=/opt/drall --no-progress

# The GitHub Action shivammathur/setup-php@v2 gives higher priority to
# the executables present in /opt/drall/vendor/bin. Thus, we remove
# Drush from this directory to force /opt/drupal/vendor/bin/drush.
rm -f /opt/drall/vendor/bin/drush


# Due to the way Composer works, jigarius/drall cannot be symlinked into
# the Drupal setup used for development. Thus, after every change made to
# Drall, it must be re-installed inside the Drupal installation.
.PHONY: refresh
refresh:
rsync -Ervu --inplace --delete --exclude=.coverage --exclude=.phpunit.cache --exclude=.idea --exclude=.git --exclude=vendor /opt/drall/ /opt/no-drupal/vendor/jigarius/drall/
rsync -Ervu --inplace --delete --exclude=.coverage --exclude=.phpunit.cache --exclude=.idea --exclude=.git --exclude=vendor /opt/drall/ /opt/empty-drupal/vendor/jigarius/drall/
rsync -Ervu --inplace --delete --exclude=.coverage --exclude=.phpunit.cache --exclude=.idea --exclude=.git --exclude=vendor /opt/drall/ /opt/drupal/vendor/jigarius/drall/


Expand All @@ -92,17 +112,8 @@ test:

.PHONY: info
info:
@cd $(DRUPAL_PATH)
@echo "Path: $(PATH)"
@echo "PWD: $(PWD)"
@echo "Drupal path: $(DRUPAL_PATH)"

which php
@php --version

which composer
@composer --version

which drush
@drush --version

which drall
@drall --version
17 changes: 17 additions & 0 deletions bin/drall-launcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

dir=$(pwd)
while [ "$dir" != "/" ]; do
if [ -x "$dir/vendor/bin/drall" ]; then
"$dir/vendor/bin/drall" "$@"
break
fi
dir=$(dirname "$dir")
done

if [ "$dir" == "/" ]; then
echo "Drall executable not found."
exit 1
fi
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ services:
- "8080:80"
volumes:
- .:/opt/drall
- .docker/main/sites/sites.php:/opt/drupal/web/sites/sites.php
- .docker/main/sites/sites.reddish.php:/opt/drupal/web/sites/sites.reddish.php
- .docker/main/sites/sites.bluish.php:/opt/drupal/web/sites/sites.bluish.php
- .docker/main/composer.json:/opt/drupal/composer.json
- .docker/main/drush:/opt/drupal/drush
- .docker/main/drupal/composer.json:/opt/drupal/composer.json
- ./Makefile:/opt/no-drupal/Makefile
- ./Makefile:/opt/empty-drupal/Makefile
- ./Makefile:/opt/drupal/Makefile
environment:
- DRALL_ENVIRONMENT=development
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@
<rule ref="Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps">
<severity>0</severity>
</rule>
<rule ref="Generic.Files.LineLength.MaxExceeded">
<exclude-pattern>test/*.php</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.DocComment.MissingShort">
<exclude-pattern>test/*.php</exclude-pattern>
</rule>
</ruleset>
24 changes: 0 additions & 24 deletions src/IntegrationTestCase.php

This file was deleted.

12 changes: 5 additions & 7 deletions src/Service/SiteDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public function getSiteAliases(
?string $group = NULL,
?string $filter = NULL,
): array {
// Use Drupal Finder to ensure that the Drupal is installed. This ensures
// consistency in errors raised by methods that depend on sites.*.php.
$this->drupalFinder()->getDrupalRoot();

$result = array_values($this->siteAliasManager()->getMultiple());

if ($group) {
Expand Down Expand Up @@ -158,13 +162,7 @@ public function getSiteAliasNames(
* Path/to/drush.
*/
public function getDrushPath(): string {
if (!$vendorDir = $this->drupalFinder->getVendorDir()) {
// This should only happen when drall is installed globally and not in a
// specific Drupal project.
return 'drush';
}

return "$vendorDir/bin/drush";
return $this->drupalFinder->getVendorDir() . "/bin/drush";
}

private function getSitesFile($group = NULL): ?SitesFile {
Expand Down
Loading
Loading