before_script:
  - VERSION=`cat ./version`
  - RELDATE=`date '+%Y%m%d%H%M'`
  - mkdir -p build || true
  - echo "Host `hostname`, User `id`"

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

stages:
  - before
  - build
  - test
  #  - 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} snapshot
    - chmod a+r qfq_${VERSION}_*.zip
    - echo "mv qfq_${VERSION}_*.zip qfq_${VERSION}_${RELDATE}-${CI_COMMIT_REF_NAME}.zip"
    - mv qfq_${VERSION}_*.zip qfq_${VERSION}_${RELDATE}-${CI_COMMIT_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} release
    - chmod a+r qfq_${VERSION}_*.zip
    - scp qfq_${VERSION}_*.zip w16:qfq/releases/
    - mv qfq_${VERSION}_*.zip build/qfq.zip

  testsnapshot:
    stage: test
    except:
      - tags
    script:
      make phpunit_snapshot
  
  testrelease:
    stage: test
    only:
      - tags
    script:
      make phpunit_release

  #selenium:
  #  stage: selenium
  #  script:
  #    - unzip -q build/qfq.zip -d qfq
  #    - cd docker/
  #    # Required docker images: https://systemvcs.math.uzh.ch/megger/qfq_docker.git
  #    - ./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 -p "$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
    when: on_failure
    paths:
      - extension/Tests/selenium/selenium_logs/



