From 48ab012fc354bc9d8d629ddb0d2653ea706a789f Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen.haas@lakedrops.com> Date: Wed, 11 Jan 2023 16:23:38 +0100 Subject: [PATCH] Always overwrite config files that are ignored by git Add cypress script Add some cypress directories to .gitignore --- src/Handler.php | 50 ++++++++++++++++++-------------- src/UpdateCommand.php | 2 +- templates/tests/cypress-run.twig | 22 ++++++++++++++ 3 files changed, 51 insertions(+), 23 deletions(-) create mode 100755 templates/tests/cypress-run.twig diff --git a/src/Handler.php b/src/Handler.php index ba14d7f..a0ddd44 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -256,11 +256,8 @@ class Handler extends BaseHandler { /** * Configure Drupal Project for Docker. - * - * @param bool $overwrite - * Whether to overwrite existing config files. */ - public function configureProject(bool $overwrite = FALSE): void { + public function configureProject(): void { // We only do the fancy stuff for developers. if (!$this->isDevMode()) { @@ -387,7 +384,7 @@ class Handler extends BaseHandler { } continue; } - if (($overwrite && empty($def['add2git'])) || !$fs->exists($file)) { + if (empty($def['add2git']) || !$fs->exists($file)) { $source = isset($def['source']) && is_file($pluginRoot . '/templates/' . $def['source']) ? $pluginRoot . '/templates/' . $def['source'] : $pluginRoot . '/templates/' . ($def['source'] ?? '') . $template . '.twig'; @@ -454,6 +451,11 @@ class Handler extends BaseHandler { $this->gitIgnore('tests/backstop/backstop_data/html_report'); $this->gitLFS('tests/backstop/**/*.png'); + // Ignore some Cypress directories + $this->gitIgnore('tests/cypress/downloads'); + $this->gitIgnore('tests/cypress/screenshots'); + $this->gitIgnore('tests/cypress/videos'); + if (getenv('LAKEDROPS_BUILD_NG') !== 'yes') { $this->updateTraefik(); } @@ -561,23 +563,27 @@ class Handler extends BaseHandler { 'dest' => $projectRoot . '/tests', ], ]; - if ($this->config->readValue(['cypress', 'enable'])) { - $files['cypress.config.js'] = [ - 'source' => 'tests/', - 'dest' => $projectRoot . '/tests', - 'add2git' => TRUE, - ]; - $files['commands.js'] = [ - 'source' => 'tests/cypress/support/', - 'dest' => $projectRoot . '/tests/cypress/support', - 'add2git' => TRUE, - ]; - $files['e2e.js'] = [ - 'source' => 'tests/cypress/support/', - 'dest' => $projectRoot . '/tests/cypress/support', - 'add2git' => TRUE, - ]; - } + $files['cypress.config.js'] = [ + 'source' => 'tests/', + 'dest' => $projectRoot . '/tests', + 'add2git' => TRUE, + ]; + $files['cypress-run'] = [ + 'source' => 'tests/', + 'dest' => $projectRoot . '/tests', + 'add2git' => FALSE, + 'mode' => 0775, + ]; + $files['commands.js'] = [ + 'source' => 'tests/cypress/support/', + 'dest' => $projectRoot . '/tests/cypress/support', + 'add2git' => TRUE, + ]; + $files['e2e.js'] = [ + 'source' => 'tests/cypress/support/', + 'dest' => $projectRoot . '/tests/cypress/support', + 'add2git' => TRUE, + ]; if (getenv('LAKEDROPS_BUILD_NG') === 'yes') { if ($this->config->readValue(['backup', 'enable'])) { $files['config.yaml'] = [ diff --git a/src/UpdateCommand.php b/src/UpdateCommand.php index 89f0b3c..ca8bd9d 100644 --- a/src/UpdateCommand.php +++ b/src/UpdateCommand.php @@ -30,7 +30,7 @@ class UpdateCommand extends BaseCommand { parent::execute($input, $output); /** @var Handler $handler */ $handler = $this->handler; - $handler->configureProject(TRUE); + $handler->configureProject(); return 0; } diff --git a/templates/tests/cypress-run.twig b/templates/tests/cypress-run.twig new file mode 100755 index 0000000..adf9d14 --- /dev/null +++ b/templates/tests/cypress-run.twig @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +NAME={{ projectname }}_cypress_e2e +ID=$(docker container ls --all -q -f name=^${NAME}$) +if [[ -n ${ID} ]]; then + echo "Ataching to existing process ..." + docker start --attach --interactive ${NAME} +else + docker run -u 1000:$(stat -c "%g" /var/run/docker.sock) --rm --name=${NAME} \ + --network host \ + --env CYPRESS_baseUrl={{ projectprotocol }}://{{ projectdomain }}{{ projectport }} \ + --env CYPRESS_mailhogUrl={{ projectprotocol }}://mailhog-{{ projectdomain }}{{ projectport }} \ + --env PHP_CONTAINER={{ projectname }}-php-1 \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v $(php /usr/local/bin/volume.php --none)/tests/:/e2e \ + -w /e2e \ + registry.lakedrops.com/docker/cypress:latest \ + cypress run --browser firefox --project /e2e +fi +EC=$? -- GitLab