-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
196 lines (180 loc) · 6.81 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
# Azure DevOps pipeline to build, check source codes, run tests, and deploy.
#
# To make Danger JS run on a pull request you need to add the following pipeline
# variable and set it with a GitHub access token (scope public_repo); otherwise
# set its value to 'skip' without marking it secret:
# - DANGER_GITHUB_API_TOKEN
#
# To enable the deployment in any environment you need to configure the following
# global variable otherwise all the deployment jobs will be always skipped:
# - DO_DEPLOY = true
# you also need to configure the following additional parameters based on the
# environment(s) to update when running the pipeline:
# - PRODUCTION_ENABLE_DEPLOY = true
# - TEST_ENABLE_DEPLOY = true
#
# The following parameter and variables must also be set to run the deployment:
# - PRODUCTION_DEPLOY_TYPE:
# -- 'deployToAzureBlob': deploy to 'AzureBlobStorage'
# - PRODUCTION_AZURE_SUBSCRIPTION
# - PRODUCTION_STORAGE_ACCOUNT_NAME
#
# - TEST_DEPLOY_TYPE:
# -- 'deployToAzureBlob': deploy to 'AzureBlobStorage'
# - TEST_AZURE_SUBSCRIPTION
# - TEST_STORAGE_ACCOUNT_NAME
#
variables:
NODE_VERSION: '10.14.1'
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
BLOB_CONTAINER_NAME: '$web'
REACT_APP_API_URL: 'https://api.io.italia.it'
ADB2C_TENANT_AUDIENCE: 'https://iobackoffice.b2clogin.com/iobackoffice.onmicrosoft.com/c2c9dbf8-9fc3-4f69-b8a6-c87d10d0ab06'
ADB2C_TENANT_AUTHORITY: 'https://iobackoffice.b2clogin.com/iobackoffice.onmicrosoft.com/B2C_1_backoffice'
ADB2C_TENANT_B2CSCOPES: 'https://iobackoffice.onmicrosoft.com/c2c9dbf8-9fc3-4f69-b8a6-c87d10d0ab06/ProfileRead'
ADB2C_TENANT_CLIENTID: 'c2c9dbf8-9fc3-4f69-b8a6-c87d10d0ab06'
parameters:
- name: 'TEST_ENABLE_DEPLOY'
displayName: 'Enable deploy in test environment'
type: boolean
default: false
- name: 'TEST_DEPLOY_TYPE'
displayName: 'Method to achieve deployment in Test (if enabled):'
type: string
default: deployToAzureBlob
values:
- deployToAzureBlob
- name: 'PRODUCTION_ENABLE_DEPLOY'
displayName: 'Enable deploy in production environment'
type: boolean
default: true
- name: 'PRODUCTION_DEPLOY_TYPE'
displayName: 'Method to achieve deployment in Production (if enabled):'
type: string
default: deployToAzureBlob
values:
- deployToAzureBlob
# This pipeline can be manually run or is automatically triggered whenever one
# of the following conditions is true:
# - a push is made to any branch in the repository (not only 'master')
# - a pull request is created
# - a tag named 'latest' is pushed
# Note. In the last case, the tag can be (re-)created using the Git CLI, e.g.:
# git push -f origin <abfb967>:refs/tags/latest
trigger:
branches:
include:
- '*'
- refs/tags/latest
# This pipeline has been implemented to be run on hosted agent pools based both
# on 'windows' and 'ubuntu' virtual machine images and using the scripts defined
# in the package.json file. Since we are usually deploying on Azure Web app on Windows
# runtime, the pipeline is currently configured to use a Windows hosted image for
# verifying the build and deploying, and Linux OS for all other jobs for faster
# execution. In this specific case the deploying just need to copy static Web contents.
pool:
vmImage: 'windows-2019'
stages:
# A) Build and code validation (always run)
- stage: Build
dependsOn: []
jobs:
# A1) Checkout, install module and build code (use Windows OS)
- job: make_build
steps:
- template: azure-templates/make-build-steps.yml
parameters:
make: build
# A2) Analyze source code to find errors with lint (use Linux VM)
- job: lint
pool:
vmImage: 'ubuntu-latest'
steps:
- template: azure-templates/make-build-steps.yml
parameters:
make: install_dependencies
- script: |
yarn lint
displayName: 'Lint'
# A3) Run Danger (skipping if not executing on a PR)
- job: danger
pool:
vmImage: 'ubuntu-latest'
condition:
and(
succeeded(),
and(
eq(variables['Build.Reason'], 'PullRequest'),
ne(variables['DANGER_GITHUB_API_TOKEN'], 'skip')
)
)
steps:
- template: azure-templates/make-build-steps.yml
parameters:
make: install_dependencies
- bash: |
yarn danger ci
env:
DANGER_GITHUB_API_TOKEN: '$(DANGER_GITHUB_API_TOKEN)'
displayName: 'Danger CI'
# B) Run unit tests: no test is currently available (stage Test is missed)
# C) Deploy to TEST environment if the following conditions apply:
# - continuos deployment (automatic):
# - $DO_DEPLOY == true and TEST_ENABLE_DEPLOY == true
# - there is a push on 'master' branch
# - manual deployment:
# - $DO_DEPLOY == true and TEST_ENABLE_DEPLOY == true
- ${{ if eq(parameters.TEST_ENABLE_DEPLOY, true) }}:
- stage: Deploy_test
condition:
and(
succeeded(),
and (
eq(variables['DO_DEPLOY'], true),
or(
eq(variables['Build.SourceBranch'], 'refs/heads/master'),
eq(variables['Build.Reason'], 'Manual')
)
)
)
dependsOn:
- Build
jobs:
- job: deploy_to_container
steps:
- template: azure-templates/deploy-steps.yml
parameters:
deployType: 'deployToAzureBlob'
azureSubscription: '$(TEST_AZURE_SUBSCRIPTION)'
storageAccountName: '$(TEST_STORAGE_ACCOUNT_NAME)'
containerName: '$(BLOB_CONTAINER_NAME)'
# D) Deploy to PRODUCTION environment if one of the following conditions apply:
# - continuos deployment (automatic):
# - $DO_DEPLOY == true and PRODUCTION_ENABLE_DEPLOY == true
# - the 'latest' tag is pushed
# - manual deployment:
# - $DO_DEPLOY == true and PRODUCTION_ENABLE_DEPLOY == true
- ${{ if eq(parameters.PRODUCTION_ENABLE_DEPLOY, true) }}:
- stage: Deploy_production
condition:
and(
succeeded(),
and (
eq(variables['DO_DEPLOY'], true),
or(
eq(variables['Build.SourceBranch'], 'refs/tags/latest'),
eq(variables['Build.Reason'], 'Manual')
)
)
)
dependsOn:
- Build
jobs:
- job: deploy_to_container
steps:
- template: azure-templates/deploy-steps.yml
parameters:
deployType: 'deployToAzureBlob'
azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)'
storageAccountName: '$(PRODUCTION_STORAGE_ACCOUNT_NAME)'
containerName: '$(BLOB_CONTAINER_NAME)'