@mojaloop/sdk-scheme-adapter 17.0.1 → 17.0.2-snapshot.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/.circleci/config.yml +456 -175
  2. package/Dockerfile +12 -5
  3. package/audit-resolve.json +31 -67
  4. package/docker-compose.yml +4 -2
  5. package/package.json +18 -16
  6. package/src/lib/model/AccountsModel.js +4 -7
  7. package/src/lib/model/Async2SyncModel.js +4 -3
  8. package/src/lib/model/InboundTransfersModel.js +16 -14
  9. package/src/lib/model/OutboundBulkQuotesModel.js +4 -7
  10. package/src/lib/model/OutboundBulkTransfersModel.js +4 -7
  11. package/src/lib/model/OutboundRequestToPayModel.js +5 -10
  12. package/src/lib/model/OutboundRequestToPayTransferModel.js +6 -12
  13. package/src/lib/model/OutboundTransfersModel.js +10 -9
  14. package/src/lib/model/common/BackendError.js +1 -13
  15. package/src/lib/model/common/Enums.js +30 -0
  16. package/src/lib/model/common/index.js +3 -2
  17. package/test/config/integration.env +2 -2
  18. package/test/integration/lib/Outbound/parties.test.js +2 -1
  19. package/test/integration/lib/Outbound/quotes.test.js +3 -1
  20. package/test/integration/lib/Outbound/simpleTransfers.test.js +2 -1
  21. package/test/unit/inboundApi/handlers.test.js +3 -1
  22. package/test/unit/lib/model/AccountsModel.test.js +2 -1
  23. package/test/unit/lib/model/InboundTransfersModel.test.js +10 -6
  24. package/test/unit/lib/model/OutboundBulkQuotesModel.test.js +5 -3
  25. package/test/unit/lib/model/OutboundBulkTransfersModel.test.js +4 -3
  26. package/test/unit/lib/model/OutboundRequestToPayModel.test.js +3 -2
  27. package/test/unit/lib/model/OutboundRequestToPayTransferModel.test.js +4 -3
  28. package/test/unit/lib/model/OutboundTransfersModel.test.js +37 -34
  29. package/test/unit/lib/model/PartiesModel.test.js +2 -1
  30. package/test/unit/lib/model/QuotesModel.test.js +2 -1
  31. package/test/unit/lib/model/TransfersModel.test.js +2 -1
  32. package/test/unit/lib/model/data/getBulkTransfersBackendResponse.json +1 -1
  33. package/test/unit/lib/model/data/getBulkTransfersMojaloopResponse.json +1 -1
@@ -7,11 +7,10 @@ version: 2.1
7
7
  # Orbs used in this pipeline
8
8
  ###
9
9
  orbs:
10
- anchore: anchore/anchore-engine@1.6.0
11
- slack: circleci/slack@3.4.2
12
- pr-tools: mojaloop/pr-tools@0.1.10
13
- github-release: h-matsuo/github-release@0.1.3
14
-
10
+ anchore: anchore/anchore-engine@1.9.0
11
+ slack: circleci/slack@4.9.3 # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
12
+ pr-tools: mojaloop/pr-tools@0.1.10 # Ref: https://github.com/mojaloop/ci-config/
13
+ gh: circleci/github-cli@2.1.0
15
14
 
16
15
  ##
17
16
  # defaults
@@ -19,24 +18,18 @@ orbs:
19
18
  # YAML defaults templates, in alphabetical order
20
19
  ##
21
20
  defaults_Dependencies: &defaults_Dependencies |
21
+ apk --no-cache add bash
22
22
  apk --no-cache add git
23
23
  apk --no-cache add ca-certificates
24
24
  apk --no-cache add curl
25
25
  apk --no-cache add openssh-client
26
- apk --no-cache add bash
27
- apk add --no-cache -t build-dependencies make gcc g++ python3 libtool autoconf automake
26
+ apk add --no-cache -t build-dependencies make gcc g++ python3 libtool autoconf automake jq
27
+ apk add --no-cache -t openssl ncurses coreutils libgcc linux-headers grep util-linux binutils findutils
28
28
  npm config set unsafe-perm true
29
29
  npm install -g node-gyp
30
30
 
31
31
  defaults_awsCliDependencies: &defaults_awsCliDependencies |
32
- apk upgrade --no-cache
33
- apk --no-cache add \
34
- python3 \
35
- py3-pip \
36
- groff \
37
- less \
38
- mailcap
39
- pip3 install --upgrade pip awscli==1.14.5 s3cmd==2.0.1 python-magic
32
+ apk --no-cache add aws-cli
40
33
 
41
34
  defaults_license_scanner: &defaults_license_scanner
42
35
  name: Install and set up license-scanner
@@ -44,10 +37,12 @@ defaults_license_scanner: &defaults_license_scanner
44
37
  git clone https://github.com/mojaloop/license-scanner /tmp/license-scanner
45
38
  cd /tmp/license-scanner && make build default-files set-up
46
39
 
40
+ ## remove
47
41
  defaults_npm_auth: &defaults_npm_auth
48
42
  name: Update NPM registry auth token
