forked from mccsoft/backend-frontend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
171 lines (145 loc) · 5.16 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
trigger:
branches:
include:
- master
- main
paths:
exclude:
- docs/*
variables:
BUILD_NUMBER: 0.1.$(Build.BuildId)
REACT_APP_BUILD_NUMBER: 0.1.$(Build.BuildId)
solution: 'webapi/MccSoft.TemplateApp.sln'
project: 'webapi/src/MccSoft.TemplateApp.App/MccSoft.TemplateApp.App.csproj'
stages:
- stage: Build
jobs:
- job: Build_Backend_Frontend
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self
fetchDepth: 1
submodules: true
- template: ./azure-pipelines-tests-shared.yml
- script: |
yarn json -f package.json -I -e 'this.version="$(BUILD_NUMBER)"'
yarn json -f frontend/package.json -I -e 'this.version="$(BUILD_NUMBER)"'
yarn --version
# `set version` step should go after `yarn install`, since it uses `json` package which should be installed
# we do not use `yarn version` plugin, because it doesn't play well with shallow clone (https://yarnpkg.com/features/release-workflow#commit-history)
displayName: 'set version'
- script: |
yarn copy-translations-to-backend
displayName: 'copy translations to backend'
- script: |
yarn build-frontend
displayName: 'build frontend'
- script: |
yarn frontend build-storybook
displayName: 'build storybook'
- script: |
yarn build-dotnet
displayName: 'build backend'
- script: |
yarn copy-frontend && yarn copy-storybook
displayName: 'copy frontend to backend'
- template: ./build-import-meta-env.yml
# - script: |
# mkdir ./cobertura
# find '$(Agent.TempDirectory)' -name 'coverage.cobertura.xml' -exec cp --backup=numbered -t ./cobertura {} +
# cd ./cobertura
# for f in *~*~; do mv "$f" "$(echo "$f" | sed -r 's/(.*)\.~([0-9]+)~/\2\1/')"; done;
# displayName: 'copy coverage files'
# - script: |
# cd ./webapi
# dotnet tool restore
# dotnet reportgenerator -reports:../cobertura/* -targetdir:../cobertura/report -sourcedirs:./ -assemblyfilters:+Lmt.Unicorn.App\;+Lmt.Unicorn.Common\;+Lmt.Unicorn.Domain
# displayName: 'generate coverage report'
# - publish: './cobertura'
# artifact: 'backend-coverage'
# - task: PublishTestResults@2
# inputs:
# testResultsFormat: 'JUnit'
# testResultsFiles: '**/junit.xml'
# mergeTestResults: true
- script: |
docker login $(DOCKER_REGISTRY) -u $(DOCKER_USER) -p $(DOCKER_TOKEN)
displayName: 'Authenticate at Container Registry'
- task: Docker@2
condition: succeeded()
inputs:
repository: $(DOCKER_REGISTRY)
command: 'buildAndPush'
Dockerfile: 'publish/Dockerfile'
buildContext: '$(Build.SourcesDirectory)/publish'
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
tags: |
$(BUILD_NUMBER)
latest
${{ else }}:
tags: |
$(BUILD_NUMBER)
displayName: 'build and push docker image'
- publish: './publish'
artifact: 'publish'
- publish: './docker-compose.yaml'
artifact: 'docker-compose'
- publish: './nginx'
artifact: 'nginx'
- publish: './scripts/deploy'
artifact: 'scripts'
- stage: DeployToDev
dependsOn: Build
condition: succeeded()
jobs:
- deployment:
environment:
name: 'DEV'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- template: ./azure-deploy-template.yml
- stage: TagDevSources
dependsOn: DeployToDev
condition: succeeded()
jobs:
- job:
condition: succeeded()
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
persistCredentials: true
- script: |
git tag 'dev' -f
git push origin 'dev' -f --tags
- stage: DeployToProd
dependsOn: Build
condition: succeeded()
jobs:
- deployment:
environment:
name: 'PROD'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- template: ./azure-deploy-template.yml
- stage: TagProdSources
dependsOn: DeployToProd
condition: succeeded()
jobs:
- job:
condition: succeeded()
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
persistCredentials: true
- script: |
git tag 'prod' -f
git push origin 'prod' -f --tags