From 26945ae50f85a98d8da3a1657cb8be3006d2c748 Mon Sep 17 00:00:00 2001 From: Morley Zhi Date: Thu, 18 Apr 2019 16:03:01 -0400 Subject: [PATCH] Publish with CircleCI (#33) Add CircleCI support for publishing to NPM when there's a new version tag. --- .circleci/config.yml | 87 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index eb456700..f7b8492f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,19 +3,48 @@ # Check https://circleci.com/docs/2.0/language-javascript/ for more details # version: 2 + +defaults: &defaults + docker: + # specify the version you desire here + - image: circleci/node:lts + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/mongo:3.4.4 + + working_directory: ~/repo + jobs: - build: - docker: - # specify the version you desire here - - image: circleci/node:lts + test: + <<: *defaults + steps: + - checkout - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/mongo:3.4.4 + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- - working_directory: ~/repo + - run: yarn install + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + + # run tests! + - run: yarn test:ci + + - persist_to_workspace: + root: ~/repo + paths: . + + build: + <<: *defaults steps: - checkout @@ -35,3 +64,43 @@ jobs: # run tests! - run: yarn test:ci + + # build + - run: yarn build + + - persist_to_workspace: + root: ~/repo + paths: . + + deploy: + <<: *defaults + steps: + - attach_workspace: + at: ~/repo + - run: + name: Authenticate with registry + command: + echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/repo/.npmrc + - run: + name: Publish package + command: npm publish + +workflows: + version: 2 + only_test: + jobs: + - test + test-deploy: + jobs: + - build: + filters: + tags: + only: /^v.*/ + - deploy: + requires: + - build + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/