49
43
  command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
50
44
 
45
+ ## remove
51
46
  defaults_npm_publish_release: &defaults_npm_publish_release
52
47
  name: Publish NPM $RELEASE_TAG artifact
53
48
  command: |
@@ -55,6 +50,31 @@ defaults_npm_publish_release: &defaults_npm_publish_release
55
50
  echo "Publishing tag $RELEASE_TAG"
56
51
  npm publish --tag $RELEASE_TAG --access public
57
52
 
53
+ defaults_export_version_from_package: &defaults_export_version_from_package
54
+ name: Format the changelog into the github release body and get release tag
55
+ command: |
56
+ git diff --no-indent-heuristic master~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
57
+ echo 'export RELEASE_CHANGES=`cat /tmp/changes`' >> $BASH_ENV
58
+ echo 'export RELEASE_TAG=`cat package-lock.json | jq -r .version`' >> $BASH_ENV
59
+
60
+ defaults_configure_git: &defaults_configure_git
61
+ name: Configure git
62
+ command: |
63
+ git config user.email ${GIT_CI_EMAIL}
64
+ git config user.name ${GIT_CI_USER}
65
+
66
+ defaults_configure_nvm: &defaults_configure_nvm
67
+ name: Configure NVM
68
+ command: |
69
+ touch $HOME/.profile
70
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
71
+ export NVM_DIR="$HOME/.nvm"
72
+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
73
+ echo "Installing Node version: $(cat .nvmrc)"
74
+ nvm install $(cat .nvmrc)
75
+ nvm alias default $(cat .nvmrc)
76
+ nvm use $(cat .nvmrc)
77
+
58
78
  ##
59
79
  # Executors
60
80
  #
@@ -64,11 +84,11 @@ executors:
64
84
  default-docker:
65
85
  working_directory: /home/circleci/project
66
86
  docker:
67
- - image: node:16.15.0-alpine
87
+ - image: node:16.15.0-alpine # Ref: https://hub.docker.com/_/node?tab=tags&page=1&name=alpine
68
88
 
69
89
  default-machine:
70
90
  machine:
71
- image: ubuntu-2004:202010-01
91
+ image: ubuntu-2004:current # Ref: https://circleci.com/developer/machine/image/ubuntu-2004
72
92
 
73
93
  ##
74
94
  # Jobs
@@ -84,19 +104,45 @@ jobs:
84
104
  command: *defaults_Dependencies
85
105
  - checkout
86
106
  - run:
87
- name: Access npm folder as root
88
- command: cd $(npm root -g)/npm
107
+ <<: *defaults_configure_nvm
89
108
  - run:
90
- name: Update NPM install (using `npm ci`)
109
+ name: Update NPM install
91
110
  command: npm ci
92
- - run:
93
- name: Delete build dependencies
94
- command: apk del build-dependencies
95
111
  - save_cache:
96
112
  key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
97
113
  paths:
98
114
  - node_modules
99
115
 
116
+ test-dependencies:
117
+ executor: default-docker
118
+ steps:
119
+ - run:
120
+ name: Install general dependencies
121
+ command: *defaults_Dependencies
122
+ - checkout
123
+ - run:
124
+ <<: *defaults_configure_nvm
125
+ - restore_cache:
126
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
127
+ - run:
128
+ name: Execute dependency tests
129
+ command: npm run dep:check
130
+
131
+ test-lint:
132
+ executor: default-docker
133
+ steps:
134
+ - run:
135
+ name: Install general dependencies
136
+ command: *defaults_Dependencies
137
+ - checkout
138
+ - run:
139
+ <<: *defaults_configure_nvm
140
+ - restore_cache:
141
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
142
+ - run:
143
+ name: Execute lint tests
144
+ command: npm run lint
145
+
100
146
  test-unit:
101
147
  executor: default-docker
102
148
  steps:
@@ -104,6 +150,8 @@ jobs:
104
150
  name: Install general dependencies
105
151
  command: *defaults_Dependencies
106
152
  - checkout
153
+ - run:
154
+ <<: *defaults_configure_nvm
107
155
  - restore_cache:
108
156
  key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
109
157
  - run:
@@ -119,20 +167,9 @@ jobs:
119
167
  steps:
120
168
  - checkout
121
169
  - run:
122
- name: Install Docker Compose
123
- command: |
124
- curl -L https://github.com/docker/compose/releases/download/1.28.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
125
- chmod +x ~/docker-compose
126
- sudo mv ~/docker-compose /usr/local/bin/docker-compose
170
+ <<: *defaults_configure_nvm
127
171
  - restore_cache:
128
172
  key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
