|
| 1 | +# Javascript Node CircleCI 2.0 configuration file |
| 2 | +# |
| 3 | +# Check https://circleci.com/docs/2.0/language-javascript/ for more details |
| 4 | +# |
| 5 | +version: 2.1 |
| 6 | + |
| 7 | +npm-login: &npm-login |
| 8 | + # NPM_TOKEN is manually defined in CircleCI |
| 9 | + # project settings > Build settings > Environment variables |
| 10 | + # Add the NPM_TOKEN name and the value is your npm token |
| 11 | + # Get your npm token via npm token create |
| 12 | + # https://docs.npmjs.com/cli/token |
| 13 | + run: |
| 14 | + name: Create .npmrc |
| 15 | + command: | |
| 16 | + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc |
| 17 | +
|
| 18 | +orbs: |
| 19 | + node: circleci/node@1.1.6 |
| 20 | + |
| 21 | +jobs: |
| 22 | + test: |
| 23 | + executor: |
| 24 | + name: node/default |
| 25 | + tag: '10' |
| 26 | + working_directory: ~/repo |
| 27 | + steps: |
| 28 | + # Check out the git repo to the working directory |
| 29 | + - checkout |
| 30 | + - add_ssh_keys: |
| 31 | + fingerprints: |
| 32 | + # You need to add a deploy key with write permission in order for the CI to commit changes |
| 33 | + # back to the repo |
| 34 | + # https://circleci.com/docs/2.0/gh-bb-integration/#adding-readwrite-deployment-keys-to-github-or-bitbucket |
| 35 | + - "36:2c:16:f2:d0:59:13:25:f1:7f:44:87:a4:52:8f:03" |
| 36 | + # Download and cache dependencies so subsequent builds run faster |
| 37 | + - restore_cache: |
| 38 | + keys: |
| 39 | + - dependencies-{{ checksum "package-lock.json" }} |
| 40 | + # fallback to using the latest cache if no exact match is found |
| 41 | + - dependencies- |
| 42 | + - run: |
| 43 | + name: Install deps |
| 44 | + command: | |
| 45 | + npm i |
| 46 | + - save_cache: |
| 47 | + paths: |
| 48 | + - node_modules |
| 49 | + key: dependencies-{{ checksum "package-lock.json" }} |
| 50 | + - run: |
| 51 | + name: Run tests |
| 52 | + command: | |
| 53 | + npm run test:ci |
| 54 | + - run: |
| 55 | + name: Build the libraries |
| 56 | + command: | |
| 57 | + npm run build |
| 58 | + publish: |
| 59 | + executor: |
| 60 | + name: node/default |
| 61 | + tag: '12' |
| 62 | + working_directory: ~/repo |
| 63 | + steps: |
| 64 | + # Check out the git repo to the working directory |
| 65 | + - checkout |
| 66 | + # Create the .npmrc file so npm can auth for publishing |
| 67 | + - *npm-login |
| 68 | + - add_ssh_keys: |
| 69 | + fingerprints: |
| 70 | + # You need to add a deploy key with write permission in order for the CI to commit changes |
| 71 | + # back to the repo |
| 72 | + # https://circleci.com/docs/2.0/gh-bb-integration/#adding-readwrite-deployment-keys-to-github-or-bitbucket |
| 73 | + - "36:2c:16:f2:d0:59:13:25:f1:7f:44:87:a4:52:8f:03" |
| 74 | + # Download and cache dependencies so subsequent builds run faster |
| 75 | + - restore_cache: |
| 76 | + keys: |
| 77 | + - dependencies-{{ checksum "package-lock.json" }} |
| 78 | + # fallback to using the latest cache if no exact match is found |
| 79 | + - dependencies- |
| 80 | + - run: |
| 81 | + name: Install deps |
| 82 | + command: | |
| 83 | + npm i |
| 84 | + - save_cache: |
| 85 | + paths: |
| 86 | + - node_modules |
| 87 | + key: dependencies-{{ checksum "package-lock.json" }} |
| 88 | + - run: |
| 89 | + name: Build the libraries |
| 90 | + command: | |
| 91 | + npm run build |
| 92 | + - run: |
| 93 | + name: npm publish (master only) |
| 94 | + command: | |
| 95 | + .circleci/deploy.sh |
| 96 | +
|
| 97 | +workflows: |
| 98 | + version: 2 |
| 99 | + build: |
| 100 | + jobs: |
| 101 | + - test |
| 102 | + - publish: |
| 103 | + filters: |
| 104 | + branches: |
| 105 | + only: master |
| 106 | + requires: |
| 107 | + - test |
| 108 | + context: npm-build |
0 commit comments