|
3 | 3 | # Check https://circleci.com/docs/2.0/language-javascript/ for more details |
4 | 4 | # |
5 | 5 | version: 2 |
| 6 | +workflows: |
| 7 | + version: 2 |
| 8 | + build_and_deploy: |
| 9 | + jobs: |
| 10 | + - build: |
| 11 | + filters: |
| 12 | + tags: |
| 13 | + only: /.*/ |
| 14 | + - deploy: |
| 15 | + requires: |
| 16 | + - build |
| 17 | + filters: |
| 18 | + tags: |
| 19 | + only: /[0-9]+(\.[0-9]+)*/ |
| 20 | + branches: |
| 21 | + only: |
| 22 | + - master |
| 23 | + |
6 | 24 | jobs: |
7 | 25 | build: |
| 26 | + working_directory: ~/repo |
8 | 27 | docker: |
9 | | - # specify the version you desire here |
10 | 28 | - image: circleci/node:10.0 |
11 | 29 |
|
12 | | - # Specify service dependencies here if necessary |
13 | | - # CircleCI maintains a library of pre-built images |
14 | | - # documented at https://circleci.com/docs/2.0/circleci-images/ |
15 | | - # - image: circleci/mongo:3.4.4 |
16 | | - |
17 | | - working_directory: ~/repo |
18 | | - |
19 | 30 | steps: |
20 | 31 | - checkout |
21 | | - |
22 | | - # Download and cache dependencies |
23 | | - - restore_cache: |
| 32 | + - restore_cache: # ensure this step occurs *before* installing dependencies |
24 | 33 | keys: |
25 | | - - v1-dependencies-{{ checksum "package.json" }} |
26 | | - # fallback to using the latest cache if no exact match is found |
27 | | - - v1-dependencies- |
28 | | - |
| 34 | + - v{{ .Environment.CACHE_VERSION }}-dep-cache-{{ .Branch }}-{{ checksum "package.json" }} |
| 35 | + - v{{ .Environment.CACHE_VERSION }}-dep-cache-{{ .Branch }}- |
| 36 | + - v{{ .Environment.CACHE_VERSION }}-dep-cache- |
29 | 37 | - run: npm install |
30 | | - |
31 | 38 | - save_cache: |
32 | 39 | paths: |
33 | 40 | - node_modules |
34 | | - key: v1-dependencies-{{ checksum "package.json" }} |
35 | | - |
36 | | - # run tests! |
| 41 | + key: v{{ .Environment.CACHE_VERSION }}-dep-cache-{{ .Branch }}-{{ checksum "package.json" }} |
37 | 42 | - run: npm test |
| 43 | + deploy: |
| 44 | + working_directory: ~/repo |
| 45 | + docker: |
| 46 | + - image: circleci/node:10.0 |
| 47 | + steps: |
| 48 | + - checkout |
| 49 | + - restore_cache: # ensure this step occurs *before* installing dependencies |
| 50 | + keys: |
| 51 | + - v{{ .Environment.CACHE_VERSION }}-dep-cache-{{ .Branch }}-{{ checksum "package.json" }} |
| 52 | + - v{{ .Environment.CACHE_VERSION }}-dep-cache-{{ .Branch }}- |
| 53 | + - v{{ .Environment.CACHE_VERSION }}-dep-cache- |
| 54 | + - run: npm install |
| 55 | + - save_cache: |
| 56 | + paths: |
| 57 | + - node_modules |
| 58 | + key: v{{ .Environment.CACHE_VERSION }}-dep-cache-{{ .Branch }}-{{ checksum "package.json" }} |
| 59 | + - run: |
| 60 | + name: Authenticate with registry |
| 61 | + command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc |
| 62 | + - run: |
| 63 | + name: Publish package |
| 64 | + command: npm publish |
0 commit comments