before_script:
  - VERSION=`cat ./version`
  - RELDATE=`date '+%Y%m%d%H%M'`
  - mkdir build || true

variables:
  SELENIUM_LOGS_PATH: "/scratch/tmp/7/"

stages:
  - before
  - build
#   - selenium

documentation:
  stage: before
  script:
    - docker pull t3docs/render-documentation
    - source <(docker run --rm t3docs/render-documentation show-shell-commands)
    - dockrun_t3rd makehtml

snapshot:
  stage: build
  except:
    - tags
  artifacts:
    expire_in: 1 week
    paths:
      - build/
  script:
    - make VERSION=${VERSION} phpunit_snapshot
    - chmod a+r qfq_${VERSION}_*.zip
    - echo "mv qfq_${VERSION}_*.zip qfq_${VERSION}_${RELDATE}-${CI_BUILD_REF_NAME}.zip"
    - mv qfq_${VERSION}_*.zip qfq_${VERSION}_${RELDATE}-${CI_BUILD_REF_NAME}.zip
    - scp qfq_${VERSION}_*.zip w16:qfq/snapshots/
    - mv qfq_${VERSION}_*.zip build/qfq.zip

release:
  stage: build
  only:
    - tags
  artifacts:
    expire_in: 1 week
    paths:
      - build/
  script:
    - make VERSION=${VERSION} phpunit_release
    - chmod a+r qfq_${VERSION}_*.zip
    - scp qfq_${VERSION}_*.zip w16:qfq/releases/
    - mv qfq_${VERSION}_*.zip build/qfq.zip

# selenium:
#   stage: selenium
#   script:
#     - unzip -q build/qfq.zip -d qfq
#     - cd docker/
#     - ./run_qfq_docker.sh -no-deploy
#     - ./deploy_to_container.sh ../qfq
#     - ./run_selenium_tests_docker.sh
#     - echo "hello"
#   after_script:
# #   remove containers and move logs to persistent location
#     - cd docker; ./remove-containers.sh <<< "y"
#     - cd ..
#     - umask 002
#     - mkdir "$SELENIUM_LOGS_PATH/$CI_COMMIT_SHORT_SHA"
#     - cp extension/Tests/selenium/selenium_logs/* "$SELENIUM_LOGS_PATH/$CI_COMMIT_SHORT_SHA/"
#     - echo "Selenium Logs copied to $SELENIUM_LOGS_PATH/$CI_COMMIT_SHORT_SHA/"
#     - echo "Or download result (log/screenshot) in gitlab under CI/CD > Pipelines  <job> > right side 'Artifacts'"

#   artifacts:
#     expire_in: 1 week
#     paths:
#       - extension/Tests/selenium/selenium_logs/