kind: pipeline
name: sonarcube
type: docker

clone:
    retries: 10

steps:
  - name: unity-build-tests
    image: docker.io/library/unity-runner:0.1
    commands:
      - ls
      - /opt/unity/editors/2021.3.19f1/Editor/Unity -batchmode -nographics -projectPath . -executeMethod GitTools.Solution.Sync -quit
      - cat Assembly-CSharp.csproj
      - sed -i 's/v4.7.1/net7.0/g' Assembly-CSharp.csproj
      - cat Assembly-CSharp.csproj
  - name: code-analysis
    pull: if-not-exists
    image: ghcr.io/nosinovacao/dotnet-sonar:latest
    commands:
      # - apt-get update && apt-get install -y unzip
      # - export PATH="$PATH:/root/.dotnet/tools"
      - rm src.sln
      - rm Assembly-CSharp-Editor.csproj
      # - rm Assembly-CSharp.csproj
      - cat Assembly-CSharp.csproj
      - ls
      # - dotnet tool install --global dotnet-sonarscanner
      - dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin /k:"$SONAR_PROJECT_KEY" /d:sonar.host.url="$SONAR_HOST" /d:sonar.login="$SONAR_TOKEN" /d:sonar.branch.name="$DRONE_REPO_BRANCH" /d:sonar.analysis.mode=preview
      - dotnet restore
      - dotnet build
      - dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"

     
    environment:
      SONAR_HOST:
        from_secret: sonar_host
      SONAR_TOKEN:
        from_secret: sonar_token
      SONAR_PROJECT_KEY:
        from_secret: sonar_project_key

trigger:
  event:
    - push
    - pull_request
---
kind: pipeline
name: tests
type: docker

trigger:
  event:
    - push
    - pull_request

steps:
  - name: unity-tests
    image: docker.io/library/unity-runner:0.1
    commands:
      - /opt/unity/editors/2021.3.19f1/Editor/Unity -runTests -batchmode -nographics -projectPath . -testResults results_editmode.xml -testPlatform EditMode || true
      - /opt/unity/editors/2021.3.19f1/Editor/Unity -runTests -batchmode -nographics -projectPath . -testResults results_playmode.xml -testPlatform PlayMode || true
      
  - name: tests-parser
    image: docker.io/library/unity-test-parser:0.1
    commands:
      - python /app/unity_test_parser.py results_editmode.xml results_playmode.xml

---
kind: pipeline
name: builds
type: docker

trigger:
  event:
    - push
    - pull_request

steps:
  - name: unity-builds
    image: docker.io/library/unity-runner:0.1
    commands:
      - /opt/unity/editors/2021.3.19f1/Editor/Unity -batchmode -nographics -projectPath . -buildWindowsPlayer WiiSign.exe -quit --headless
      - /opt/unity/editors/2021.3.19f1/Editor/Unity -batchmode -nographics -projectPath . -buildLinux64Player WiiSign -quit --headless
      - /opt/unity/editors/2021.3.19f1/Editor/Unity -batchmode -nographics -projectPath . -buildOSXUniversalPlayer WiiSign.app -quit --headless
      - curl --request POST --header "PRIVATE-TOKEN:\ ixKiNbp48zzmP5PF-epo" --form "file=WiiSign.exe" "https://gitlab.ilabt.imec.be/api/v4/projects/4583/uploads"
