Skip to content

Commit

Permalink
Azure Pipelines (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovation22 authored Aug 29, 2023
1 parent a4c2ae9 commit bf6571b
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .azuredevops/pipelines/api-pipeline.yml
Original file line number Diff line number Diff line change
@@ -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'
36 changes: 36 additions & 0 deletions .azuredevops/pipelines/templates/api-cd.yml
Original file line number Diff line number Diff line change
@@ -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'
100 changes: 100 additions & 0 deletions .azuredevops/pipelines/templates/api-ci.yml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit bf6571b

Please sign in to comment.