-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
206 lines (200 loc) · 8.36 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
trigger:
- main
pool:
vmImage: "ubuntu-latest"
parameters:
- name: environments
type: object
default: ["dev", "int"]
variables:
serviceConnectionName: "nbs-mya-rg-dev"
stages:
- stage: Build
displayName: Build
jobs:
- job: "Build"
variables:
apiProjectPath: "src/api/Nhs.Appointments.Api/Nhs.Appointments.Api.csproj"
apiUnitTestProjectPath: "tests/Nhs.Appointments.Api.UnitTests/Nhs.Appointments.Api.UnitTests.csproj"
coreUnitTestProjectPath: "tests/Nhs.Appointments.Core.UnitTests/Nhs.Appointments.Core.UnitTests.csproj"
persistanceUnitTestProjectPath: "tests/Nhs.Appointments.Persistance.UnitTests/Nhs.Appointments.Persistance.UnitTests.csproj"
steps:
- task: DotNetCoreCLI@2
displayName: "dotnet Publish"
inputs:
command: publish
publishWebProjects: false
projects: $(apiProjectPath)
arguments: "--output $(Build.ArtifactStagingDirectory)"
zipAfterPublish: false
modifyOutputPath: false
- task: DotNetCoreCLI@2
displayName: "Run Api Unit Tests"
inputs:
command: "test"
projects: "$(apiUnitTestProjectPath)"
- task: DotNetCoreCLI@2
displayName: "Run Core Unit Tests"
inputs:
command: "test"
projects: $(coreUnitTestProjectPath)
- task: DotNetCoreCLI@2
displayName: "Run Persistance Unit Tests"
inputs:
command: "test"
projects: $(persistanceUnitTestProjectPath)
- task: ArchiveFiles@2
displayName: Zip Api
inputs:
rootFolderOrFile: $(Build.ArtifactStagingDirectory)
includeRootFolder: false
archiveType: "zip"
archiveFile: "$(Build.ArtifactStagingDirectory)/out/mya-api-$(Build.BuildId).zip"
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
displayName: "Publish API Artifact"
inputs:
PathtoPublish: "$(Build.ArtifactStagingDirectory)/out"
ArtifactName: "drop_api"
publishLocation: "Container"
- task: UseNode@1
displayName: "Install Node"
inputs:
version: 20.x
- script: |
cd ./src/new-client
npm ci
npm run lint
npm run format:check
npm run test:ci
displayName: "Run Web App Tests"
- task: PublishTestResults@2
displayName: "Publish Web App Test Results"
inputs:
testResultsFiles: "junit.xml"
testRunTitle: NBS Appointments Management Service Client Tests
testResultsFormat: "JUnit"
publishRunAttachments: true
searchFolder: "$(Build.SourcesDirectory)/src/new-client"
condition: succeededOrFailed()
- script: |
cd ./src/new-client
npm run build
mv .next/static .next/standalone/.next/static
displayName: "Build Web App"
- task: ArchiveFiles@2
displayName: Zip Web Client
inputs:
rootFolderOrFile: "$(Build.SourcesDirectory)/src/new-client/.next"
includeRootFolder: false
archiveType: "zip"
archiveFile: "$(Build.ArtifactStagingDirectory)/web/next.zip"
- task: PublishBuildArtifacts@1
displayName: "Publish Web App"
inputs:
PathtoPublish: "$(Build.ArtifactStagingDirectory)/web"
ArtifactName: "drop_web"
publishLocation: "Container"
- task: PublishBuildArtifacts@1
displayName: "Publish Terraform"
inputs:
PathtoPublish: "$(Build.SourcesDirectory)/infrastructure"
ArtifactName: "drop_terraform"
publishLocation: "Container"
- job: RunIntegrationAndE2ETests
displayName: "Run integration and E2E tests"
variables:
PFX_CERT_PATH: "$(Build.SourcesDirectory)/.aspnet/https"
integrationTestProjectPath: "tests/Nhs.Appointments.Api.Integration/Nhs.Appointments.Api.Integration.csproj"
cosmosDbSeederProjectPath: "mock-data/CosmosDbSeeder/CosmosDbSeeder.csproj"
steps:
- powershell: |
$ShortCommitHash = "$(Build.SourceVersion)".Substring(0, 7)
Write-Host "##vso[task.setvariable variable=SHORT_COMMIT_HASH]$ShortCommitHash"
displayName: Set short commit hash
- task: AzureCLI@2
displayName: "Create Cosmos DB account"
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: scriptPath
scriptPath: "$(Build.SourcesDirectory)/scripts/cosmos-pr-build/create_cosmos_db.ps1"
- task: AzureCLI@2
displayName: "Get Cosmos DB account connection string"
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: scriptPath
scriptPath: "$(Build.SourcesDirectory)/scripts/cosmos-pr-build/get_cosmos_connection_string.ps1"
- script: |
mkdir -p $(PFX_CERT_PATH)
dotnet dev-certs https -ep $(PFX_CERT_PATH)/aspnetapp.pfx -p password
displayName: "Create aspnet developer certificate"
- script: |
docker compose up --build --detach
displayName: "Start docker containers"
- task: DotNetCoreCLI@2
displayName: "Run Integration Tests"
inputs:
command: "test"
projects: "$(integrationTestProjectPath)"
arguments: '--logger:"trx;logfilename=myaServiceTests.trx";verbosity=detailed'
- task: PublishTestResults@2
displayName: "Publish integration test results"
inputs:
searchFolder: $(Agent.TempDirectory)
testResultsFormat: "VSTest"
testResultsFiles: "myaServiceTests.trx"
testRunTitle: "NBS Appointments Management Service Integration Tests"
publishRunAttachments: true
condition: succeededOrFailed()
- task: DotNetCoreCLI@2
displayName: "Reset and seed Cosmos DB containers"
inputs:
command: "run"
projects: $(cosmosDbSeederProjectPath)
- task: UseNode@1
displayName: "Install Node"
inputs:
version: 20.x
- script: |
cd ./src/new-client
npm ci
npx playwright install --with-deps chromium
npm run test:e2e
displayName: "Run E2E tests"
env:
CI: "true"
- task: PublishTestResults@2
displayName: "Publish E2E test results"
condition: succeededOrFailed()
inputs:
searchFolder: "src/new-client/testing"
testResultsFormat: "JUnit"
testResultsFiles: "e2e-junit-results.xml"
mergeTestResults: true
failTaskOnFailedTests: true
testRunTitle: "NBS Appointments Management Service End-To-End Tests"
- task: PublishBuildArtifacts@1
displayName: "Publish E2E test artifacts"
condition: succeededOrFailed()
inputs:
PathtoPublish: "src/new-client/test-artifacts"
ArtifactName: "E2E Test-results"
- task: AzureCLI@2
displayName: "Delete Cosmos DB account"
condition: or(succeeded(), canceled())
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: scriptPath
scriptPath: "$(Build.SourcesDirectory)/scripts/cosmos-pr-build/delete_cosmos_db.ps1"
- ${{ each env in parameters.environments }}:
- template: "scripts/pipeline-templates/deploy.yml"
parameters:
env: ${{env}}
variable_group: nbs-mya-${{env}}
apiServerName: nbs-mya-func-${{env}}-uks
webServerName: nbs-mya-app-${{env}}-uks
serviceConnectionName: nbs-mya-rg-${{env}}
isMain: ${{eq(variables['Build.SourceBranch'], 'refs/heads/main')}}