default:
  # Guide the choice of an appropriate runner for all these jobs.
  # https://docs.gitlab.com/ee/ci/runners/#runner-runs-only-tagged-jobs
  tags:
    - "nixos"
    - "shell"

docs:
  stage: "build"
  script:
    - "nix-shell --run 'nix-build docs.nix'"
    - "cp --recursive --no-preserve=mode result/docs/. docs/build/"
  artifacts:
    paths:
      - "docs/build/index.html"
    expose_as: "documentation"

unit-tests:
  stage: "test"
  script:
    - "nix-shell --run 'nix-build nixos/unit-tests.nix' && cat result"

vulnerability-scan:
  stage: "test"
  script:
    - "ci-tools/vulnerability-scan security-report.json"
    - "ci-tools/count-vulnerabilities <security-report.json"
  artifacts:
    paths:
      - "security-report.json"
    expose_as: "security report"


system-tests:
  stage: "test"
  timeout: "3 hours"
  script:
    - "nix-shell --run 'nix-build nixos/system-tests.nix'"

deploy-to-staging:
  stage: "deploy"
  only:
    - "staging"
  environment:
    name: "staging"
    url: "https://privatestorage-staging.com/"
  script:
    - echo "Hello $GITLAB_USER_LOGIN from $CI_JOB_NAME. I was triggered by $CI_PIPELINE_SOURCE "
    - echo "and would like to deploy the $CI_COMMIT_BRANCH branch to the $CI_ENVIRONMENT_NAME environment."

deploy-to-production:
  stage: "deploy"
  only:
    - "production"
  environment:
    name: "production"
    url: "https://privatestorage.io/"
  script:
    - echo "Hello $GITLAB_USER_LOGIN from $CI_JOB_NAME. I was triggered by $CI_PIPELINE_SOURCE "
    - echo "and would like to deploy the $CI_COMMIT_BRANCH branch to the $CI_ENVIRONMENT_NAME environment."
