|
| 1 | +parameters: |
| 2 | + buildConfiguration: 'Release' |
| 3 | + nugetFeed: '' |
| 4 | + name: 'Tailspin.SpaceGame.Web' |
| 5 | + vmImage: 'ubuntu-latest' |
| 6 | + projectFile: '**/Tailspin.SpaceGame.Web.csproj' |
| 7 | + runDotNetCoreTests: true |
| 8 | + |
| 9 | +jobs: |
| 10 | + |
| 11 | +- job: build |
| 12 | + displayName: build ${{ parameters.name }} |
| 13 | + variables: |
| 14 | + # Use the latest reportgenerator for code coverage |
| 15 | + disable.coverage.autogenerate: 'true' |
| 16 | + pool: |
| 17 | + vmImage: '${{ parameters.vmImage }}' |
| 18 | + |
| 19 | + steps: |
| 20 | + |
| 21 | + - checkout: self |
| 22 | + |
| 23 | + # - task: VersionAssemblies@2 |
| 24 | + # inputs: |
| 25 | + # sourcePath: '$(Build.SourcesDirectory)' |
| 26 | + # filePattern: '**/AssemblyInfo.*' |
| 27 | + # versionSource: 'buildNumber' |
| 28 | + # versionFormat: 'fourParts' |
| 29 | + # replaceVersionFormat: 'fourParts' |
| 30 | + |
| 31 | + - task: DotNetCoreCLI@2 |
| 32 | + displayName: 'dotnet restore' |
| 33 | + inputs: |
| 34 | + command: 'restore' |
| 35 | + projects: '${{ parameters.projectFile }}' |
| 36 | + vstsFeed: '${{ parameters.nugetFeed }}' |
| 37 | + |
| 38 | + - task: DotNetCoreCLI@2 |
| 39 | + displayName: 'dotnet build' |
| 40 | + inputs: |
| 41 | + command: 'build' |
| 42 | + projects: '${{ parameters.projectFile }}' |
| 43 | + arguments: '--configuration ${{ parameters.buildConfiguration }} /p:Version=$(build.buildnumber)' |
| 44 | + |
| 45 | + - ${{ if eq(parameters.runDotNetCoreTests, 'true') }}: |
| 46 | + # Run tests - ensure `coverlet.msbuild` nuget package is added on each test project for code coverage |
| 47 | + # This should run on windows+ubuntu |
| 48 | + # If only cared about windows and were okay with downloading a .coverage file instead of inline results, remove the /p: arguments and just used '--collect "Code coverage"' |
| 49 | + # Sept 22 20: updated code coverage to be less flaky - old: /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura' . See: https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/KnownIssues.md#1-vstest-stops-process-execution-earlydotnet-test |
| 50 | + # With new version, we are using 'coverlet.collector' NuGet package instead |
| 51 | + - task: DotNetCoreCLI@2 |
| 52 | + displayName: 'dotnet test' |
| 53 | + inputs: |
| 54 | + command: test |
| 55 | + projects: '**/*[Tt]ests/*.csproj' |
| 56 | + publishTestResults: true |
| 57 | + arguments: '--collect:"XPlat Code Coverage"' |
| 58 | + |
| 59 | + # Run the report generator for just the app |
| 60 | + - task: reportgenerator@4 |
| 61 | + inputs: |
| 62 | + reports: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml;$(Pipeline.Workspace)/**/Cobertura.xml;$(Agent.WorkFolder)/**/coverage.cobertura.xml' |
| 63 | + targetdir: '$(Build.ArtifactStagingDirectory)/CoverageResults' |
| 64 | + # |
| 65 | + |
| 66 | + # Download all CoverageResults for all pipeline jobs |
| 67 | + - download: 'current' |
| 68 | + patterns: '**/CoverageResults/**' |
| 69 | + |
| 70 | + - task: reportgenerator@4 |
| 71 | + inputs: |
| 72 | + reports: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml;$(Pipeline.Workspace)/**/Cobertura.xml;$(Agent.WorkFolder)/**/coverage.cobertura.xml' |
| 73 | + targetdir: '$(Pipeline.Workspace)/CoverageResults' |
| 74 | + |
| 75 | + - task: PublishCodeCoverageResults@1 |
| 76 | + displayName: 'Publish code coverage report' |
| 77 | + inputs: |
| 78 | + codeCoverageTool: 'Cobertura' |
| 79 | + summaryFileLocation: '$(Pipeline.Workspace)/CoverageResults/Cobertura.xml' |
| 80 | + reportDirectory: '$(Pipeline.Workspace)/CoverageResults' |
| 81 | + |
| 82 | + - task: reportgenerator@4 |
| 83 | + displayName: 'Converting coverage file to sonarqube format' |
| 84 | + inputs: |
| 85 | + reports: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml;$(Pipeline.Workspace)/**/Cobertura.xml;$(Agent.WorkFolder)/**/coverage.cobertura.xml' |
| 86 | + targetdir: '$(Agent.TempDirectory)' |
| 87 | + reporttypes: 'SonarQube' |
| 88 | + |
| 89 | + - task: DotNetCoreCLI@2 |
| 90 | + displayName: 'dotnet publish' |
| 91 | + inputs: |
| 92 | + command: 'publish' |
| 93 | + publishWebProjects: false |
| 94 | + projects: '${{ parameters.projectFile }}' |
| 95 | + zipAfterPublish: true |
| 96 | + arguments: '--configuration ${{ parameters.buildConfiguration }} --output $(build.artifactstagingdirectory) /p:Version=$(build.buildnumber)' |
| 97 | + |
| 98 | + - publish: '$(Build.ArtifactStagingDirectory)' |
| 99 | + artifact: ${{ parameters.name }} |
0 commit comments