kind: pipeline
type: docker
name: MineGuide_CI_Pipeline

trigger:
  branch:
    - develop
  event:
    - push

steps:
  #Build pour la version avec les vues (plusieurs minutes)
  #- name: build_maui
  #  image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest
  #  commands:
  #    - cd Sources/
  #    - dotnet restore MineGuide.sln
  #    - dotnet build MineGuide.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0
  #    - dotnet publish Vues/Vues.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk
  #  depends_on: [clone]

  #Build pour la version sans les vues (quelques secondes)
  - name: build_net7
    image: mcr.microsoft.com/dotnet/sdk:7.0
    commands:
      - cd Sources/
      - dotnet restore MineGuide_linuxOnly.sln
      - dotnet build MineGuide_linuxOnly.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0
      - dotnet publish MineGuide_linuxOnly.sln -c Release --no-restore -o $CI_PROJECT_DIR/build/release
    depends_on: [clone]

  #Tests après les build(s)
  - name: tests
    image: mcr.microsoft.com/dotnet/sdk:7.0
    commands:
      - cd Sources/
      - dotnet restore MineGuide_linuxOnly.sln
      - dotnet test MineGuide_linuxOnly.sln --no-restore
    depends_on: [build_net7]

  #Déploiement de la CI sur Sonar (Inspection de code)
  - name: code-inspection-linux-only
    image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7
    secrets: [ SECRET_SONAR_LOGIN ]
    environment:
      sonar_host: https://codefirst.iut.uca.fr/sonar/
      sonar_token:
        from_secret: SECRET_SONAR_LOGIN
      project_key: MineGuide101
      coverage_exclusions: "Tests/**"
    commands:
      - cd Sources/
      - dotnet restore MineGuide_linuxOnly.sln
      - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} 
      - dotnet build MineGuide_linuxOnly.sln -c Release --no-restore
      - dotnet test MineGuide_linuxOnly.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage"
      - reportgenerator -reports:'**/coverage.cobertura.xml' -reporttypes:SonarQube -targetdir:"coveragereport" -verbosity:Verbose
      - dotnet publish MineGuide_linuxOnly.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release
      - dotnet sonarscanner end /d:sonar.login=$${sonar_token}
    branch:
      - develop
    depends_on: [tests]