variables:
  DOCROOT: "${CI_PROJECT_DIR}/vendor/mink/driver-testsuite/web-fixtures"
  CHROME_DEBUG_URL: http://localhost:9222

stages:
  - lint
  - test

.test_template:
  stage: test
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
    - if: '$CI_PIPELINE_SOURCE == "web"'
  tags: [docker]
  retry: 2
  script:
    - bin/wait-for-chrome.sh
    - curl -s http://localhost:9222/json/version
    - composer install -o --prefer-dist --ansi --no-progress
    - test -z "${AUTOSTART_XVFB}" || sed -i '27s#^#//#' vendor/mink/driver-testsuite/tests/Basic/BasicAuthTest.php
    - vendor/bin/phpunit --colors=always --log-junit junit.xml
  needs: []
  artifacts:
    paths:
      - junit.xml
    reports:
      junit:
        - junit.xml

Changelog:
  image: composer
  stage: lint
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
  allow_failure: true
  script:
    - git fetch
    - FILES_CHANGED=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA...HEAD)
    - |+
      for i in $FILES_CHANGED
      do
        if [[ "$i" == "CHANGELOG.md" ]]
        then
          exit 0
        fi
      done
      echo -e "⚠️\e[93m CHANGELOG.md is not updated in this MR, please add a CHANGELOG entry"
      echo -e "⚠️\e[93m (or an explanatory comment in MR if it's not CHANGELOG-worthy)"
      exit 1

GrumPHP:
  image: composer
  stage: lint
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
    - if: '$CI_PIPELINE_SOURCE == "web"'
  tags: [docker]
  script:
    - composer require --dev --prefer-dist --ansi --no-progress --sort-packages phpro/grumphp-shim ergebnis/composer-normalize enlightn/security-checker
    - vendor/bin/grumphp run -n

PHP 7.4:
  extends: .test_template
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless:7.4

PHP 8.0:
  extends: .test_template
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless:8.0

PHP 8.1:
  extends: .test_template
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless:8.1

PHP 8.2:
  extends: .test_template
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless:8.2

Chromium:
  extends: .test_template
  variables:
    CHROME_BUILD: chromium
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless

Chrome unstable:
  extends: .test_template
  variables:
    CHROME_BUILD: google-chrome-unstable
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless

Chrome beta:
  extends: .test_template
  variables:
    CHROME_BUILD: google-chrome-beta
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless

Headed:
  extends: .test_template
  variables:
    AUTOSTART_XVFB: "true"
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless

Headed chrome unstable:
  extends: .test_template
  variables:
    AUTOSTART_XVFB: "true"
    CHROME_BUILD: google-chrome-unstable
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless

Headed chrome beta:
  extends: .test_template
  variables:
    AUTOSTART_XVFB: "true"
    CHROME_BUILD: google-chrome-beta
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless

Headed chromium:
  extends: .test_template
  variables:
    AUTOSTART_XVFB: "true"
    CHROME_BUILD: chromium
  image: registry.gitlab.com/behat-chrome/docker-chrome-headless
