From 7de48c8f59a32030a0b1d4149399a0c589a3f1a9 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Wed, 6 Jul 2022 21:15:34 +0100 Subject: [PATCH] Update from template. Enables use of contexts for CI credentials. --- .circleci/config.yml | 51 +++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9ec2126..54391f6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,44 +1,53 @@ -version: 2 +version: 2.1 defaults: &defaults working_directory: ~/repo docker: - - image: circleci/node:10.15.0 + - image: cimg/node:14.19 + +_steps: + restore_npm_cache: &restore_npm_cache + restore_cache: + keys: + - npm-v1-{{ .Branch }}-{{ checksum "package-lock.json" }} + - npm-v1-{{ .Branch }}- + - npm-v1- + save_npm_cache: &save_npm_cache + save_cache: + paths: + - .npm-cache + key: npm-v1-{{ .Branch }}-{{ checksum "package-lock.json" }} + configure_registry_auth: &configure_registry_auth + run: + name: Configure registry auth + command: echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/repo/.npmrc jobs: - test_and_build: + test: <<: *defaults steps: - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package-lock.json" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - run: npm ci + - *restore_npm_cache + - *configure_registry_auth + - run: npm ci --cache .npm-cache - run: name: Run coverage tests command: npm run test:coverage - run: - name: Build + name: Run build command: npm run build - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package-lock.json" }} - persist_to_workspace: root: ~/repo paths: . - store_artifacts: path: ~/repo/dist + - *save_npm_cache deploy: <<: *defaults steps: - attach_workspace: at: ~/repo - - run: - name: Configure registry auth - command: echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/repo/.npmrc + - *configure_registry_auth - run: name: Publish package # For now we only publish on tags here and assume the version number is already correct. @@ -49,13 +58,17 @@ workflows: version: 2 test-deploy: jobs: - - test_and_build: + - test: + context: + - "NPM Read" filters: tags: only: /^v.*/ - deploy: + context: + - "NPM Write" requires: - - test_and_build + - test filters: tags: only: /^v.*/