diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 58b212f4..35a90370 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,53 +37,74 @@ jobs: - name: Run tests run: composer run phpunit -- --no-coverage - # This does not work - # behat: - # name: Tests (Behat with PHP ${{ matrix.php }}) - # runs-on: ubuntu-latest - - # services: - # redmine-6-0: - # image: redmine:6.0.7 - # ports: - # - "5060:3000" - # env: - # # Workaround: Remove secret for Rails 7.2 so it will be generated automatically - # # @see https://github.com/docker-library/redmine/issues/349#issuecomment-2516634932 - # # REDMINE_SECRET_KEY_BASE: supersecretkey - # REDMINE_PLUGINS_MIGRATE: true - # volumes: - # - /home/runner/work/_temp/redmine-60007_data/files:/usr/src/redmine/files - # - /home/runner/work/_temp/redmine-60007_data/sqlite:/usr/src/redmine/sqlite - # options: --health-cmd="wget -O /dev/null http://localhost:3000" --health-start-period=30s --health-interval=30s --health-timeout=30s --health-retries=3 - - # strategy: - # fail-fast: false - # matrix: - # operating-system: ["ubuntu-latest"] - # php: ["8.3"] - - # steps: - # - name: Checkout - # uses: actions/checkout@v4 - # with: - # fetch-depth: 2 - - # - name: Setup PHP, with composer and extensions - # uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php - # with: - # php-version: ${{ matrix.php }} - # tools: phpunit - # extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite - # coverage: xdebug - - # # Install composer dependencies and handle caching in one go. - # # @link https://github.com/marketplace/actions/install-composer-dependencies - # - name: "Install Composer dependencies" - # uses: "ramsey/composer-install@v2" - - # - name: Run behat - # run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --suite=redmine_6_0 + behat: + 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: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: phpunit + extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, curl + coverage: xdebug + + - name: Install Composer dependencies + uses: ramsey/composer-install@v2 + + - name: Create data directories + run: | + mkdir -p .docker/redmine-60101_data/{files,sqlite} + mkdir -p .docker/redmine-60008_data/{files,sqlite} + mkdir -p .docker/redmine-50111_data/{files,sqlite} + chmod -R 777 .docker/redmine-*_data/ + + - name: Start Redmine containers + run: docker compose up -d redmine-6-1 redmine-6-0 redmine-5-1 + + - name: Wait for Redmine instances to be healthy + run: | + for i in $(seq 1 60); do + if curl -sf http://localhost:5061 > /dev/null 2>&1 && \ + curl -sf http://localhost:5060 > /dev/null 2>&1 && \ + curl -sf http://localhost:5051 > /dev/null 2>&1; then + echo "All Redmine instances are ready" + exit 0 + fi + echo "Waiting for Redmine instances... ($i/60)" + sleep 5 + done + echo "Redmine instances did not become ready in time" + docker compose logs redmine-6-1 redmine-6-0 redmine-5-1 + exit 1 + + - name: Fix permissions + run: sudo chmod -R 777 .docker/redmine-*_data/ + + - name: Run behat [Redmine 6.1] + run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --format=progress --suite=redmine_6_1 + + - name: Run behat [Redmine 6.0] + run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --format=progress --suite=redmine_6_0 + + - name: Run behat [Redmine 5.1] + run: vendor/bin/behat --config tests/Behat/behat.yml --profile=github-actions --format=progress --suite=redmine_5_1 + + - name: Cleanup + if: always() + run: docker compose down -v code-quality: name: Check ${{ matrix.tool }} (PHP ${{ matrix.php }}) diff --git a/tests/Behat/Bootstrap/FeatureContext.php b/tests/Behat/Bootstrap/FeatureContext.php index 7718312d..3a6caf10 100644 --- a/tests/Behat/Bootstrap/FeatureContext.php +++ b/tests/Behat/Bootstrap/FeatureContext.php @@ -84,7 +84,7 @@ public static function clean(AfterSuiteScope $scope): void */ private array $lastReturnAsArray; - public function __construct(string $redmineVersion, string $rootPath) + public function __construct(string $redmineVersion, string $rootPath, ?string $redmineUrl = null) { $version = RedmineVersion::tryFrom($redmineVersion); @@ -92,7 +92,7 @@ public function __construct(string $redmineVersion, string $rootPath) throw new InvalidArgumentException('Redmine ' . $redmineVersion . ' is not supported.'); } - $this->redmine = self::$tracer::getRedmineInstance($version, $rootPath); + $this->redmine = self::$tracer::getRedmineInstance($version, $rootPath, $redmineUrl); } /** diff --git a/tests/Behat/behat.yml b/tests/Behat/behat.yml index d2da111c..157409dd 100644 --- a/tests/Behat/behat.yml +++ b/tests/Behat/behat.yml @@ -29,14 +29,17 @@ github-actions: contexts: - Redmine\Tests\Behat\Bootstrap\FeatureContext: redmineVersion: '6.1.1' - rootPath: '/home/runner/work/_temp' + rootPath: '%paths.base%/../../.docker' + redmineUrl: 'http://localhost:5061' redmine_6_0: contexts: - Redmine\Tests\Behat\Bootstrap\FeatureContext: redmineVersion: '6.0.8' - rootPath: '/home/runner/work/_temp' + rootPath: '%paths.base%/../../.docker' + redmineUrl: 'http://localhost:5060' redmine_5_1: contexts: - Redmine\Tests\Behat\Bootstrap\FeatureContext: redmineVersion: '5.1.11' - rootPath: '/home/runner/work/_temp' + rootPath: '%paths.base%/../../.docker' + redmineUrl: 'http://localhost:5051' diff --git a/tests/RedmineExtension/BehatHookTracer.php b/tests/RedmineExtension/BehatHookTracer.php index 58c8571f..94019756 100644 --- a/tests/RedmineExtension/BehatHookTracer.php +++ b/tests/RedmineExtension/BehatHookTracer.php @@ -19,14 +19,14 @@ final class BehatHookTracer implements InstanceRegistration */ private static array $instances = []; - public static function getRedmineInstance(RedmineVersion $redmineVersion, string $rootPath): RedmineInstance + public static function getRedmineInstance(RedmineVersion $redmineVersion, string $rootPath, ?string $redmineUrl = null): RedmineInstance { if (!self::$tracer instanceof \Redmine\Tests\RedmineExtension\BehatHookTracer) { throw new RuntimeException('You can only get a Redmine instance while a Behat Suite is running.'); } if (! array_key_exists($redmineVersion->asId(), self::$instances)) { - RedmineInstance::create(self::$tracer, $redmineVersion, $rootPath); + RedmineInstance::create(self::$tracer, $redmineVersion, $rootPath, $redmineUrl); } return self::$instances[$redmineVersion->asId()]; diff --git a/tests/RedmineExtension/RedmineInstance.php b/tests/RedmineExtension/RedmineInstance.php index 082136a9..0964cbd3 100644 --- a/tests/RedmineExtension/RedmineInstance.php +++ b/tests/RedmineExtension/RedmineInstance.php @@ -14,9 +14,9 @@ final class RedmineInstance /** * @param InstanceRegistration $tracer Required to ensure that RedmineInstance is created while Test Runner is running */ - public static function create(InstanceRegistration $tracer, RedmineVersion $version, string $rootPath): void + public static function create(InstanceRegistration $tracer, RedmineVersion $version, string $rootPath, ?string $redmineUrl = null): void { - $tracer->registerInstance(new self($tracer, $version, $rootPath)); + $tracer->registerInstance(new self($tracer, $version, $rootPath, $redmineUrl)); } private InstanceRegistration $tracer; @@ -41,7 +41,7 @@ public static function create(InstanceRegistration $tracer, RedmineVersion $vers private string $apiKey; - private function __construct(InstanceRegistration $tracer, RedmineVersion $version, string $rootPath) + private function __construct(InstanceRegistration $tracer, RedmineVersion $version, string $rootPath, ?string $redmineUrl = null) { $this->tracer = $tracer; $this->version = $version; @@ -65,7 +65,7 @@ private function __construct(InstanceRegistration $tracer, RedmineVersion $versi $parts = explode('.', $version->asString()); - $this->redmineUrl = 'http://redmine-' . intval($parts[0]) . '-' . intval($parts[1]) . ':3000'; + $this->redmineUrl = $redmineUrl ?? ('http://redmine-' . intval($parts[0]) . '-' . intval($parts[1]) . ':3000'); $this->apiKey = sha1($versionId . time()); $this->runHealthChecks($version);