-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
183 lines (178 loc) · 6.59 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
trigger: none
pool:
vmImage: 'ubuntu-latest'
parameters:
- name: SELECTED_PACKAGE_VERSION
type: string
displayName: 'Package Version'
default: 'not-set'
- name: "INCREASE_MAJOR"
type: boolean
default: false
displayName: "Increase Major Version"
- name: "INCREASE_MINOR"
type: boolean
default: false
displayName: "Increase Minor Version"
- name: "INCREASE_PATCH"
type: boolean
default: false
displayName: "Increase Patch Version"
variables:
BUILD_CONFIGURATION: 'Release'
PROJECT_OUT_PATH: '$(Build.ArtifactStagingDirectory)'
SAMPLES_DIR: $(Build.SourcesDirectory)/samples
MIGRATIO_DIRECTORY: $(Pipeline.Workspace)/Migratio
PACKAGE_NAME: 'Migratio'
isMaster: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]
resources:
containers:
- container: postgresDbEnv1
image: 'postgres'
ports:
- 127.0.0.1:5433:5432
env:
POSTGRES_USER: pguserenv1
POSTGRES_PASSWORD: pgpassenv1
POSTGRES_DB: EnvOneDb
- container: postgresDbEnv2
image: 'postgres'
ports:
- 127.0.0.1:5434:5432
env:
POSTGRES_USER: pguserenv2
POSTGRES_PASSWORD: pgpassenv2
POSTGRES_DB: EnvTwoDb
stages:
- stage: buildAndUnitTest
displayName: 'Build & Test'
jobs:
- job: 'Build'
displayName: 'Build job'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DotNetCoreCLI@2
displayName: 'Restore project dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build the project - $(BUILD_CONFIGURATION)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(BUILD_CONFIGURATION)'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Run Tests'
inputs:
command: 'test'
projects: '**/*Tests/*UnitTests.csproj'
arguments: '--configuration $(BUILD_CONFIGURATION) --collect "Code coverage"'
- stage: publishArtifact
displayName: 'Publish Artifact'
dependsOn: buildAndUnitTest
jobs:
- job:
steps:
- task: DotNetCoreCLI@2
displayName: 'Publish Code - $(BUILD_CONFIGURATION)'
inputs:
command: 'publish'
publishWebProjects: false
projects: '$(Build.SourcesDirectory)/src/Migratio/Migratio.csproj'
arguments: '--configuration $(BUILD_CONFIGURATION) --output $(PROJECT_OUT_PATH)/source'
zipAfterPublish: false
modifyOutputPath: false
- task: PowerShell@2
displayName: 'Set package version'
name: SetVersion
inputs:
filePath: '$(Build.SourcesDirectory)/ci/get-updated-package-version.ps1'
arguments: '-IncreaseMajor $${{ parameters.INCREASE_MAJOR }} -IncreaseMinor $${{ parameters.INCREASE_MINOR }} -IncreasePatch $${{ parameters.INCREASE_PATCH }} -SelectedVersion ${{ parameters.SELECTED_PACKAGE_VERSION }} -PackageName $(PACKAGE_NAME)'
failOnStderr: true
showWarnings: true
pwsh: true
- task: DotNetCoreCLI@2
displayName: 'Pack Nuget - $(BUILD_CONFIGURATION)'
inputs:
command: 'pack'
packagesToPack: '$(Build.SourcesDirectory)/src/Migratio/Migratio.csproj'
configuration: '$(BUILD_CONFIGURATION)'
packDirectory: '$(Build.ArtifactStagingDirectory)/nuget'
nobuild: true
versioningScheme: 'byEnvVar'
versionEnvVar: 'SETVERSION_UPDATED_PACKAGE_VERSION'
- task: PublishPipelineArtifact@1
displayName: 'Publish Binaries Artifact'
inputs:
artifact: 'migratio-binaries'
targetPath: $(PROJECT_OUT_PATH)/source
- task: PublishPipelineArtifact@1
displayName: 'Publish NuGet Artifact'
inputs:
artifact: 'migratio-nuget'
targetPath: $(PROJECT_OUT_PATH)/nuget
- stage: runSamples
displayName: 'Run samples'
dependsOn: publishArtifact
jobs:
- job:
services:
postgresDbEnv1: postgresDbEnv1
postgresDbEnv2: postgresDbEnv2
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download Migratio'
inputs:
buildType: 'current'
artifactName: 'migratio-binaries'
targetPath: '$(MIGRATIO_DIRECTORY)'
- task: PowerShell@2
displayName: 'Env1 - Verify'
inputs:
targetType: 'inline'
script: |
Import-Module ./Migratio.dll
Invoke-MgRollout -CreateTableIfNotExist -ConfigFile $(SAMPLES_DIR)/migratio.yml -Env env1
Invoke-MgSeeding -CreateTableIfNotExist -ConfigFile $(SAMPLES_DIR)/migratio.yml -Env env1
Invoke-MgRollback -ConfigFile $(SAMPLES_DIR)/migratio.yml -Env env1
failOnStderr: true
workingDirectory: '$(MIGRATIO_DIRECTORY)'
env:
MG_DB_PASSWORD: pgpassenv1
- task: PowerShell@2
displayName: 'Env2 - Verify'
inputs:
targetType: 'inline'
script: |
Import-Module ./Migratio.dll
Invoke-MgRollout -CreateTableIfNotExist -ConfigFile $(SAMPLES_DIR)/migratio.yml -Env env2
Invoke-MgSeeding -CreateTableIfNotExist -ConfigFile $(SAMPLES_DIR)/migratio.yml -Env env2
Invoke-MgRollback -ConfigFile $(SAMPLES_DIR)/migratio.yml -Env env2
failOnStderr: true
workingDirectory: '$(MIGRATIO_DIRECTORY)'
env:
MG_DB_PASSWORD: pgpassenv2
- stage: publish_nuget
displayName: 'Publish package'
condition: eq(variables.isMaster, true)
dependsOn: 'runSamples'
jobs:
- deployment:
displayName: 'Publish package'
environment: 'nuget-migratio-prod'
strategy:
runOnce:
deploy:
steps:
- download: none
- download: current
artifact: 'migratio-nuget'
- task: DotNetCoreCLI@2
displayName: 'Push nuget package'
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/migratio-nuget/*.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'nuget-migratio'