# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence

stages:
  - build
  - test

sast:
  stage: test
include:
- template: Security/SAST.gitlab-ci.yml

image: ubuntu:focal

linux:build:
  only:
    - main
    - merge_requests
  
  stage: build
  tags:
    - docker

  script:
    - mkdir build && cd build
    - cmake $CI_PROJECT_DIR -GNinja -DCMAKE_CXX_FLAGS="-fdiagnostics-color" -DUSE_CPPCHECK=FALSE -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR=DEB
    - ninja

  cache: # use artifacts instead if multiple runners available
    key: $CI_COMMIT_SHORT_SHA
    paths:
      - build/

linux:test:
  only:
    - master
    - merge_requests

  stage: test
  tags:
    - linux
  
  needs: ["linux:build"]
  script:
    - cd build
    - ctest -V --output-junit report.xml

  artifacts:
    when: always
    reports:
      junit: build/report.xml

  cache:
    key: $CI_COMMIT_SHORT_SHA
    paths:
      - build/

### Windows

#windows:build:
#  only:
#    - main
#    - merge_requests

#  stage: build
#  tags:
#    - windows

#  cache: # use artifacts instead if multiple runners available
#    key: $CI_COMMIT_SHORT_SHA
#    paths:
#      - build/

#  script:
#      - Import-Module "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll"
#      - Enter-VsDevShell -VsInstallPath "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/"
#      - cd $CI_PROJECT_DIR
#      - if (Test-Path build) { Remove-Item build/ -Recurse }
#      - mkdir build
#      - cd build
#      - cmake -DCMAKE_GENERATOR_PLATFORM=x64 -DWITH_GNUTLS=TRUE -DGNUTLS_INCLUDE_DIR="C:/Build/bin/gnutls/lib/includes/" -DGNUTLS_LIBRARY="C:/Build/bin/gnutls/lib/libgnutls.dll.a" ..
#      - '& MSBuild.exe beyond-ftl.sln -property:Configuration=Release -nr:false -maxCpuCount'

#windows:test:
#  only:
#    - master
#    - merge_requests
  
#  stage: test

#  tags:
#    - windows
#  needs: ["windows:build"]

#  cache: # use artifacts instead if multiple runners available
#    key: $CI_COMMIT_SHORT_SHA
#    paths:
#      - build/

#  script:
#    - $env:PATH+=";C:/Shared/Deploy"
#    - cd build
#    - ctest -V --output-on-failure --timeout 60
