generated from pagopa/io-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 4
/
azure-pipelines.yml
201 lines (180 loc) · 7.17 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
# Azure DevOps pipeline to build, check source codes, run tests, and publish
# package in NPM registry.
#
# To enable the check of source code with Danger JS you need to configure a valid
# GitHub token (with scope "public_repo") by setting the following variable:
# - DANGER_GITHUB_API_TOKEN
#
# The deployment can only be triggered by a manual run of the pipeline and consists
# in publishing a new version of the package 'io-functions-commons' to the NPM
# registry and create a corresponding release and tag in GitHub. To enable the deployment
# you need to set to true the following variable otherwise the job to release the
# package will be skipped:
# - ENABLE_MANUAL_DEPLOY = true
#
# The following variable needs to be used for specifying the increment "major", "minor",
# "patch" (DEFAULT), or "pre*" version of the package to be published (you could also
# directly specify the version; e.g. "4.2.1"):
# - PACKAGE_VERSION
#
# To publish a Release to the GitHub repository is required to specify in the following
# variable a personal access token (with scope "public_repo") for a GitHub user who
# is a 'collaborator' of the repository "pagopa/io-functions-commons":
# - GITHUB_TOKEN
#
# To publish the package to the NPM registry you also need to set an auth token (with
# "read and publish" access level) for a NPM user who is 'collaborator' of the public
# package "io-functions-commons":
# - NPM_TOKEN
#
# WARNING. Only the following values are allowed when selecting parameters to manually
# run the pipeline using Azure DevOps UI:
# - Branch/tag: you need to select a branch (a tag name cannot be specified)
# - Commit: leave empty (otherwise the updates are rejected because the tip of your
# current branch would be behind its remote counterpart)
#
variables:
NODE_VERSION: '10.14.1'
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
# 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
trigger: none
# 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 deploying on Azure Web app on Windows
# runtime, the pipeline is currently configured to use a Windows hosted image for
# verifying the build, and Linux OS for all other jobs for faster execution.
pool:
vmImage: 'ubuntu-latest'
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
pool:
vmImage: 'windows-2019'
steps:
- template: azure-templates/make-build-steps.yml
parameters:
make: build
# A2) Analyze source code to find errors with lint
- job: lint
steps:
- template: azure-templates/make-build-steps.yml
parameters:
make: install_dependencies
- script: |
yarn lint
displayName: 'Lint'
# A3) Validate API definitions
- job: lint_api
steps:
- task: UseNode@1
inputs:
version: $(NODE_VERSION)
displayName: 'Set up Node.js'
- bash: |
npx oval validate -p openapi/index.yaml
displayName: 'Validate openAPI'
# A4) Run Danger (skipping if not executing on a PR)
- job: danger
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 (use Linux OS, also required to generate certificates)
- stage: Test
dependsOn: []
jobs:
- job: unit_tests
steps:
- template: azure-templates/make-build-steps.yml
parameters:
make: build
- script: |
yarn test
displayName: 'Unit tests exec'
- bash: |
bash <(curl -s https://codecov.io/bash)
displayName: 'Code coverage'
# C) Run integration tests (use Linux OS, also required to generate certificates)
- stage: IntegrationsTest
dependsOn: []
jobs:
- job: integrations_tests
steps:
- template: azure-templates/make-build-steps.yml
parameters:
make: build
- script: |
docker run -d -p 1025:1025 -p 8025:8025 --name mailhog mailhog/mailhog
displayName: 'Start mailhog'
- script: |
MAILHOG_HOSTNAME=localhost yarn test:integration
displayName: 'Integrations tests exec'
# D) Publish a new version of the package 'io-functions-commons' to the NPM
# registry and a release in GitHub if all the following conditions apply:
# - $ENABLE_MANUAL_DEPLOY == true
# - it is a manual trigger
# - Build / Test stages succeeded (if selected)
- stage: Deploy_production
pool:
vmImage: 'windows-2019'
condition:
and(
succeeded(),
and (
eq(variables['ENABLE_MANUAL_DEPLOY'], true),
eq(variables['Build.Reason'], 'Manual')
)
)
dependsOn:
- Build
- Test
- IntegrationsTest
jobs:
- job: publish_package
steps:
# You only need to install dev dependencies to run release-it tool
- template: azure-templates/make-build-steps.yml
parameters:
make: install_dependencies
# The NPM auth token must be set in a local .npmrc file
- bash: |
echo registry=https://registry.npmjs.com/ >> .npmrc
echo \//registry.npmjs.org/:_authToken=$NPM_TOKEN >> .npmrc
env:
NPM_TOKEN: '$(NPM_TOKEN)'
displayName: 'Init .npmrc file'
# Environment variable "GITHUB_TOKEN" is required for creating GitHub release.
# Note. The git commands are run only to set the appropriate missing configurations
# (e.g. HEAD detached, upstream branch not set, username and email missing, etc.)!
- bash: |
git checkout $GIT_SOURCE_BRANCH_NAME
git checkout -B $GIT_SOURCE_BRANCH_NAME $GIT_SOURCE_COMMIT
git config user.name "devops-pipeline"
git config --global user.email "devops-pipeline@noreply.github.com"
yarn release-it $PACKAGE_VERSION --ci
env:
GIT_SOURCE_BRANCH_NAME: '$(Build.SourceBranchName)'
GIT_SOURCE_COMMIT: '$(Build.SourceVersion)'
GITHUB_TOKEN: '$(GITHUB_TOKEN)'
PACKAGE_VERSION: '$(PACKAGE_VERSION)'
displayName: 'release-it'