-
Notifications
You must be signed in to change notification settings - Fork 143
/
azure-pipelines.yml
368 lines (350 loc) · 16.6 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# fabric-chaincode-node azure pipeline configuration.
#
name: $(SourceBranchName)-$(Date:yyyyMMdd)$(Rev:.rrr)
# Daily build for final quality
# cf https://crontab.guru/#0_23_*_*_*
schedules:
- cron: "0 10,12,14,16,23 * * *"
displayName: 'Chaincode Node Nightly Driver'
branches:
include:
- 'release-2.5'
# Trigger on the main branch
# Standard Pull Request and Merge builds
# Any git tag will also trigger a build that should do publishing
trigger:
branches:
include:
- 'release-2.5'
tags:
include:
- '*'
# These are custom defined variables, the pipeline one is currently used for the build scripts
# to know to produce tests results in XML format for Azure to consume, for developers
# this isn't set so command line output is given
#
# Chaincode_Node_Vars is the protected group of keys for publishing
variables:
- group: Chaincode_Node_Vars
- name: component
value: fabric-chaincode-node
- name: pipeline
value: ci
- name: node_version_spec
value: '16.4.0'
- name: rewire_node_version_spec # see https://github.com/jhnns/rewire/issues/178
value: '16.4.0'
- name: FABRIC_VERSION
value: 2.5
# Build on Ubuntu
pool:
vmImage: 'ubuntu-latest'
#
# Publish to NPM on release builds (they are the github tagged releases)
# Publish to NPM on nightly builds when there is something to build
# the ids will be of the format 2.5.0.{commitid}
#
stages:
# Primary stage of building, linting and unit tests
- stage: Build_and_Test
jobs:
# output some basic information for reference
- job: displayenv
steps:
- template: templates/build-data.yaml
- job: main
dependsOn: displayenv
displayName: 'Build, lint, UT'
variables:
VERSION: $[ dependencies.displayenv.outputs['BuildData.PACKAGE_VERSION'] ]
BUILD_DATE: $[ dependencies.displayenv.outputs['BuildData.BUILD_DATE'] ]
steps:
- task: NodeTool@0
inputs:
versionSpec: $(rewire_node_version_spec)
- template: templates/nightly-version-update.yaml
- script: |
set -ev
node common/scripts/install-run-rush.js install
displayName: 'Setup the rush environment'
- script: |
set -ev
node common/scripts/install-run-rush.js rebuild
displayName: 'Full rebuild'
- script: |
npx cobertura-merge -o merged_coverage.xml shim=./libraries/fabric-shim/coverage/cobertura-coverage.xml contractapi=./apis/fabric-contract-api/coverage/cobertura-coverage.xml -p
condition: or(succeeded(), failed())
- task: PublishTestResults@2
condition: or(succeeded(), failed()) # publish either way
inputs:
testResultsFiles: '**/test-results.xml'
artifactName: 'Unit Test results'
testRunTitle: 'Unit Test results'
- task: PublishCodeCoverageResults@1
condition: or(succeeded(), failed()) # publish either way
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: 'merged_coverage.xml'
artifactName: 'Unit Test Coverage'
- script: |
mkdir -p $(Build.ArtifactStagingDirectory)/logs
find . \( -type d -name 'node_modules' \) -prune -o -name '*.build*.log' -exec cp {} $(Build.ArtifactStagingDirectory)/logs \;
displayName: 'Copy build logs'
condition: or(succeeded(), failed()) # publish either way
- task: PublishBuildArtifacts@1
condition: or(succeeded(), failed()) # publish either way
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)/logs
artifactName: 'Build logs'
displayName: 'Publish build logs'
# Copy the built artifacts to the staging directory, tgz, and the docker image
- script: |
set -ev
node common/scripts/install-run-rush.js publish --include-all --pack --release-folder $(Build.ArtifactStagingDirectory)/tgz --publish
docker image save hyperledger/fabric-nodeenv | gzip > $(Build.ArtifactStagingDirectory)/fabric-nodeenv.tar.gz
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)/tgz
artifactName: node-tgz
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)/fabric-nodeenv.tar.gz
artifactName: nodeenv-docker-image
# Run the FV tests but using the built material
- job: fvt
displayName: 'FV Tests'
dependsOn: [main,displayenv]
variables:
VERSION: $[ dependencies.displayenv.outputs['BuildData.PACKAGE_VERSION'] ]
BUILD_DATE: $[ dependencies.displayenv.outputs['BuildData.BUILD_DATE'] ]
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_version_spec)
- template: templates/nightly-version-update.yaml
- task: DownloadPipelineArtifact@2
inputs:
artifact: nodeenv-docker-image
path: $(Build.SourcesDirectory)/build
- task: DownloadPipelineArtifact@2
inputs:
artifact: node-tgz
path: $(Build.SourcesDirectory)/build
- script: |
set -ev
./tools/getEdgeDocker.sh # essential to get main docker images of peer etc.
docker image load --input build/fabric-nodeenv.tar.gz # gets the build image of nodeenv
docker tag hyperledger/fabric-nodeenv:latest hyperledger/fabric-nodeenv:$(FABRIC_VERSION)
docker images
node common/scripts/install-run-rush.js install
node common/scripts/install-run-rush.js update # should the tests need 'building' this will need to go here
displayName: 'Get the latest main docker images'
- script: |
set -ev
export TLS=true
node common/scripts/install-run-rush.js start-fabric
node common/scripts/install-run-rush.js start-verdaccio # script will check for the ci variable and use built images
docker images | grep hyperledger && docker ps -a
node common/scripts/install-run-rush.js test:fv --verbose
node common/scripts/install-run-rush.js test:e2e --verbose
displayName: 'FV Tests'
- task: PublishTestResults@2
condition: or(succeeded(), failed()) # publish either way
inputs:
testResultsFiles: '**/test-results.xml'
testRunTitle: 'FV Test results'
- task: CopyFiles@2
condition: or(succeeded(), failed()) # publish either way
inputs:
sourceFolder: $(Build.SourcesDirectory)/test
contents: |
**/*.build*.log
!**/node_modules/**
targetFolder: $(Build.ArtifactStagingDirectory)/testlogs
- script: |
mkdir -p $(Build.ArtifactStagingDirectory)/testlogs
find . \( -type d -name 'node_modules' \) -prune -o -name '*.build*.log' -exec cp {} $(Build.ArtifactStagingDirectory)/testlogs \;
condition: or(succeeded(), failed())
displayName: 'Copy test logs'
- task: PublishBuildArtifacts@1
condition: or(succeeded(), failed()) # publish either way
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)/testlogs
artifactName: 'Test logs'
displayName: 'Publish test logs'
# Job to handle the auditing of the code
# NPM audit is run on a 'fake' installation of the libraries
# Pulling in all the dependencies it will be able to run NPM AUDIT, and if that returns a
# error code the job will fail.
- job: src_audit
displayName: 'Node Module Auditing'
dependsOn: [main,displayenv]
variables:
VERSION: $[ dependencies.displayenv.outputs['BuildData.PACKAGE_VERSION'] ]
BUILD_DATE: $[ dependencies.displayenv.outputs['BuildData.BUILD_DATE'] ]
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_version_spec)
- task: DownloadPipelineArtifact@2
inputs:
artifact: node-tgz
path: $(Build.SourcesDirectory)/build
- template: templates/nightly-version-update.yaml
- script: |
node common/scripts/install-run-rush.js install
node common/scripts/install-run-rush.js start-verdaccio # script will check for the ci variable and use built images
mkdir -p $(Build.SourcesDirectory)/audit && cd $(Build.SourcesDirectory)/audit && npm init -y
npm install --registry http://localhost:4873 fabric-shim fabric-shim-api fabric-contract-api --save
npm audit --audit-level=moderate
displayName: 'Run npm audit'
# Build and publish API docs on every merge build
- job: jsdoc
dependsOn: displayenv
condition: and(succeeded(),eq(variables['Build.Reason'], 'IndividualCI'))
variables:
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
jsdoc_release: main
${{ if ne(variables['Build.SourceBranch'], 'refs/heads/main') }}:
jsdoc_release: $[format('release-{0}',dependencies.displayenv.outputs['BuildData.MINOR_PACKAGE_VERSION'])]
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_version_spec)
- script: |
set -ev
node common/scripts/install-run-rush.js install
displayName: 'Setup the rush environment'
- script: |
set -ev
node common/scripts/install-run-rush.js rebuild --to fabric-shim-docs
displayName: 'Build JSDoc'
- task: CopyFiles@2
inputs:
contents: |
gen/**
sourceFolder: '$(Build.SourcesDirectory)/docs'
targetFolder: $(Build.ArtifactStagingDirectory)/jsdoc
cleanTargetFolder: true
displayName: 'Copy JSDoc'
- task: CopyFiles@2
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
inputs:
contents: |
_config.yml
**/?(*.md|*.html)
!_jsdoc.json
!_jsdoc/**
!gen/**
!node_modules/**
sourceFolder: '$(Build.SourcesDirectory)/docs'
targetFolder: $(Build.ArtifactStagingDirectory)/gh-pages
cleanTargetFolder: true
displayName: 'Copy gh-pages doc (main branch only)'
- script: |
git reset --hard HEAD
git clean -xdf
git fetch origin
git checkout -b gh-pages origin/gh-pages
git clean -xdf
mkdir -p $(jsdoc_release)/api
rm -rf $(jsdoc_release)/api/*
cp -r $(Build.ArtifactStagingDirectory)/jsdoc/gen/* $(jsdoc_release)/api
if [ -d $(Build.ArtifactStagingDirectory)/gh-pages ]; then
find . -maxdepth 1 ! \( -name [.]* -o -name 'gh-pages' -o -name 'main' -o -name 'release-*' \) -exec rm -rf {} \;
cp -r $(Build.ArtifactStagingDirectory)/gh-pages/* .
fi
displayName: 'Update gh-pages branch'
- script: |
git config --global user.email "hlfdev.azp@gmail.com"
git config --global user.name "Hyperledger Bot"
git add -A
git commit -m "Publishing GitHub Pages"
git push https://$(GITHUB-PAT)@github.com/hyperledger/fabric-chaincode-node.git gh-pages
displayName: 'Commit gh-pages changes'
continueOnError: true # Need to fix jsdoc publishing after release
# Publish a new version, triggered by a git tag
- stage: Publish_tag
dependsOn: Build_and_Test
condition: and(succeeded('Build_and_Test'), startsWith(variables['Build.SourceBranch'], 'refs/tags'))
jobs:
- job: npm_publish
displayName: 'npm publish'
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_version_spec)
- download: current
artifact: node-tgz
- script: |
touch $(Agent.TempDirectory)/.npmrc
echo '##vso[task.setvariable variable=NPM_CONFIG_USERCONFIG]$(Agent.TempDirectory)/.npmrc'
displayName: 'create user .npmrc file'
- script: |
npm config set registry https://registry.npmjs.org/
npm config ls
displayName: 'set npmjs registry'
- task: npmAuthenticate@0
inputs:
workingFile: '$(Agent.TempDirectory)/.npmrc'
customEndpoint: 'fabric-chainode-node-npm'
- script: |
find $(Pipeline.Workspace)/node-tgz/ -maxdepth 1 -type f -name 'fabric-*.tgz' -exec npm publish {} --tag beta \;
displayName: 'npm publish'
- job: dockerhub_publish
steps:
- template: templates/build-data.yaml
- task: DownloadPipelineArtifact@2
inputs:
artifact: nodeenv-docker-image
path: $(Build.SourcesDirectory)/build
- script: |
wget -qO "$PWD/manifest-tool" https://github.com/estesp/manifest-tool/releases/download/v1.0.0/manifest-tool-linux-amd64
chmod +x ./manifest-tool
docker image load --input build/fabric-nodeenv.tar.gz
docker images
docker login ${DOCKER_REGISTRY_URL} --username=${DOCKER_REGISTRY_USERNAME} --password=${DOCKER_REGISTRY_PASSWORD}
echo "Logged in to docker registry"
# tag nodeenv image to PACKAGE_VERSION
docker tag hyperledger/fabric-nodeenv hyperledger/fabric-nodeenv:amd64-$(BuildData.PACKAGE_VERSION)
# push nodeenv to repository
docker push hyperledger/fabric-nodeenv:amd64-$(BuildData.PACKAGE_VERSION)
# publish patch version (3-digit) image
./manifest-tool push from-args --platforms linux/amd64 --template "hyperledger/fabric-nodeenv:amd64-$(BuildData.PACKAGE_VERSION)" --target "hyperledger/fabric-nodeenv:$(BuildData.PACKAGE_VERSION)"
# publish minor version (2-digit) image
./manifest-tool push from-args --platforms linux/amd64 --template "hyperledger/fabric-nodeenv:amd64-$(BuildData.PACKAGE_VERSION)" --target "hyperledger/fabric-nodeenv:$(BuildData.MINOR_PACKAGE_VERSION)"
env:
DOCKER_REGISTRY_USERNAME: $(DockerHub-Username)
DOCKER_REGISTRY_PASSWORD: $(DockerHub-Password)
# Stage to publish the nightly drivers
- stage: Publish_tag_nightly
dependsOn: Build_and_Test
condition: and(succeeded('Build_and_Test'), eq(variables['Build.Reason'], 'Schedule')) # only run on the scheduled builds
jobs:
- job: npm_publish
displayName: 'npm publish'
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_version_spec)
- download: current
artifact: node-tgz
- script: |
touch $(Agent.TempDirectory)/.npmrc
echo '##vso[task.setvariable variable=NPM_CONFIG_USERCONFIG]$(Agent.TempDirectory)/.npmrc'
displayName: 'create user .npmrc file'
- script: |
npm config set registry https://registry.npmjs.org/
npm config ls
displayName: 'set npmjs registry'
- task: npmAuthenticate@0
inputs:
workingFile: '$(Agent.TempDirectory)/.npmrc'
customEndpoint: 'fabric-chainode-node-npm'
- script: |
find $(Pipeline.Workspace)/node-tgz/ -maxdepth 1 -type f -name 'fabric-*.tgz' -exec npm publish {} --tag beta \;
displayName: 'npm publish'