#This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
#© Copyright Utrecht University (Department of Information and Computing Sciences)

image: golang:1.16

stages:
  - test

unit_tests:
  stage: test
  script:
    - make dep
    - make test
    - gocover-cobertura < coverage.txt > coverage.xml
  artifacts:
    reports:
      cobertura: coverage.xml

coverage:
  stage: test
  script:
    - make coverage
  after_script:
    - mkdir $CI_COMMIT_BRANCH
    - cp cover.html $CI_COMMIT_BRANCH
    - mv $CI_COMMIT_BRANCH/cover.html $CI_COMMIT_BRANCH/index.html

    - if [[ $CI_COMMIT_BRANCH = "develop" || $CI_COMMIT_BRANCH = "main" ]]; then COVERAGE_PATH=""; else COVERAGE_PATH="features"; fi

    # install openssh client and add ssh keys
    - apt-get install openssh-client curl -y >/dev/null
    - mkdir ~/.ssh/
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - ssh-add ~/.ssh/id_rsa
    - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - ssh -fN -L 1234:science-vs260.science.uu.nl:22 sivan@up.science.uu.nl
    - scp -r -o StrictHostKeyChecking=no -P 1234 -i ~/.ssh/id_rsa $CI_COMMIT_BRANCH root@localhost:/datadisk/documentation-coverage/home/backend/$CI_PROJECT_NAME/$COVERAGE_PATH
  artifacts:
    untracked: false
    expire_in: 30 days
    paths:
      - cover.html