{SonarOne}

Coming soon to theaters

# CHAPTER 1

Background & Problem

Yuc.Acquisition.BFFs is a monorepo: A code repo containing more than one project.

Yuc.Acquisition.BFFs is a monorepo: A code repo containing more than one project. The problem is it's not possible to mesure code coverage nor setup a quality gate properly

1

Developer submits a PR impacting more than one project

2

PR pipeline is triggered

3

Impacted projects are detected: AutoGrant & Ypay

5

Ypay build is finished and quality report is sent to Sonar

4

Ypay and AutoGrant are built in parallel

6

AutoGrant build is finished and quality report is sent to Sonar

humanity in peril

# CHAPTER 2

Challenges

  1. Conversion Team split
  2. RFC boss says quality is must

Sonar monorepo support

https://docs.sonarcloud.io/advanced-setup/monorepo-support

Convert an existing project

Training the one

Nice, but we don't use monorepos !

name: 1.$(Year:yy).$(DayOfYear)$(Rev:.r)

trigger: none

variables:
  project_name: "Yuc.Project"
  build_configuration: "Release"
  build_platform: "any cpu"

pool:
  name: Pool-Agent-windows
  demands:
    - DotNetFramework

stages:
  - stage: Build
    jobs:
      - job: BuildFront
        workspace:
          clean: all
        variables:
          npm_config_cache: $(Pipeline.Workspace)/.npm-cache
          npm_config_prefix: $(Pipeline.Workspace)/.npm-prefix
        steps:
          - checkout: self
            persistCredentials: true
          - template: ./templates/compute_base_head.yml
          - task: NodeTool@0
            displayName: "Install Node 16.x"
            inputs:
              versionSpec: "16.x"

          - task: Cache@2
            inputs:
              key: "npm-v8 | $(Agent.OS) | Front/package-lock.json"
              restoreKeys: |
                npm-v8 | $(Agent.OS)
                npm-v8
              path: $(npm_config_cache)
            displayName: Cache npm

          - task: Npm@1
            displayName: "npm ci"
            inputs:
              command: ci
              workingDir: "Front"
          - pwsh: |
              $affected = ""
              $affected = npm run nx affected:apps -- --base=$(base) --head=$(head) | Where { $_ -match '( - )([\w-\d_]+)' } | % { "#" + $matches[2] + "#" }        
              $buildFront = $affected -ne $null
              Write-Host "##vso[task.setvariable variable=buildFront;]$buildFront"              
              Write-Host $buildFront
            workingDirectory: "$(Build.SourcesDirectory)/Front"
            displayName: "Compute Affected frontend Apps"
            name: computeAffectedFrontendApps
          - ${{ if contains(variables['buildFront'], 'True') }}:
              - template: build-front.yml
                parameters:
                  npm_config_cache: $(npm_config_cache)
      - job: BuildApi
        workspace:
          clean: all
        steps:
          - checkout: self
            persistCredentials: true
          - template: ./templates/compute_base_head.yml
          - pwsh: |
              try
              {
                dotnet tool install --global dotnet-affected --version 2.0.0-preview-1
                dotnet affected --from $(head) --to $(base)
                $affectedsResult = ""                
                Write-Host 'read affected.proj'
                [XML]$affecteds = Get-Content -Path .\affected.proj
                foreach($affected in $affecteds.Project.ItemGroup.ProjectReference)
                { 
                    $csproj = Split-Path -Path $affected.Include -Leaf -Resolve
                    If( $csproj.Contains(".Api.Front.csproj"))
                    {
                      $sln = $csproj.replace('.csproj','')                      
                      $affectedsResult = -join($affectedsResult, ",", "$sln");                      
                      Write-Host $affectedsResult
                    }
                }
                
                Write-Host $affectedsResult
                $buildApi = $affectedsResult -ne ""
                Write-Host $buildApi
                Write-Host "##vso[task.setvariable variable=buildApi;]$buildApi"
              }
              catch
              {
                Write-Host $affectedsResult
                $buildApi = $affectedsResult -ne ""
                Write-Host $buildApi
                Write-Host "##vso[task.setvariable variable=buildApi;]$buildApi"
                Write-Host 'catch no affected'
              }
              exit(0)
            displayName: "Compute Affected backend Apps"
            name: computeAffectedBackendApps
          - ${{ if contains(variables['buildApi'], 'True') }}:
              - template: build-api.yml
# Finally
Produced by: Conversion Team
Big thanks to our sponsors:
Cedric V.
Etienne D.
Frederico R.

Code

By skible

Code

  • 12