diff --git a/.circleci/config.yml b/.circleci/config.yml index 910fdfa..bf08dd6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,4 @@ -version: 2 +version: 2.1 defaults: workspace_root: &workspace_root @@ -7,19 +7,54 @@ defaults: nodejs_container: &nodejs_container working_directory: *workspace_root docker: - - image: circleci/node:12-stretch - + - image: cimg/node:lts attach_workspace: &attach_workspace attach_workspace: at: *workspace_root - restore_node_modules: &restore_node_modules - restore_cache: - name: Restore node_modules cache - keys: - - v2-amazon-ids-node-{{ .Branch }}-{{ checksum "yarn.lock" }} - - v2-amazon-ids-node-master-{{ checksum "yarn.lock" }} - - v2-amazon-ids-node-master- +commands: + restore-nodejs: + description: "Restore Node.js dependencies" + parameters: + key: + type: string + working_directory: + type: string + default: *workspace_root + default_branch: + type: string + default: master + steps: + - restore_cache: + name: Restore node_modules cache + keys: + - << parameters.key >>-nodejs-{{ .Branch }}-{{ checksum "<< parameters.working_directory >>/yarn.lock" }} + - << parameters.key >>-nodejs-<< parameters.default_branch >>-{{ checksum "<< parameters.working_directory >>/yarn.lock" }} + - << parameters.key >>-nodejs-<< parameters.default_branch >>- + + install-nodejs: + description: "Install Node.js dependencies" + parameters: + key: + type: string + working_directory: + type: string + default: *workspace_root + steps: + - restore-nodejs: + key: << parameters.key >> + working_directory: << parameters.working_directory >> + + - run: + name: Install dependencies + command: yarn --frozen-lockfile --non-interactive + working_directory: << parameters.working_directory >> + + - save_cache: + name: Save node_modules cache + key: << parameters.key >>-nodejs-{{ .Branch }}-{{ checksum "<< parameters.working_directory >>/yarn.lock" }} + paths: + - << parameters.working_directory >>/node_modules jobs: checkout: @@ -36,28 +71,34 @@ jobs: <<: *nodejs_container steps: - *attach_workspace - - *restore_node_modules - - - run: - name: Install dependencies - command: yarn --frozen-lockfile - - save_cache: - name: Save node_modules cache - key: v2-amazon-ids-node-{{ .Branch }}-{{ checksum "yarn.lock" }} - paths: - - node_modules/ + - install-nodejs: + key: v1-amazon-ids lint: <<: *nodejs_container steps: - *attach_workspace - - *restore_node_modules + + - restore-nodejs: + key: v1-amazon-ids - run: name: Lint JavaScript command: yarn xo + test: + <<: *nodejs_container + steps: + - *attach_workspace + + - restore-nodejs: + key: v1-amazon-ids + + - run: + name: Test + command: yarn test --ci + workflows: version: 2 @@ -72,3 +113,7 @@ workflows: - lint: requires: - install + + - test: + requires: + - install