From b41ebd9c0e400b84b9d8eb31472f9f98b0d78ea5 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 13:45:00 +0200 Subject: [PATCH 01/15] Create workflow for behat tests --- .github/workflows/behat-tests.yml | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/behat-tests.yml diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml new file mode 100644 index 00000000..b697963c --- /dev/null +++ b/.github/workflows/behat-tests.yml @@ -0,0 +1,33 @@ +name: Behat-Tests + +on: + push: + pull_request: + +jobs: + tests: + name: Tests (Behat with PHP ${{ matrix.php }}) + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + operating-system: ["ubuntu-latest"] + php: ["8.3"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Start containers + run: | + docker-compose -f "docker-compose.yml" up -d --build + + - name: Setup PHP, with co + run: | + docker-compose -f "docker-compose.yml" exec php composer update + + - name: Run behat tests + run: docker-compose -f "docker-compose.yml" exec php composer behat From 7e9dd35e551979503a3a5a584b4ee3d847768a72 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 13:51:23 +0200 Subject: [PATCH 02/15] try docker compose instead of docker-compose --- .github/workflows/behat-tests.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index b697963c..a6816e2b 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -21,13 +21,16 @@ jobs: with: fetch-depth: 2 + - name: Debug docker + run: docker compose --version && docker-compose --version + - name: Start containers run: | - docker-compose -f "docker-compose.yml" up -d --build + docker compose -f "docker-compose.yml" up -d --build - name: Setup PHP, with co run: | - docker-compose -f "docker-compose.yml" exec php composer update + docker compose -f "docker-compose.yml" exec php composer update - name: Run behat tests - run: docker-compose -f "docker-compose.yml" exec php composer behat + run: docker compose -f "docker-compose.yml" exec php composer behat From 1774052cd0094454ea402c3f0249f2bccf87d82e Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 14:01:35 +0200 Subject: [PATCH 03/15] let containers stop, version in docker-compose.yml is obsolete --- .github/workflows/behat-tests.yml | 10 +++++++--- docker-compose.yml | 2 -- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index a6816e2b..ba18481e 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -21,16 +21,20 @@ jobs: with: fetch-depth: 2 - - name: Debug docker - run: docker compose --version && docker-compose --version + - name: Show docker info + run: docker compose version - name: Start containers run: | docker compose -f "docker-compose.yml" up -d --build - - name: Setup PHP, with co + - name: Setup PHP with composer run: | docker compose -f "docker-compose.yml" exec php composer update - name: Run behat tests run: docker compose -f "docker-compose.yml" exec php composer behat + + - name: Stop containers + run: | + docker compose -f "docker-compose.yml" down diff --git a/docker-compose.yml b/docker-compose.yml index 08ae3b72..83e9550c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.7" - services: php: build: # Info to build the Docker image From a07ff9c725fa2eb4aec73e0e5000f7e5fcfdac34 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 14:11:43 +0200 Subject: [PATCH 04/15] try to cache Docker image, show tree --- .github/workflows/behat-tests.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index ba18481e..de7c931d 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -24,6 +24,14 @@ jobs: - name: Show docker info run: docker compose version + - name: Build and cache Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Start containers run: | docker compose -f "docker-compose.yml" up -d --build @@ -32,6 +40,10 @@ jobs: run: | docker compose -f "docker-compose.yml" exec php composer update + - name: Debug docker files + run: | + docker compose -f "docker-compose.yml" exec php tree ./.docker + - name: Run behat tests run: docker compose -f "docker-compose.yml" exec php composer behat From 9099ff1d4c2c7cb8056e7b1d817ab3f5566c92cc Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 14:23:47 +0200 Subject: [PATCH 05/15] try different approach for docker cache --- .github/workflows/behat-tests.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index de7c931d..f4c05771 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -21,16 +21,17 @@ jobs: with: fetch-depth: 2 - - name: Show docker info - run: docker compose version + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Build and cache Docker image - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: . push: false - cache-from: type=gha - cache-to: type=gha,mode=max + tags: user/app:latest + cache-from: type=registry,ref=user/app:latest + cache-to: type=inline - name: Start containers run: | From a2baeea8f9548961d4a6a151c6857015bc23073f Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 14:25:44 +0200 Subject: [PATCH 06/15] Allow docker cache to push --- .github/workflows/behat-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index f4c05771..db3ae9e4 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -28,7 +28,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . - push: false + push: true tags: user/app:latest cache-from: type=registry,ref=user/app:latest cache-to: type=inline From 82adf118ea52eac4a014c1e9ee467b3deb641748 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 14:41:12 +0200 Subject: [PATCH 07/15] Remove checkout action and context --- .github/workflows/behat-tests.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index db3ae9e4..fd48a91d 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -16,18 +16,12 @@ jobs: php: ["8.3"] steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and cache Docker image uses: docker/build-push-action@v6 with: - context: . push: true tags: user/app:latest cache-from: type=registry,ref=user/app:latest From 9d27224a43f1ae55db2a265472ec8ab53559e9cb Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 15:03:34 +0200 Subject: [PATCH 08/15] Remove cache for docker --- .github/workflows/behat-tests.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index fd48a91d..ed3b28af 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -16,16 +16,13 @@ jobs: php: ["8.3"] steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and cache Docker image - uses: docker/build-push-action@v6 + - name: Checkout + uses: actions/checkout@v4 with: - push: true - tags: user/app:latest - cache-from: type=registry,ref=user/app:latest - cache-to: type=inline + fetch-depth: 2 + + - name: Show docker info + run: docker compose version - name: Start containers run: | From ab24bd420d8840e280e655b4e715ca9212d52bce Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 15:25:16 +0200 Subject: [PATCH 09/15] use ls instead of tree --- .github/workflows/behat-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index ed3b28af..e55805c4 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -34,7 +34,7 @@ jobs: - name: Debug docker files run: | - docker compose -f "docker-compose.yml" exec php tree ./.docker + docker compose -f "docker-compose.yml" exec php ls -al ./.docker/redmine_50103_data/sqlite - name: Run behat tests run: docker compose -f "docker-compose.yml" exec php composer behat From a7d4d626e10164b2b28ae678b192c8d2d2add4ce Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 15:26:37 +0200 Subject: [PATCH 10/15] Fix path --- .github/workflows/behat-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index e55805c4..e58809b4 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -34,7 +34,7 @@ jobs: - name: Debug docker files run: | - docker compose -f "docker-compose.yml" exec php ls -al ./.docker/redmine_50103_data/sqlite + docker compose -f "docker-compose.yml" exec php ls -al ./.docker/redmine-50103_data/sqlite - name: Run behat tests run: docker compose -f "docker-compose.yml" exec php composer behat From d3f4e43b4e8f5e1110ff29bfd45297ebdd0d498c Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 1 Jul 2024 16:46:01 +0200 Subject: [PATCH 11/15] Add health check for redmine instances, simplify supported redmine versions --- docker-compose.yml | 1 - tests/RedmineExtension/BehatHookTracer.php | 8 ---- tests/RedmineExtension/RedmineInstance.php | 46 ++++++++++++++-------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 83e9550c..3d6f8f3f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,7 +23,6 @@ services: - ./.docker/redmine-dev_data/sqlite:/usr/src/redmine/sqlite # Make sure the following services are configured in: - # - /tests/RedmineExtension/RedmineInstance.php # - /tests/Behat/behat.yml redmine-50103: diff --git a/tests/RedmineExtension/BehatHookTracer.php b/tests/RedmineExtension/BehatHookTracer.php index 177bdac5..bb916de1 100644 --- a/tests/RedmineExtension/BehatHookTracer.php +++ b/tests/RedmineExtension/BehatHookTracer.php @@ -22,14 +22,6 @@ final class BehatHookTracer implements InstanceRegistration */ private static array $instances = []; - /** - * @return RedmineVersion[] - */ - public static function getSupportedRedmineVersions(): array - { - return RedmineInstance::getSupportedVersions(); - } - public static function getRedmineInstance(RedmineVersion $redmineVersion): RedmineInstance { if (static::$tracer === null) { diff --git a/tests/RedmineExtension/RedmineInstance.php b/tests/RedmineExtension/RedmineInstance.php index fa07f2b3..b18034d8 100644 --- a/tests/RedmineExtension/RedmineInstance.php +++ b/tests/RedmineExtension/RedmineInstance.php @@ -10,28 +10,11 @@ final class RedmineInstance { - /** - * Make sure that supported versions have a service in /docker-composer.yml - * and are configured in /tests/Behat/behat.yml - */ - public static function getSupportedVersions(): array - { - return [ - RedmineVersion::V5_1_3, - RedmineVersion::V5_0_9, - RedmineVersion::V4_2_10, - ]; - } - /** * @param InstanceRegistration $tracer Required to ensure that RedmineInstance is created while Test Runner is running */ public static function create(InstanceRegistration $tracer, RedmineVersion $version): void { - if (! in_array($version, static::getSupportedVersions())) { - throw new InvalidArgumentException('Redmine ' . $version->asString() . ' is not supported.'); - } - $tracer->registerInstance(new self($tracer, $version)); } @@ -77,6 +60,8 @@ private function __construct(InstanceRegistration $tracer, RedmineVersion $versi $this->redmineUrl = 'http://redmine-' . $versionId . ':3000'; $this->apiKey = sha1($versionId . (string) time()); + $this->runHeathChecks($version); + $this->createDatabaseBackup(); $this->createFilesBackup(); $this->runDatabaseMigration(); @@ -104,6 +89,33 @@ public function getApiKey(): string return $this->apiKey; } + private function runHeathChecks(RedmineVersion $version): void + { + $ch = curl_init($this->redmineUrl); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec($ch); + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($data === false || $statusCode !== 200) { + throw new InvalidArgumentException(sprintf( + 'Could not connect to Redmine server at %s, please make sure that Redmine %s has running a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.', + $this->redmineUrl, + $version->asString(), + )); + } + + if (! file_exists($this->rootPath . $this->workingDB)) { + throw new InvalidArgumentException(sprintf( + 'Could not find database file in %s, please make sure that Redmine %s has a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.', + $this->rootPath . $this->workingDB, + $version->asString(), + )); + } + } + public function reset(InstanceRegistration $tracer): void { if ($tracer !== $this->tracer) { From ac358f7b8153ce345cb7272de7de588568d97934 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 3 Jul 2024 11:40:25 +0200 Subject: [PATCH 12/15] list running containers --- .github/workflows/behat-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index e58809b4..a3428b06 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -34,6 +34,7 @@ jobs: - name: Debug docker files run: | + docker ps -a docker compose -f "docker-compose.yml" exec php ls -al ./.docker/redmine-50103_data/sqlite - name: Run behat tests From 016790070162cab0d8c1bdd131c9491bb28f330c Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 3 Jul 2024 12:41:08 +0200 Subject: [PATCH 13/15] remove behat-tests.yml workflow --- .github/workflows/behat-tests.yml | 45 ------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 .github/workflows/behat-tests.yml diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml deleted file mode 100644 index a3428b06..00000000 --- a/.github/workflows/behat-tests.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Behat-Tests - -on: - push: - pull_request: - -jobs: - tests: - name: Tests (Behat with PHP ${{ matrix.php }}) - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - operating-system: ["ubuntu-latest"] - php: ["8.3"] - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - - name: Show docker info - run: docker compose version - - - name: Start containers - run: | - docker compose -f "docker-compose.yml" up -d --build - - - name: Setup PHP with composer - run: | - docker compose -f "docker-compose.yml" exec php composer update - - - name: Debug docker files - run: | - docker ps -a - docker compose -f "docker-compose.yml" exec php ls -al ./.docker/redmine-50103_data/sqlite - - - name: Run behat tests - run: docker compose -f "docker-compose.yml" exec php composer behat - - - name: Stop containers - run: | - docker compose -f "docker-compose.yml" down From d8a974594a78af597ddaf91d9dab9c533562658f Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 3 Jul 2024 12:42:57 +0200 Subject: [PATCH 14/15] Fix method name --- tests/RedmineExtension/RedmineInstance.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/RedmineExtension/RedmineInstance.php b/tests/RedmineExtension/RedmineInstance.php index b18034d8..71aa4130 100644 --- a/tests/RedmineExtension/RedmineInstance.php +++ b/tests/RedmineExtension/RedmineInstance.php @@ -60,7 +60,7 @@ private function __construct(InstanceRegistration $tracer, RedmineVersion $versi $this->redmineUrl = 'http://redmine-' . $versionId . ':3000'; $this->apiKey = sha1($versionId . (string) time()); - $this->runHeathChecks($version); + $this->runHealthChecks($version); $this->createDatabaseBackup(); $this->createFilesBackup(); @@ -89,7 +89,7 @@ public function getApiKey(): string return $this->apiKey; } - private function runHeathChecks(RedmineVersion $version): void + private function runHealthChecks(RedmineVersion $version): void { $ch = curl_init($this->redmineUrl); curl_setopt($ch, CURLOPT_TIMEOUT, 5); From f93c4fc04e1f2589396705d98aedae90bef456c6 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 3 Jul 2024 12:52:07 +0200 Subject: [PATCH 15/15] Fix error message --- tests/RedmineExtension/RedmineInstance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/RedmineExtension/RedmineInstance.php b/tests/RedmineExtension/RedmineInstance.php index 71aa4130..fcb5b578 100644 --- a/tests/RedmineExtension/RedmineInstance.php +++ b/tests/RedmineExtension/RedmineInstance.php @@ -101,7 +101,7 @@ private function runHealthChecks(RedmineVersion $version): void if ($data === false || $statusCode !== 200) { throw new InvalidArgumentException(sprintf( - 'Could not connect to Redmine server at %s, please make sure that Redmine %s has running a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.', + 'Could not connect to Redmine server at %s, please make sure that Redmine %s has a docker service in /docker-composer.yml and is correctly configured in /tests/Behat/behat.yml.', $this->redmineUrl, $version->asString(), ));