
variables:
  NIXOS_VERSION: "23.11"
  NIXPKGS_ALLOW_UNFREE: "1"
  NIXPKGS_ALLOW_INSECURE: "1"
  GIT_DEPTH: 10

stages:
  - test
  - release
  - deploy 

before_script:
  - git config --global user.email "${GITLAB_USER_EMAIL}"
  - git config --global user.name "${GITLAB_USER_NAME}"
  - git config --global credential.helper '!f() { echo "username=gitlab-ci-token"; echo "password=${CI_JOB_TOKEN}"; }; f'
  - git config --global pull.rebase true
  - git config --global http.sslVerify "false"

after_script:
  - nix develop .#gitlab --command clean-up

tests:
  stage: test
  tags:
    - nixos-gen3
  script:
    - nix develop .#gitlab --command run-ci-tests
  cache:
    untracked: true
    key:
      files:
        - package
    paths:
      - node_modules/
  rules:
    - if: $DEPLOY_VERSION == null

web-tests:
  stage: test
  tags:
    - nixos-gen3
  script:
    - nix --version
    - nix develop .#gitlab --command run-ci-web-tests
  cache:
    untracked: true
    key:
      files:
        - package-lock.json
    paths:
      - node_modules/
  artifacts:
    paths:
      - screenshot.png
  rules:
    - if: $DEPLOY_VERSION == null

release:
  stage: release
  tags:
    - nixos-gen3
  script:
    - nix develop .#gitlab --command release
  when: on_success
  rules:
    - if: $DEPLOY_VERSION == null && $CI_COMMIT_BRANCH == "master"
      
deploy:
  stage: deploy
  tags:
    - nixos-gen3
  script:
    - nix develop .#gitlab --command deploy
  when: on_success
  rules:
    - if: $DEPLOY_VERSION && $CI_COMMIT_TAG 
      when: always
  