129
- - run:
130
- name: Set up NVM
131
- command: |
132
- echo ${NVM_DIR}
133
- [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
134
- nvm install v16.14
135
- nvm alias default v16.14
136
173
  - run:
137
174
  name: Start docker-compose
138
175
  command: |
@@ -142,15 +179,11 @@ jobs:
142
179
  - run:
143
180
  name: Execute Wait4 script
144
181
  command: |
145
- [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
146
182
  chmod +x ./docker/wait4/wait4.js
147
- # chmod +x ./docker/wait4/setup_hosts_file.sh
148
- # sh -c "./docker/wait4/setup_hosts_file.sh"
149
183
  sh -c "./docker/wait4/wait4.js cicd-integration-tests"
150
184
  - run:
151
185
  name: Execute integration tests
152
186
  command: |
153
- [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
154
187
  npm ci
155
188
  npm run test:int
156
189
  - run:
@@ -176,24 +209,6 @@ jobs:
176
209
  name: Execute unit tests
177
210
  command: npm run build:openapi && npm run validate:api
178
211
 
179
- lint:
180
- executor: default-docker
181
- steps:
182
- - run:
183
- name: Install general dependencies
184
- command: *defaults_Dependencies
185
- - checkout
186
- - restore_cache:
187
- key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
188
- - run:
189
- name: Create dir for lint results
190
- command: mkdir -p /lintresults
191
- - run:
192
- name: Execute linting
193
- command: (npm run lint > /lintresults/results.txt)
194
- - store_artifacts:
195
- path: /lintresults
196
-
197
212
  vulnerability-check:
198
213
  executor: default-docker
199
214
  steps:
@@ -201,6 +216,8 @@ jobs:
201
216
  name: Install general dependencies
202
217
  command: *defaults_Dependencies
203
218
  - checkout
219
+ - run:
220
+ <<: *defaults_configure_nvm
204
221
  - restore_cache:
205
222
  key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
206
223
  - run:
@@ -211,6 +228,7 @@ jobs:
211
228
  command: npm run audit:check --silent -- --json > ./audit/results/auditResults.json
212
229
  - store_artifacts:
213
230
  path: ./audit/results
231
+ prefix: audit
214
232
 
215
233
  audit-licenses:
216
234
  executor: default-docker
@@ -232,27 +250,9 @@ jobs:
232
250
  - store_artifacts:
233
251
  path: /tmp/license-scanner/results
234
252
 
235
- build-local:
236
- executor: default-machine
237
- steps:
238
- - checkout
239
- - run:
240
- name: Build Docker local image for testing
241
- command: |
242
- echo "Building Docker image: local"
243
- docker build -t mojaloop/$CIRCLE_PROJECT_REPONAME:local .
244
- - run:
245
- name: Save docker image to workspace
246
- command: docker save -o /tmp/docker-image.tar mojaloop/$CIRCLE_PROJECT_REPONAME:local
247
- - persist_to_workspace:
248
- root: /tmp
249
- paths:
250
- - ./docker-image.tar
251
-
252
253
  license-scan:
253
254
  executor: default-machine
254
255
  steps:
255
- - checkout
256
256
  - attach_workspace:
257
257
  at: /tmp
258
258
  - run:
@@ -262,15 +262,39 @@ jobs:
262
262
  <<: *defaults_license_scanner
263
263
  - run:
264
264
  name: Run the license-scanner
265
- command: cd /tmp/license-scanner && mode=docker dockerImages=mojaloop/$CIRCLE_PROJECT_REPONAME:local make run
265
+ command: cd /tmp/license-scanner && mode=docker dockerImages=$DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG make run
266
266
  - store_artifacts:
267
267
  path: /tmp/license-scanner/results
268
+ prefix: licenses
268
269
 
269
270
  image-scan:
270
271
  executor: anchore/anchore_engine
271
272
  steps:
272
273
  - setup_remote_docker
273
274
  - checkout
275
+ - run:
276
+ name: Setup Slack config
277
+ command: |
278
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
279
+ echo "export SLACK_RELEASE_TYPE='GitHub Release'" >> $BASH_ENV
280
+ echo "export SLACK_RELEASE_TAG='${RELEASE_TAG} on ${CIRCLE_BRANCH} branch'" >> $BASH_ENV
281
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
282
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
283
+ echo "export SLACK_CUSTOM_MSG='Anchore Image Scan failed for: \`${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}:${CIRCLE_TAG}\`'" >> $BASH_ENV
284
+ - run:
285
+ name: Install docker dependencies for anchore
286
+ command: |
287
+ apk add --update py-pip docker python3-dev libffi-dev openssl-dev gcc libc-dev make jq npm
288
+ - run:
289
+ name: Install general dependencies
290
+ command: |
291
+ apk --no-cache add git
292
+ apk --no-cache add ca-certificates
293
+ apk --no-cache add curl
294
+ apk --no-cache add openssh-client
295
+ apk add --no-cache -t build-dependencies make gcc g++ python3 libtool autoconf automake
296
+ npm config set unsafe-perm true
297
+ npm install -g node-gyp
274
298
  - run:
275
299
  name: Install AWS CLI dependencies
276
300
  command: *defaults_awsCliDependencies
@@ -279,42 +303,78 @@ jobs:
279
303
  - run:
280
304
  name: Load the pre-built docker image from workspace
281
305
  command: docker load -i /tmp/docker-image.tar
306
+ - run:
307
+ name: Download the mojaloop/ci-config repo
308
+ command: |
309
+ git clone https://github.com/mojaloop/ci-config /tmp/ci-config
310
+ # Generate the mojaloop anchore-policy
311
+ cd /tmp/ci-config/container-scanning && ./mojaloop-policy-generator.js /tmp/mojaloop-policy.json
312
+ - run:
313
+ name: Pull base image locally
314
+ command: |
315
+ docker pull node:16.15.0-alpine
316
+ # Analyze the base and derived image
317
+ # Note: It seems images are scanned in parallel, so preloading the base image result doesn't give us any real performance gain
282
318
  - anchore/analyze_local_image:
283
- dockerfile_path: ./Dockerfile
284
- image_name: mojaloop/${CIRCLE_PROJECT_REPONAME}:local
285
- # Anchore bug: if policy_failure is `true`, reports don't get written - we manually check for failures below
319
+ # Force the older version, version 0.7.0 was just published, and is broken
320
+ anchore_version: v0.6.1
321
+ image_name: "docker.io/node:16.15.0-alpine $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
286
322
  policy_failure: false
287
323
  timeout: '500'
324
+ # Note: if the generated policy is invalid, this will fallback to the default policy, which we don't want!
325
+ policy_bundle_file_path: /tmp/mojaloop-policy.json
288
326
  - run:
289
- name: Evaluate Failures.
290
- command: |
291
- if [[ ! $(which jq) ]]; then
292
- (set +o pipefail; apk add jq || apt-get install -y jq || yum install -y jq)
293
- fi
294
- if [[ $(ls anchore-reports/*content-os*.json 2> /dev/null) ]]; then
295
- printf "\n%s\n" "The following OS packages are installed:"
296
- jq '[.content | sort_by(.package) | .[] | {package: .package, version: .version}]' anchore-reports/*content-os*.json
297
- fi
298
- if [[ $(ls anchore-reports/*vuln*.json 2> /dev/null) ]]; then
299
- printf "\n%s\n" "The following vulnerabilities were found:"
300
- jq '[.vulnerabilities | group_by(.package) | .[] | {package: .[0].package, vuln: [.[].vuln]}]' anchore-reports/*vuln*.json
301
- fi
302
- # - run:
303
- # name: Upload Anchore reports to s3
304
- # command: |
305
- # aws s3 cp anchore-reports ${AWS_S3_DIR_ANCHORE_REPORTS}/${CIRCLE_PROJECT_REPONAME}/ --recursive
306
- # aws s3 rm ${AWS_S3_DIR_ANCHORE_REPORTS}/latest/ --recursive --exclude "*" --include "${CIRCLE_PROJECT_REPONAME}*"
307
- # aws s3 cp anchore-reports ${AWS_S3_DIR_ANCHORE_REPORTS}/latest/ --recursive
308
-
309
- # TODO: Enable this when we want to increase the strictness of our security policies
310
- # failCount=$(cat anchore-reports/*policy*.json | grep 'fail' | wc -l)
311
- # echo "FailCount is: ${failCount}"
312
- # if [ $failCount -gt 0 ]; then
313
- # printf "Failed with a policy failure count of: ${failCount}"
314
- # exit 1
315
- # fi
327
+ name: Upload Anchore reports to s3
328
+ command: |
329
+ aws s3 cp anchore-reports ${AWS_S3_DIR_ANCHORE_REPORTS}/${CIRCLE_PROJECT_REPONAME}/ --recursive
330
+ aws s3 rm ${AWS_S3_DIR_ANCHORE_REPORTS}/latest/ --recursive --exclude "*" --include "${CIRCLE_PROJECT_REPONAME}*"
331
+ aws s3 cp anchore-reports ${AWS_S3_DIR_ANCHORE_REPORTS}/latest/ --recursive
332
+ - run:
333
+ name: Evaluate failures
334
+ command: /tmp/ci-config/container-scanning/anchore-result-diff.js anchore-reports/node_16.15.0-alpine-policy.json anchore-reports/${CIRCLE_PROJECT_REPONAME}*-policy.json
316
335
  - store_artifacts:
317
336
  path: anchore-reports
337
+ - slack/notify:
338
+ event: fail
339
+ template: SLACK_TEMP_RELEASE_FAILURE
340
+
341
+ build-local:
342
+ executor: default-machine
343
+ steps:
344
+ - checkout
345
+ - run:
346
+ name: Build Docker local image for testing
347
+ command: |
348
+ echo "Building Docker image: local"
349
+ docker build -t $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local .
350
+ - run:
351
+ name: Save docker image to workspace
352
+ command: docker save -o /tmp/docker-image-local.tar $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local
353
+ - persist_to_workspace:
354
+ root: /tmp
355
+ paths:
356
+ - ./docker-image-local.tar
357
+
358
+ build:
359
+ executor: default-machine
360
+ steps:
361
+ - attach_workspace:
362
+ at: /tmp
363
+ - run:
364
+ name: Load the pre-built docker local image from workspace
365
+ command: docker load -i /tmp/docker-image-local.tar
366
+ - run:
367
+ name: Re-tag the image
368
+ command: |
369
+ echo "Re-tagging Docker image: $CIRCLE_TAG"
370
+ docker tag $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
371
+ - run:
372
+ name: Save the new docker image to workspace
373
+ command: docker save -o /tmp/docker-image.tar $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
374
+ - persist_to_workspace:
375
+ root: /tmp
376
+ paths:
377
+ - ./docker-image.tar
318
378
 
319
379
  release:
320
380
  executor: default-docker
@@ -323,26 +383,30 @@ jobs:
323
383
  name: Install general dependencies
324
384
  command: *defaults_Dependencies
325
385
  - checkout
386
+ - run:
387
+ <<: *defaults_configure_nvm
326
388
  - restore_cache:
327
- key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
389
+ keys:
390
+ - dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
328
391
  - run:
329
- name: Configure git
330
- command: |
331
- git config user.email ${GIT_CI_EMAIL}
332
- git config user.name ${GIT_CI_USER}
333
- git checkout ${CIRCLE_BRANCH}
392
+ <<: *defaults_configure_git
334
393
  - run:
335
- name: Configure ssh
394
+ name: Setup Slack config
336
395
  command: |
337
- mkdir -p ~/.ssh
338
- ssh-keyscan -p 443 ssh.github.com >> ~/.ssh/known_hosts
339
- ssh-keyscan github.com >> ~/.ssh/known_hosts
396
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
397
+ echo "export SLACK_RELEASE_TYPE='GitHub Release'" >> $BASH_ENV
398
+ echo "export SLACK_RELEASE_TAG='${RELEASE_TAG} on ${CIRCLE_BRANCH} branch'" >> $BASH_ENV
399
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
400
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
340
401
  - run:
341
402
  name: Generate changelog and bump package version
342
- command: npm run release
403
+ command: npm run release -- --no-verify
343
404
  - run:
344
405
  name: Push the release
345
406
  command: git push --follow-tags origin ${CIRCLE_BRANCH}
407
+ - slack/notify:
408
+ event: fail
409
+ template: SLACK_TEMP_RELEASE_FAILURE
346
410
 
347
411
  github-release:
348
412
  executor: default-machine
@@ -351,77 +415,236 @@ jobs:
351
415
  name: Install git
352
416
  command: |
353
417
  sudo apt-get update && sudo apt-get install -y git
418
+ - gh/install
354
419
  - checkout
420
+ - run:
421
+ <<: *defaults_configure_git
355
422
  - run:
356
423
  name: Fetch updated release branch
357
424
  command: |
358
- git config user.email ${GIT_CI_EMAIL}
359
- git config user.name ${GIT_CI_USER}
360
425
  git fetch origin
361
426
  git checkout origin/${CIRCLE_BRANCH}
362
427
  - run:
363
- # Note: this is rather imperfect, but will do for now
364
- name: Format the changelog into the github release body and get release tag
365
- command: |
366
- git diff --no-indent-heuristic master~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
367
- echo 'export RELEASE_CHANGES=`cat /tmp/changes`' >> $BASH_ENV
368
- echo 'export RELEASE_TAG=`cat package-lock.json | jq -r .version`' >> $BASH_ENV
428
+ <<: *defaults_export_version_from_package
369
429
  - run:
370
- name: check the release changes
430
+ name: Check the release changes
371
431
  command: |
372
432
  echo "Changes are: ${RELEASE_CHANGES}"
373
- - github-release/create:
374
- github-token-variable: ${GITHUB_TOKEN}
375
- tag: v${RELEASE_TAG}
376
- title: v${RELEASE_TAG} Release
377
- description: ${RELEASE_CHANGES}
378
- file-path: CHANGELOG.md
379
- - slack/status:
380
- webhook: "$SLACK_WEBHOOK_ANNOUNCEMENT"
381
- success_message: '*"${CIRCLE_PROJECT_REPONAME}"* - Release \`"v${RELEASE_TAG}"\` \nhttps://github.com/mojaloop/"${CIRCLE_PROJECT_REPONAME}"/releases/tag/"v${RELEASE_TAG}"'
433
+ - run:
434
+ name: Setup Slack config
435
+ command: |
436
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
437
+ echo "export SLACK_RELEASE_TYPE='Github Release'" >> $BASH_ENV
438
+ echo "export SLACK_RELEASE_TAG=v${RELEASE_TAG}" >> $BASH_ENV
439
+ echo "export SLACK_RELEASE_URL=https://github.com/mojaloop/${CIRCLE_PROJECT_REPONAME}/releases/tag/v${RELEASE_TAG}" >> $BASH_ENV
440
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
441
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
442
+ - run:
443
+ name: Create Release
444
+ command: |
445
+ gh release create "v${RELEASE_TAG}" --title "v${RELEASE_TAG} Release" --draft=false --notes "${RELEASE_CHANGES}" ./CHANGELOG.md
446
+ - slack/notify:
447
+ event: pass
448
+ template: SLACK_TEMP_RELEASE_SUCCESS
449
+ - slack/notify:
450
+ event: fail
451
+ template: SLACK_TEMP_RELEASE_FAILURE
382
452
 
383
453
  publish-docker:
384
454
  executor: default-machine
385
455
  steps:
386
456
  - checkout
457
+ - run:
458
+ name: Setup for LATEST release
459
+ command: |
460
+ echo "export RELEASE_TAG=$RELEASE_TAG_PROD" >> $BASH_ENV
461
+ echo "RELEASE_TAG=$RELEASE_TAG_PROD"
462
+
463
+ PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
464
+ echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
465
+ echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
466
+ - run:
467
+ name: Setup Slack config
468
+ command: |
469
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
470
+ echo "export SLACK_RELEASE_TYPE='Docker Release'" >> $BASH_ENV
471
+ echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
472
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
473
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
387
474
  - attach_workspace:
388
475
  at: /tmp
389
476
  - run:
390
477
  name: Load the pre-built docker image from workspace
391
- command: docker load -i /tmp/docker-image.tar
478
+ command: |
479
+ docker load -i /tmp/docker-image.tar
392
480
  - run:
393
481
  name: Login to Docker Hub
394
482
  command: docker login -u $DOCKER_USER -p $DOCKER_PASS
395
483
  - run:
396
484
  name: Re-tag pre built image
397
485
  command: |
398
- docker tag $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:latest
399
- docker tag $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
486
+ docker tag $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
487
+ - run:
488
+ name: Publish Docker image $CIRCLE_TAG & Latest tag to Docker Hub
489
+ command: |
490
+ echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
491
+ docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
492
+ echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG"
493
+ docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
494
+ - run:
495
+ name: Set Image Digest
496
+ command: |
497
+ IMAGE_DIGEST=$(docker inspect $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:v${CIRCLE_TAG:1} | jq '.[0].RepoDigests | .[]')
498
+ echo "IMAGE_DIGEST=${IMAGE_DIGEST}"
499
+ echo "export IMAGE_DIGEST=${IMAGE_DIGEST}" >> $BASH_ENV
500
+ - run:
501
+ name: Update Slack config
502
+ command: |
503
+ echo "export SLACK_RELEASE_URL='https://hub.docker.com/layers/${CIRCLE_PROJECT_REPONAME}/${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}/v${CIRCLE_TAG:1}/images/${IMAGE_DIGEST}?context=explore'" | sed -r "s/${DOCKER_ORG}\/${CIRCLE_PROJECT_REPONAME}@sha256:/sha256-/g" >> $BASH_ENV
504
+ - slack/notify:
505
+ event: pass
506
+ template: SLACK_TEMP_RELEASE_SUCCESS
507
+ - slack/notify:
508
+ event: fail
509
+ template: SLACK_TEMP_RELEASE_FAILURE
510
+
511
+ publish-docker-snapshot:
512
+ executor: default-machine
513
+ steps:
514
+ - checkout
515
+ - run:
516
+ name: Setup for SNAPSHOT release
517
+ command: |
518
+ echo "export RELEASE_TAG=$RELEASE_TAG_SNAPSHOT" >> $BASH_ENV
519
+ echo "RELEASE_TAG=$RELEASE_TAG_SNAPSHOT"
520
+
521
+ PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
522
+ echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
523
+ echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
524
+ - run:
525
+ name: Setup Slack config
526
+ command: |
527
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
528
+ echo "export SLACK_RELEASE_TYPE='Docker Release'" >> $BASH_ENV
529
+ echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
530
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
531
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
532
+ - attach_workspace:
533
+ at: /tmp
534
+ - run:
535
+ name: Load the pre-built docker image from workspace
536
+ command: |
537
+ docker load -i /tmp/docker-image.tar
538
+ - run:
539
+ name: Login to Docker Hub
540
+ command: docker login -u $DOCKER_USER -p $DOCKER_PASS
541
+ - run:
542
+ name: Re-tag pre built image
543
+ command: |
544
+ docker tag $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
400
545
  - run:
401
546
  name: Publish Docker image $CIRCLE_TAG & Latest tag to Docker Hub
402
547
  command: |
403
548
  echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
404
549
  docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
405
- echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:latest"
406
- docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:latest
550
+ echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG"
551
+ docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
552
+ - run:
553
+ name: Set Image Digest
554
+ command: |
555
+ IMAGE_DIGEST=$(docker inspect $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:v${CIRCLE_TAG:1} | jq '.[0].RepoDigests | .[]')
556
+ echo "IMAGE_DIGEST=${IMAGE_DIGEST}"
557
+ echo "export IMAGE_DIGEST=${IMAGE_DIGEST}" >> $BASH_ENV
558
+ - run:
559
+ name: Update Slack config
560
+ command: |
561
+ echo "export SLACK_RELEASE_URL='https://hub.docker.com/layers/${CIRCLE_PROJECT_REPONAME}/${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}/v${CIRCLE_TAG:1}/images/${IMAGE_DIGEST}?context=explore'" | sed -r "s/${DOCKER_ORG}\/${CIRCLE_PROJECT_REPONAME}@sha256:/sha256-/g" >> $BASH_ENV
562
+ - slack/notify:
563
+ event: pass
564
+ template: SLACK_TEMP_RELEASE_SUCCESS
565
+ - slack/notify:
566
+ event: fail
567
+ template: SLACK_TEMP_RELEASE_FAILURE
407
568
 
408
569
  publish-npm:
409
570
  executor: default-docker
410
571
  steps:
572
+ - run:
573
+ name: Install general dependencies
574
+ command: *defaults_Dependencies
411
575
  - checkout
576
+ - restore_cache:
577
+ key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
578
+ - run:
579
+ name: Setup for LATEST release
580
+ command: |
581
+ echo "export RELEASE_TAG=$RELEASE_TAG_PROD" >> $BASH_ENV
582
+ echo "RELEASE_TAG=$RELEASE_TAG_PROD"
583
+
584
+ PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
585
+ echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
586
+ echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
587
+ - run:
588
+ name: Setup Slack config
589
+ command: |
590
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
591
+ echo "export SLACK_RELEASE_TYPE='NPM Release'" >> $BASH_ENV
592
+ echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
593
+ echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
594
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
595
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
596
+ - run:
597
+ <<: *defaults_npm_auth
598
+ - run:
599
+ <<: *defaults_npm_publish_release
600
+ - slack/notify:
601
+ event: pass
602
+ template: SLACK_TEMP_RELEASE_SUCCESS
603
+ - slack/notify:
604
+ event: fail
605
+ template: SLACK_TEMP_RELEASE_FAILURE
606
+
607
+ publish-npm-snapshot:
608
+ executor: default-docker
609
+ steps:
412
610
  - run:
413
611
  name: Install general dependencies
414
612
  command: *defaults_Dependencies
613
+ - checkout
415
614
  - restore_cache:
416
615
  key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
417
616
  - run:
418
- name: setup environment vars for LATEST release
617
+ name: Setup for SNAPSHOT release
419
618
  command: |
420
- echo 'export RELEASE_TAG=$RELEASE_TAG_PROD' >> $BASH_ENV
619
+ echo "export RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}" >> $BASH_ENV
620
+ echo "RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}"
621
+
622
+ echo "Override package version: ${CIRCLE_TAG:1}"
623
+ npx standard-version --skip.tag --skip.commit --skip.changelog --release-as ${CIRCLE_TAG:1}
624
+
625
+ PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
626
+ echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
627
+ echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
628
+ - run:
629
+ name: Setup Slack config
630
+ command: |
631
+ echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
632
+ echo "export SLACK_RELEASE_TYPE='NPM Snapshot'" >> $BASH_ENV
633
+ echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
634
+ echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
635
+ echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
636
+ echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
421
637
  - run:
422
638
  <<: *defaults_npm_auth
423
639
  - run:
424
640
  <<: *defaults_npm_publish_release
641
+ - slack/notify:
642
+ event: pass
643
+ template: SLACK_TEMP_RELEASE_SUCCESS
644
+ - slack/notify:
645
+ event: fail
646
+ template: SLACK_TEMP_RELEASE_FAILURE
647
+
425
648
  ##
426
649
  # Workflows
427
650
  #
@@ -442,8 +665,7 @@ workflows:
442
665
  ignore:
443
666
  - /feature*/
444
667
  - /bugfix*/
445
-
446
- - test-unit:
668
+ - test-dependencies:
447
669
  context: org-global
448
670
  requires:
449
671
  - setup
@@ -454,8 +676,7 @@ workflows:
454
676
  ignore:
455
677
  - /feature*/
456
678
  - /bugfix*/
457
-
458
- - validate-openapi:
679
+ - test-lint:
459
680
  context: org-global
460
681
  requires:
461
682
  - setup
@@ -466,8 +687,18 @@ workflows:
466
687
  ignore:
467
688
  - /feature*/
468
689
  - /bugfix*/
469
-
470
- - lint:
690
+ - test-unit:
691
+ context: org-global
692
+ requires:
693
+ - setup
694
+ filters:
695
+ tags:
696
+ only: /.*/
697
+ branches:
698
+ ignore:
699
+ - /feature*/
700
+ - /bugfix*/
701
+ - validate-openapi:
471
702
  context: org-global
472
703
  requires:
473
704
  - setup
@@ -478,7 +709,6 @@ workflows:
478
709
  ignore:
479
710
  - /feature*/
480
711
  - /bugfix*/
481
-
482
712
  - test-integration:
483
713
  context: org-global
484
714
  requires:
@@ -490,7 +720,6 @@ workflows:
490
720
  ignore:
491
721
  - /feature*/
492
722
  - /bugfix*/
493
-
494
723
  - vulnerability-check:
495
724
  context: org-global
496
725
  requires:
@@ -513,64 +742,75 @@ workflows:
513
742
  ignore:
514
743
  - /feature*/
515
744
  - /bugfix*/
516
-
517
745
  - build-local:
518
746
  context: org-global
519
747
  requires:
520
- - test-integration
521
- - validate-openapi
522
- - test-unit
748
+ - setup
523
749
  filters:
524
750
  tags:
525
- only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
751
+ only: /.*/
526
752
  branches:
527
753
  ignore:
528
754
  - /feature*/
529
755
  - /bugfix*/
530
-
531
- - image-scan:
756
+ - build:
532
757
  context: org-global
533
758
  requires:
759
+ - setup
760
+ - test-dependencies
761
+ - test-lint
762
+ - test-unit
763
+ - test-integration
764
+ - vulnerability-check
765
+ - audit-licenses
534
766
  - build-local
767
+ - validate-openapi
535
768
  filters:
536
769
  tags:
537
- only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
770
+ only: /v[0-9]+(\.[0-9]+)*(\-snapshot(\.[0-9]+)?)?(\-hotfix(\.[0-9]+)?)?(\-perf(\.[0-9]+)?)?/
538
771
  branches:
539
772
  ignore:
540
- - /feature*/
541
- - /bugfix*/
542
-
773
+ - /.*/
543
774
  - license-scan:
544
775
  context: org-global
545
776
  requires:
546
- - build-local
777
+ - build
547
778
  filters:
548
779
  tags:
549
- only: /v[0-9]+(\.[0-9]+)*(\-snapshot)?/
780
+ only: /v[0-9]+(\.[0-9]+)*(\-snapshot(\.[0-9]+)?)?(\-hotfix(\.[0-9]+)?)?(\-perf(\.[0-9]+)?)?/
550
781
  branches:
551
782
  ignore:
552
- - /feature*/
553
- - /bugfix*/
554
-
783
+ - /.*/
784
+ - image-scan:
785
+ context: org-global
786
+ requires:
787
+ - build
788
+ filters:
789
+ tags:
790
+ only: /v[0-9]+(\.[0-9]+)*(\-snapshot(\.[0-9]+)?)?(\-hotfix(\.[0-9]+)?)?(\-perf(\.[0-9]+)?)?/
791
+ branches:
792
+ ignore:
793
+ - /.*/
555
794
  # New commits to master release automatically
556
795
  - release:
557
796
  context: org-global
558
797
  requires:
559
- - build-local
560
798
  - pr-tools/pr-title-check
561
- - validate-openapi
799
+ - test-dependencies
800
+ - test-lint
562
801
  - test-unit
802
+ - build
803
+ - test-integration
563
804
  - vulnerability-check
564
805
  - audit-licenses
565
- - test-integration
566
806
  - license-scan
567
807
  - image-scan
808
+ - validate-openapi
568
809
  filters:
569
810
  branches:
570
811
  only:
571
812
  - master
572
813
  - /release\/v.*/
573
-
574
814
  - github-release:
575
815
  context: org-global
576
816
  requires:
@@ -580,40 +820,81 @@ workflows:
580
820
  only:
581
821
  - master
582
822
  - /release\/v.*/
583
-
584
823
  - publish-docker:
585
824
  context: org-global
586
825
  requires:
587
- - build-local
588
826
  - pr-tools/pr-title-check
827
+ - test-dependencies
828
+ - test-lint
829
+ - test-unit
830
+ - build
831
+ - test-integration
832
+ - vulnerability-check
833
+ - audit-licenses
834
+ - license-scan
835
+ - image-scan
589
836
  - validate-openapi
837
+ filters:
838
+ tags:
839
+ only: /v[0-9]+(\.[0-9]+)*/
840
+ branches:
841
+ ignore:
842
+ - /.*/
843
+ - publish-docker-snapshot:
844
+ context: org-global
845
+ requires:
846
+ - pr-tools/pr-title-check
847
+ - test-dependencies
848
+ - test-lint
590
849
  - test-unit
850
+ - build
591
851
  - vulnerability-check
592
852
  - audit-licenses
593
853
  - test-integration
594
854
  - license-scan
595
855
  - image-scan
856
+ - validate-openapi
596
857
  filters:
597
858
  tags:
598
- only: /.*/
859
+ only: /v[0-9]+(\.[0-9]+)*\-snapshot+((\.[0-9]+)?)/
599
860
  branches:
600
861
  ignore:
601
862
  - /.*/
602
-
603
863
  - publish-npm:
604
864
  context: org-global
605
865
  requires:
606
866
  - pr-tools/pr-title-check
867
+ - test-dependencies
868
+ - test-lint
869
+ - test-unit
870
+ - vulnerability-check
871
+ - audit-licenses
872
+ - test-integration
873
+ - license-scan
874
+ - image-scan
607
875
  - validate-openapi
876
+ filters:
877
+ tags:
878
+ only: /v[0-9]+(\.[0-9]+)*/
879
+ branches:
880
+ ignore:
881
+ - /.*/
882
+ - publish-npm-snapshot:
883
+ context: org-global
884
+ requires:
885
+ - pr-tools/pr-title-check
886
+ - test-dependencies
887
+ - test-lint
608
888
  - test-unit
609
889
  - vulnerability-check
610
890
  - audit-licenses
611
891
  - test-integration
612
892
  - license-scan
613
893
  - image-scan
894
+ - validate-openapi
614
895
  filters:
615
896
  tags:
616
- only: /.*/
897
+ only: /v[0-9]+(\.[0-9]+)*\-snapshot+((\.[0-9]+)?)/
617
898
  branches:
618
899
  ignore:
619
900
  - /.*/