diff --git a/.azuredevops/pipelines/api-pipeline.yml b/.azuredevops/pipelines/api-pipeline.yml new file mode 100644 index 0000000..78ec838 --- /dev/null +++ b/.azuredevops/pipelines/api-pipeline.yml @@ -0,0 +1,39 @@ +name: api.project.template.$(Date:yyyy.MM.dd).$(Rev:rr) + +trigger: + branches: + include: + - main + +pr: + branches: + include: + - main + +parameters: + +- name: configuration + displayName: 'Build Configuration' + default: 'Release' + type: string + values: + - 'Release' + - 'Debug' + +- name: benchmarks + displayName: 'Run the Benchmark tests?' + default: false + type: boolean + +stages: + +- template: 'templates/api-ci.yml' + parameters: + configuration: ${{parameters.configuration}} + benchmarks: ${{parameters.benchmarks}} + +- ${{ if ne(variables['Build.Reason'], 'PullRequest')}}: + - template: 'templates/api-cd.yml' + parameters: + environment: 'Dev' + serviceConnection: 'TODO' \ No newline at end of file diff --git a/.azuredevops/pipelines/templates/api-cd.yml b/.azuredevops/pipelines/templates/api-cd.yml new file mode 100644 index 0000000..81e5268 --- /dev/null +++ b/.azuredevops/pipelines/templates/api-cd.yml @@ -0,0 +1,36 @@ +parameters: + +- name: environment + type: string + default: 'Dev' + +- name: serviceConnection + type: string + +stages: + - stage: 'deploy_${{parameters.environment}}' + displayName: 'Deploy to ${{upper(parameters.environment)}}' + pool: + vmImage: ubuntu-20.04 + + jobs: + - deployment: 'deploy_${{parameters.environment}}' + displayName: 'Deploy to ${{upper(parameters.environment)}}' + workspace: + clean: all + environment: '${{parameters.environment}}' + strategy: + runOnce: + deploy: + steps: + - checkout: none + - download: current + artifact: 'drop' + - task: AzureWebApp@1 + displayName: 'Deploy .NET Web App to App Service' + inputs: + appType: 'webAppLinux' + azureSubscription: '${{parameters.serviceConnection}}' + appName: 'TODO-${{parameters.environment}}' + package: '$(Pipeline.Workspace)/drop/Api.Project.Template.Api.zip' + startUpCommand: 'dotnet Api.Project.Template.Api.dll' \ No newline at end of file diff --git a/.azuredevops/pipelines/templates/api-ci.yml b/.azuredevops/pipelines/templates/api-ci.yml new file mode 100644 index 0000000..fb99638 --- /dev/null +++ b/.azuredevops/pipelines/templates/api-ci.yml @@ -0,0 +1,100 @@ +parameters: + +- name: configuration + displayName: 'Build Configuration' + type: string + values: + - 'Release' + - 'Debug' + +- name: benchmarks + displayName: 'Build.Reason' + pool: + vmImage: ubuntu-20.04 + +jobs: +- job: build + displayName: 'Build and Test' + steps: + - checkout: self + + - task: UseDotNet@2 + displayName: 'Use .NET Core SDK 7.0.x' + inputs: + packageType: 'sdk' + version: '7.0.x' + + - task: DotNetCoreCLI@2 + displayName: 'Restore' + inputs: + command: 'restore' + projects: '**/*.csproj' + feedsToUse: 'select' + verbosityRestore: 'quiet' + + - task: DotNetCoreCLI@2 + displayName: 'Build' + inputs: + command: 'build' + projects: '**/*.csproj' + arguments: '--configuration ${{parameters.configuration}} --no-restore' + + - task: DotNetCoreCLI@2 + displayName: 'Run Unit, Integration, and Architecture tests - ${{parameters.configuration}}' + inputs: + command: 'test' + projects: '**/*.csproj' + arguments: '--configuration ${{parameters.configuration}} /p:CollectCoverage=true --collect:"XPlat Code Coverage" /p:CoverletOutputFormat=opencover' + nobuild: true + + - script: | + dotnet tool install -g dotnet-reportgenerator-globaltool --ignore-failed-sources + reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:Cobertura + condition: succeededOrFailed() + displayName: 'Create Code Coverage Report' + + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Code Coverage Results' + condition: succeededOrFailed() + inputs: + codeCoverageTool: 'Cobertura' + summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml' + pathToSources: '$(Build.SourcesDirectory)' + + - task: DotNetCoreCLI@2 + displayName: 'Run Benchmarks' + condition: eq('${{parameters.benchmarks}}', true) + inputs: + command: 'run' + projects: '**/Api.Project.Template.Tests.Benchmark.csproj' + arguments: '--configuration Release no-build $(Build.SourcesDirectory)/BenchmarkDotNet.Artifacts' + + - task: PublishBuildArtifacts@1 + displayName: 'Publish Benchmark Results' + condition: eq('${{parameters.benchmarks}}', true) + inputs: + artifactName: 'Benchmarks' + PathToPublish: '$(Build.SourcesDirectory)/BenchmarkDotNet.Artifacts/results' + + - task: publishhtmlreport@1 + displayName: 'Publish Benchmark Report' + condition: eq('${{parameters.benchmarks}}', true) + inputs: + tabName: 'Benchmarks' + htmlType: 'genericHTML' + htmlPath: '$(Build.SourcesDirectory)/BenchmarkDotNet.Artifacts/results/Api.Project.Template.Tests.Benchmark.LoggingBenchmarks-report.html' + + - task: DotNetCoreCLI@2 + displayName: 'DotNet Publish' + inputs: + command: 'publish' + publishWebProjects: true + arguments: '--configuration ${{parameters.configuration}} -r "linux-x64" --self-contained false --output $(Build.ArtifactStagingDirectory)' + zipAfterPublish: true + + - task: PublishPipelineArtifact@1 + displayName: 'Publish Artifacts' + inputs: + path: '$(Build.ArtifactStagingDirectory)' + targetpath: '$(Pipeline.Workspace)/' + artifactName: 'drop'