Skip to content

Commit

Permalink
chore: add ci to publish npm package (#909)
Browse files Browse the repository at this point in the history
* chore: add ci to publish npm package

* chore(snapshot): 15.1.3-snapshot.0

* chore: dep audit

* chore(snapshot): 15.1.3-snapshot.1

* chore: audit

* chore(snapshot): 15.1.3-snapshot.2

* chore: address comments

* chore: address comments

* chore: npmignore
  • Loading branch information
kleyow authored Jul 12, 2022
1 parent a2b1e17 commit f0ac068
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 934 deletions.
162 changes: 140 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ version: 2.1
# Orbs used in this pipeline
##
orbs:
anchore: anchore/[email protected]
slack: circleci/[email protected] # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
pr-tools: mojaloop/[email protected] # Ref: https://github.com/mojaloop/ci-config/
gh: circleci/[email protected]
anchore: anchore/[email protected]
deploy-kube: mojaloop/[email protected]

##
# defaults
Expand All @@ -38,6 +37,17 @@ defaults_license_scanner: &defaults_license_scanner
git clone https://github.com/mojaloop/license-scanner /tmp/license-scanner
cd /tmp/license-scanner && make build default-files set-up
defaults_npm_auth: &defaults_npm_auth
name: Update NPM registry auth token
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc

defaults_npm_publish_release: &defaults_npm_publish_release
name: Publish NPM $RELEASE_TAG artifact
command: |
source $BASH_ENV
echo "Publishing tag $RELEASE_TAG"
npm publish --tag $RELEASE_TAG --access public
defaults_export_version_from_package: &defaults_export_version_from_package
name: Format the changelog into the github release body and get release tag
command: |
Expand Down Expand Up @@ -181,16 +191,6 @@ jobs:
prefix: test
- store_test_results:
path: coverage
- run:
name: Copy code coverage to SonarQube
command: |
if [ "${CIRCLE_BRANCH}" == "master" ];
then
echo "Sending lcov.info to SonarQube..."
aws s3 cp coverage/lcov.info $AWS_S3_DIR_SONARQUBE/${CIRCLE_PROJECT_REPONAME}/lcov.info
else
echo "Not a release (env CIRCLE_BRANCH != 'master'), skipping sending lcov.info to SonarQube."
fi

test-integration:
executor: default-machine
Expand All @@ -207,17 +207,17 @@ jobs:
name: Build and start the docker containers
command: |
## This is not needed as we are only doing narrow-integration tests.
# docker-compose build
# docker-compose build
## Lets pull only the Services needed for the Integration Test
docker-compose pull mysql kafka
## Lets startup only the Services needed for the Integration Test
docker-compose up -d mysql kafka
## Check straight away to see if any containers have exited
docker-compose ps
## wait for services to be up and running
npm run wait-4-docker
- run:
Expand All @@ -226,7 +226,7 @@ jobs:
npm rebuild
npm run test:int
environment:
ENDPOINT_URL: http://localhost:4545/notification
ENDPOINT_URL: http://localhost:4545/notification
- store_artifacts:
path: ./test/results
prefix: test
Expand Down Expand Up @@ -499,7 +499,7 @@ jobs:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE

publish:
publish-docker:
executor: default-machine
steps:
- checkout
Expand All @@ -524,7 +524,7 @@ jobs:
at: /tmp
- run:
name: Load the pre-built docker image from workspace
command: |
command: |
docker load -i /tmp/docker-image.tar
- run:
name: Login to Docker Hub
Expand Down Expand Up @@ -557,7 +557,7 @@ jobs:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE

publish-snapshot:
publish-docker-snapshot:
executor: default-machine
steps:
- checkout
Expand All @@ -582,7 +582,7 @@ jobs:
at: /tmp
- run:
name: Load the pre-built docker image from workspace
command: |
command: |
docker load -i /tmp/docker-image.tar
- run:
name: Login to Docker Hub
Expand Down Expand Up @@ -615,6 +615,82 @@ jobs:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE

publish-npm:
executor: default-docker
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Setup for LATEST release
command: |
echo "export RELEASE_TAG=$RELEASE_TAG_PROD" >> $BASH_ENV
echo "RELEASE_TAG=$RELEASE_TAG_PROD"
PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='NPM Release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- run:
<<: *defaults_npm_auth
- run:
<<: *defaults_npm_publish_release
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE

publish-npm-snapshot:
executor: default-docker
steps:
- run:
name: Install general dependencies
command: *defaults_Dependencies
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Setup for SNAPSHOT release
command: |
echo "export RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}" >> $BASH_ENV
echo "RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}"
echo "Override package version: ${CIRCLE_TAG:1}"
npx standard-version --skip.tag --skip.commit --skip.changelog --release-as ${CIRCLE_TAG:1}
PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='NPM Snapshot'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- run:
<<: *defaults_npm_auth
- run:
<<: *defaults_npm_publish_release
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE

##
# Workflows
#
Expand Down Expand Up @@ -803,7 +879,49 @@ workflows:
only:
- master
- /release\/v.*/
- publish:
- publish-docker:
context: org-global
requires:
- pr-tools/pr-title-check
- test-dependencies
- test-lint
- test-unit
- build
- test-coverage
- test-integration
- test-functional
- vulnerability-check
- audit-licenses
- license-scan
- image-scan
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*/
branches:
ignore:
- /.*/
- publish-docker-snapshot:
context: org-global
requires:
- pr-tools/pr-title-check
- test-dependencies
- test-lint
- test-unit
- build
- test-coverage
- test-integration
- test-functional
- vulnerability-check
- audit-licenses
- license-scan
- image-scan
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*\-snapshot+((\.[0-9]+)?)/
branches:
ignore:
- /.*/
- publish-npm:
context: org-global
requires:
- pr-tools/pr-title-check
Expand All @@ -823,7 +941,7 @@ workflows:
branches:
ignore:
- /.*/
- publish-snapshot:
- publish-npm-snapshot:
context: org-global
requires:
- pr-tools/pr-title-check
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ devspace*
# Add ignores
*IGNORE*
*ignore*
!.npmignore
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore tests for publishing
test/*
.circleci/*
64 changes: 62 additions & 2 deletions audit-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
},
"1070030|widdershins>markdown-it": {
"decision": "ignore",
"madeAt": 1657029293742,
"expiresAt": 1659621287320
"madeAt": 1657547585781,
"expiresAt": 1660139581210
},
"1068155|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>shins>markdown-it>sanitize-html": {
"decision": "ignore",
Expand Down Expand Up @@ -79,6 +79,66 @@
"decision": "ignore",
"madeAt": 1657029308195,
"expiresAt": 1659621287320
},
"1080969|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>moment": {
"decision": "ignore",
"madeAt": 1657547584804,
"expiresAt": 1660139581210
},
"1080969|@mojaloop/event-sdk>grpc>protobufjs>moment": {
"decision": "ignore",
"madeAt": 1657547584804,
"expiresAt": 1660139581210
},
"1070030|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>moment>shins>markdown-it": {
"decision": "ignore",
"madeAt": 1657547585781,
"expiresAt": 1660139581210
},
"1068155|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>moment>shins>markdown-it>sanitize-html": {
"decision": "ignore",
"madeAt": 1657547586612,
"expiresAt": 1660139581210
},
"1070260|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>moment>shins>markdown-it>sanitize-html": {
"decision": "ignore",
"madeAt": 1657547587381,
"expiresAt": 1660139581210
},
"1070030|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>moment>widdershins>markdown-it": {
"decision": "ignore",
"madeAt": 1657548277077,
"expiresAt": 1660140273753
},
"1070030|shins>markdown-it": {
"decision": "ignore",
"madeAt": 1657548277077,
"expiresAt": 1660140273753
},
"1068310|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>moment>widdershins>markdown-it>yargs>yargs-parser": {
"decision": "ignore",
"madeAt": 1657548277911,
"expiresAt": 1660140273753
},
"1068155|shins>markdown-it>sanitize-html": {
"decision": "ignore",
"madeAt": 1657548278663,
"expiresAt": 1660140273753
},
"1070260|shins>markdown-it>sanitize-html": {
"decision": "ignore",
"madeAt": 1657548279466,
"expiresAt": 1660140273753
},
"1081008|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>protobufjs>moment": {
"decision": "ignore",
"madeAt": 1657629511965,
"expiresAt": 1660221505784
},
"1081008|@mojaloop/event-sdk>grpc>protobufjs>moment": {
"decision": "ignore",
"madeAt": 1657629511965,
"expiresAt": 1660221505784
}
},
"rules": {},
Expand Down
Loading

0 comments on commit f0ac068

Please sign in to comment.