/
azure-pipelines.yml
152 lines (143 loc) · 6.79 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
pr:
- main
trigger:
- main
- release/*
pool:
vmImage: 'windows-latest'
name: $[ variables['branchName'] ]
variables:
solution: 'DbExpression.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
system.debug: true
stageLocationName: db-ex
disable.coverage.autogenerate: 'true'
# Azure Pipelines reports Build.SourceBranchName incorrectly if it has a forward slash in the name (release/foo -> foo). Following expression creates a variable that adheres to the full and complete branch name.
${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/') }}:
branchName: $[ replace(variables['Build.SourceBranch'], 'refs/heads/', '') ]
${{ if startsWith(variables['Build.SourceBranch'], 'refs/pull/') }}:
branchName: $[ replace(variables['System.PullRequest.SourceBranch'], 'refs/heads/', '') ]
parameters:
- name: unitTestMatrix
type: object
default:
# tfm, docker tag, pipeline name
- [ 'net48', '4.8.1', 'net48' ]
- [ 'net8.0', '8.0', 'net8' ]
- name: integrationTestMatrix
type: object
default:
# tfm, docker tag, pipeline name
- [ 'net8.0', '8.0', 'net8' ]
- name: mssqlVersions
type: object
default:
# version, docker tag, pipeline name
- [ '2017', '2017-latest', 'MSSQL2017' ]
- [ '2019', '2019-latest', 'MSSQL2019' ]
- [ '2022', '2022-latest', 'MSSQL2022' ]
stages:
- stage: Build_Package
displayName: 'Build and Package'
jobs:
- job: Build
displayName: 'Build and Package'
steps:
- task: UseDotNet@2
displayName: 'Install .NET 8 SDK'
inputs:
packageType: 'sdk'
# see: https://github.com/dotnet/sdk/pull/29065
# Microsoft introduced a breaking change with 7.0.200 where nuget pack pointing to a sln breaks if --output is specified. Pinning to SDK (not 7.0.*) to mitigate until MS provides documentation
# version: '7.0.102'
- task: PowerShell@2
displayName: 'Build and Package Solution'
inputs:
filePath: '$(Build.SourcesDirectory)/build.ps1'
arguments: '-SolutionPath $(solution) -PublicReleaseBranchName main -Configuration $(buildConfiguration) -BranchName $(branchName) -CommitSHA $(Build.SourceVersion) -PropertiesPath $(Build.SourcesDirectory)/Directory.Build.props -UseBranchNameInPackageSuffixWhenNotSpecified'
workingDirectory: $(Build.SourcesDirectory)
pwsh: true
- publish: $(Build.SourcesDirectory)/assets
displayName: 'Publish NuGet Assets'
artifact: nuget
- publish: $(Build.SourcesDirectory)/test/DbExpression.MsSql.Test.Unit/bin/$(buildConfiguration)
displayName: 'Publish Unit Test Assets'
artifact: unit-test
- task: CopyFiles@2
displayName: 'Copy Build Files'
inputs:
sourceFolder: '$(Build.SourcesDirectory)/build'
contents: '**'
targetFolder: '$(Build.SourcesDirectory)/_build-artifacts/build'
cleanTargetFolder: true
overWrite: true
- task: CopyFiles@2
displayName: 'Copy Build Files'
inputs:
sourceFolder: '$(Build.SourcesDirectory)/test/DbExpression.MsSql.Test.Integration/bin/$(buildConfiguration)'
contents: '**'
targetFolder: '$(Build.SourcesDirectory)/_build-artifacts/bin'
cleanTargetFolder: true
overWrite: true
- publish: $(Build.SourcesDirectory)/_build-artifacts
displayName: 'Publish Integration Test Assets'
artifact: integration-test
- stage: Unit_Test
dependsOn: Build_Package
displayName: 'Unit Test'
jobs:
- ${{ each netVersion in parameters.unitTestMatrix }}:
- job: Unit_Test_${{ netVersion[2] }}
displayName: 'Execute Unit Tests - ${{ netVersion[0] }}'
steps:
- checkout: none
- download: current
artifact: unit-test
- script: |
dotnet test $(Pipeline.Workspace)/unit-test/${{ netVersion[0] }}/DbExpression.MsSql.Test.Unit.dll --logger "trx;LogFileName=$(Pipeline.Workspace)/unit-test/TestResults/${{ netVersion[0] }}.tests.trx"
displayName: 'Execute Unit Tests - ${{ netVersion[0] }}'
- task: PublishTestResults@2
displayName: 'Publish Test Results - ${{ netVersion[0] }}'
inputs:
testResultsFormat: VSTest # MUST be VSTest. If xUnit is used the publish task will report "No Result Found to Publish", even though the file exists
testResultsFiles: $(Pipeline.Workspace)/unit-test/TestResults//${{ netVersion[0] }}.tests.trx
testRunTitle: 'Unit Tests - ${{ netVersion[0] }}'
mergeTestResults: true
failTaskOnFailedTests: true
- stage: Test_MsSql_Integration
pool:
vmImage: 'ubuntu-latest'
dependsOn: Build_Package
displayName: 'Test MSSQL Platforms'
jobs:
- ${{ each netVersion in parameters.integrationTestMatrix }}:
- ${{ each mssqlVersion in parameters.mssqlVersions }}:
- job: Test_${{ mssqlVersion[2] }}_${{ netVersion[2] }}
displayName: '${{ mssqlVersion[2] }} - ${{ netVersion[2] }}'
steps:
- checkout: none
- download: current
artifact: integration-test
- task: PowerShell@2
displayName: 'Create Docker Config Files'
inputs:
filePath: $(Pipeline.Workspace)/integration-test/build/mssql/create-docker-config.ps1
arguments: '-ASSEMBLY_NAME DbExpression.MsSql.Test.Integration.dll -MSSQL_VERSION ${{ mssqlVersion[0] }} -BUILD_CONFIGURATION $(buildConfiguration) -TARGET_FRAMEWORK_MONIKER ${{ netVersion[0] }} -NET_DOCKER_TAG ${{ netVersion[1] }} -MSSQL_DOCKER_TAG ${{ mssqlVersion[1] }} -ROOT_PATH $(Pipeline.Workspace)/integration-test'
workingDirectory: $(Pipeline.Workspace)/integration-test/build/mssql
- task: DockerCompose@0
displayName: 'Execute Tests'
inputs:
containerregistrytype: 'Container Registry'
dockerComposeFile: $(Pipeline.Workspace)/integration-test/docker-compose.yml
action: 'Run a Docker Compose command'
dockerComposeCommand: 'up --abort-on-container-exit'
currentWorkingDirectory: $(Pipeline.Workspace)/integration-test
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: VSTest # MUST be VSTest. If xUnit is used the publish task will report "No Result Found to Publish", even though the file exists
testResultsFiles: $(Pipeline.Workspace)/integration-test/TestResults/${{ netVersion[0] }}.tests.trx
testRunTitle: 'MSSQL ${{ mssqlVersion[0] }} Integration Tests - ${{ netVersion[0] }}'
mergeTestResults: true
failTaskOnFailedTests: true