Skip to content

Commit

Permalink
chore: add local build and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mogtofu33 committed Feb 2, 2024
1 parent 78cea6e commit 0c91867
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 18 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/tmp
composer.lock
vendor
vendor
drupal/tests/test_drush.py
drupal/tests/test_packages.py
drupal/tests/test_php.py
8 changes: 6 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ stages:
stage: build
script:
- echo "Build $IMAGE_VERSION with Drupal:$IMAGE_TAG PHP:$PHP_VERSION Node:$NODE_VERSION"
- PHP_VERSION="$PHP_VERSION" envsubst < "./drupal/tests/test_php.py" > "./drupal/tests/test_php.py"
- NODE_VERSION="$NODE_VERSION" envsubst < "./drupal/tests/test_packages.py" > "./drupal/tests/test_packages.py"
- DRUPAL_VERSION="$IMAGE_TAG" envsubst < "./drupal/tests/test_drush.py" > "./drupal/tests/test_drush.py"
- docker build
--tag $CI_REGISTRY_IMAGE/$IMAGE
--tag $RELEASE_IMAGE/$IMAGE
--build-arg IMAGE_VERSION=$IMAGE_VERSION
--build-arg IMAGE_TAG=$IMAGE_TAG
--build-arg PHP_VERSION=$PHP_VERSION
--build-arg IMAGE_VERSION=$IMAGE_VERSION
--build-arg NODE_VERSION=$NODE_VERSION
--compress
$BUILD_DIR
Expand Down Expand Up @@ -81,4 +84,5 @@ chrome-headless:
IMAGE: chrome-headless:${CI_COMMIT_BRANCH}
BUILD_DIR: chrome-headless
IMAGE_TAG: ''
PHP_VERSION: ''
PHP_VERSION: ''
NODE_VERSION: ''
44 changes: 38 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
IMAGE_VERSION=1.3
NODE_VERSION=18

# Must match with .gitlab-ci.yml
DRUPAL_PREVIOUS=10.1
DRUPAL_PREVIOUS_PHP=8.1
DRUPAL_CURRENT=10.2
DRUPAL_CURRENT_PHP=8.2
DRUPAL_NEXT=11
DRUPAL_NEXT_PHP=8.2

define build
@echo "Build $(1) with Drupal:$(2) PHP:$(3) Node:$(4)..."
PHP_VERSION="$(3)" envsubst < "./drupal/tests/test_php.py.tpl" > "./drupal/tests/test_php.py" ;
NODE_VERSION="$(4)" envsubst < "./drupal/tests/test_packages.py.tpl" > "./drupal/tests/test_packages.py" ;
DRUPAL_VERSION="$(2)" envsubst < "./drupal/tests/test_drush.py.tpl" > "./drupal/tests/test_drush.py" ;
docker build \
--tag test-drupal-ci:$(2) \
--build-arg IMAGE_VERSION=$(1) \
--build-arg IMAGE_TAG=$(2) \
--build-arg PHP_VERSION=$(3) \
--build-arg NODE_VERSION=$(4) \
./drupal ;
endef

define test
@echo "Run tests for $(1)..."
@docker run -d --name test-ci-$(1) test-drupal-ci:$(1)
@docker exec test-ci-$(1) /tests/prepare-tests.sh
@docker exec -w /tests test-ci-$(1) pytest-3
endef

build:
@docker build --progress=plain --tag test-drupal-ci ./drupal
@# docker build --progress=plain --tag test-drupal-ci --build-arg IMAGE_TAG='10.2' ./drupal
@docker run -it --rm test-drupal-ci bash
$(call build,${IMAGE_VERSION},${DRUPAL_PREVIOUS},${DRUPAL_PREVIOUS_PHP},${NODE_VERSION})
$(call build,${IMAGE_VERSION},${DRUPAL_CURRENT},${DRUPAL_CURRENT_PHP},${NODE_VERSION})
# $(call build,${IMAGE_VERSION},${DRUPAL_NEXT},${DRUPAL_NEXT_PHP},${NODE_VERSION})

test:
@docker run -d --name test-ci test-drupal-ci
@docker exec test-ci /tests/prepare-tests.sh
docker exec -w /tests test-ci pytest-3
$(call test,${DRUPAL_PREVIOUS})
$(call test,${DRUPAL_CURRENT})
# $(call test,${DRUPAL_NEXT})
3 changes: 1 addition & 2 deletions drupal/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ USER root

#==================
# Install Drupal core:dev, Drush for a module.
# @todo remove phpspec/prophecy-phpunit when Drupal 9 is deprecated.
RUN COMPOSER_MEMORY_LIMIT=-1 COMPOSER_ALLOW_SUPERUSER=1 \
composer require -n --dev --working-dir="/opt/drupal" \
"drupal/core-dev:^${IMAGE_TAG}" "drush/drush" "phpspec/prophecy-phpunit:^2" ; \
"drupal/core-dev:^${IMAGE_TAG}" "drush/drush" ; \
composer clear-cache

#==================
Expand Down
2 changes: 1 addition & 1 deletion drupal/tests/prepare-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eu

_main() {
echo -e "[notice] Install packages for tests..."
apt update && apt install -y python3 python3-testinfra
apt-get update && apt-get install -y python3 python3-testinfra
echo -e "[notice] Done!"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def test_drush(host):
assert host.file("/opt/drupal/vendor/bin/drush").exists
assert host.file("/opt/drupal/vendor/bin/drush").mode == 0o755
assert host.check_output("drush --version").startswith("Drush Commandline Tool")
# assert host.check_output("drush --root=/opt/drupal/web status --field=drupal-version").startswith("$DRUPAL_VERSION")
assert host.check_output("drush --root=/opt/drupal/web status --field=drupal-version").startswith("$DRUPAL_VERSION")
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def test_packages_installed(host, name):
pkg = host.package(name)
assert pkg.is_installed

# def test_node(host):
# assert host.check_output('node -v').startswith('v18')
def test_node(host):
assert host.check_output('node -v').startswith('v$NODE_VERSION')
6 changes: 3 additions & 3 deletions drupal/tests/test_php.py → drupal/tests/test_php.py.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

# def test_php_version(host):
# ''' Check PHP version so it's highlighted when changed '''
# assert host.check_output('php -v').startswith('PHP $PHP_VERSION')
def test_php_version(host):
''' Check PHP version so it's highlighted when changed '''
assert host.check_output('php -v').startswith('PHP $PHP_VERSION')

@pytest.mark.parametrize("name", [
("bcmath"),
Expand Down

0 comments on commit 0c91867

Please sign in to comment.