From d6862e74189881592b22ddfb0a2239d541a3ed02 Mon Sep 17 00:00:00 2001 From: Erik Ziegler Date: Fri, 11 Oct 2019 17:40:21 +0200 Subject: [PATCH] ci: Set cache key to only use yarn.lock checksum (#1031) * ci: Set cache key to only use yarn.lock checksum * Use increasingly general pattern for restoring the cache * Avoid running script tag e2e tests twice * Performance improvements for CI * Valid YAML * Valid YAML? * Valid YAML!!!! * Update Node image, update yarn version * circle * serve --- .circleci/config.yml | 125 +++++++++++++++++++++++++++++++------------ package.json | 1 + 2 files changed, 91 insertions(+), 35 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dede133b1..0735ed6c7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,46 +17,43 @@ orbs: defaults: &defaults docker: - - image: circleci/node:10.16.0 + - image: circleci/node:12.9.1 environment: TERM: xterm # Enable colors in term working_directory: ~/repo jobs: - CHECKOUT: + UNIT_TESTS: <<: *defaults steps: + # Update yarn + - run: yarn -v + #- run: rm -rf ~/.yarn && npm i -g yarn && yarn -v + # Enable yarn workspaces - run: yarn config set workspaces-experimental true + # Checkout code and ALL Git Tags - checkout: post: - git fetch --all + - restore_cache: name: Restore Yarn and Cypress Package Cache keys: # when lock file changes, use increasingly general patterns to restore cache - - yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }} - - yarn-packages-v1-{{ .Branch }}- - - yarn-packages-v1- + - yarn-packages-{{ checksum "yarn.lock" }} + - yarn-packages- + - run: name: Install Dependencies command: yarn install --frozen-lockfile + - save_cache: name: Save Yarn Package Cache paths: - ~/.cache ## Cache yarn and Cypress - key: yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }} - # Persist :+1: - - persist_to_workspace: - root: ~/repo - paths: . - - UNIT_TESTS: - <<: *defaults - steps: - - attach_workspace: - at: ~/repo + key: yarn-packages-{{ checksum "yarn.lock" }} # RUN TESTS - run: @@ -91,8 +88,72 @@ jobs: file: '/home/circleci/repo/platform/core/coverage/reports' flags: 'core' + UNIT_TESTS_PERSIST_WORKSPACE: + <<: *defaults + steps: + # Update yarn + #- run: rm -rf ~/.yarn && npm i -g yarn && yarn -v + + # Enable yarn workspaces + - run: yarn config set workspaces-experimental true + + # Checkout code and ALL Git Tags + - checkout: + post: + - git fetch --all + + - restore_cache: + name: Restore Yarn and Cypress Package Cache + keys: + # when lock file changes, use increasingly general patterns to restore cache + - yarn-packages-{{ checksum "yarn.lock" }} + - yarn-packages- + + - run: + name: Install Dependencies + command: yarn install --frozen-lockfile + + - save_cache: + name: Save Yarn Package Cache + paths: + - ~/.cache ## Cache yarn and Cypress + key: yarn-packages-{{ checksum "yarn.lock" }} + + # RUN TESTS + - run: + name: 'JavaScript Test Suite' + command: yarn run test:unit:ci + + # PLATFORM/VIEWER + - run: + name: 'VIEWER: Combine report output' + command: | + viewerCov="/home/circleci/repo/platform/viewer/coverage" + touch "${viewerCov}/reports" + cat "${viewerCov}/clover.xml" >> "${viewerCov}/reports" + echo "\<<\<<\<< EOF" >> "${viewerCov}/reports" + cat "${viewerCov}/lcov.info" >>"${viewerCov}/reports" + echo "\<<\<<\<< EOF" >> "${viewerCov}/reports" + - codecov/upload: + file: '/home/circleci/repo/platform/viewer/coverage/reports' + flags: 'viewer' + + # PLATFORM/CORE + - run: + name: 'CORE: Combine report output' + command: | + coreCov="/home/circleci/repo/platform/core/coverage" + touch "${coreCov}/reports" + cat "${coreCov}/clover.xml" >> "${coreCov}/reports" + echo "\<<\<<\<< EOF" >> "${coreCov}/reports" + cat "${coreCov}/lcov.info" >> "${coreCov}/reports" + echo "\<<\<<\<< EOF" >> "${coreCov}/reports" + - codecov/upload: + file: '/home/circleci/repo/platform/core/coverage/reports' + flags: 'core' + # Persist :+1: - - persist_to_workspace: + - persist_to_workspace: &persist_to_workspace root: ~/repo paths: . @@ -217,16 +278,13 @@ workflows: # PULL REQUESTS PR_CHECKS: jobs: - - CHECKOUT: + - UNIT_TESTS: filters: branches: ignore: - master - feature/* - hotfix/* - - UNIT_TESTS: - requires: - - CHECKOUT # E2E: PWA - cypress/run: name: 'E2E: PWA' @@ -237,9 +295,9 @@ workflows: store_artifacts: false working_directory: platform/viewer build: yarn run build:e2e - start: yarn run test:e2e:dist + start: yarn run test:e2e:serve wait-on: 'http://localhost:3000' - cache-key: 'yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}' + cache-key: 'yarn-packages-{{ checksum "yarn.lock" }}' no-workspace: true # Don't persist workspace post-steps: - store_artifacts: @@ -256,9 +314,9 @@ workflows: store_artifacts: false working_directory: platform/viewer build: yarn run build:package - start: yarn run test:e2e:dist + start: yarn run test:e2e:serve wait-on: 'http://localhost:3000' - cache-key: 'yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}' + cache-key: 'yarn-packages-{{ checksum "yarn.lock" }}' no-workspace: true # Don't persist workspace post-steps: - store_artifacts: @@ -269,13 +327,10 @@ workflows: # MERGE TO MASTER RELEASE: jobs: - - CHECKOUT: + - UNIT_TESTS_PERSIST_WORKSPACE: filters: branches: only: master - - UNIT_TESTS: - requires: - - CHECKOUT # E2E: PWA + Persist - cypress/run: name: 'E2E: PWA' @@ -287,9 +342,9 @@ workflows: store_artifacts: true working_directory: platform/viewer build: yarn run build:e2e - start: yarn run test:e2e:dist + start: yarn run test:e2e:serve wait-on: 'http://localhost:3000' - cache-key: 'yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}' + cache-key: 'yarn-packages-{{ checksum "yarn.lock" }}' no-workspace: true # Don't persist workspace post-steps: - store_artifacts: @@ -297,7 +352,7 @@ workflows: - store_test_results: path: cypress/results requires: - - UNIT_TESTS + - UNIT_TESTS_PERSIST_WORKSPACE # E2E: script-tag - cypress/run: name: 'E2E: Script Tag' @@ -308,9 +363,9 @@ workflows: store_artifacts: false working_directory: platform/viewer build: yarn run build:package - start: yarn run test:e2e:dist + start: yarn run test:e2e:serve wait-on: 'http://localhost:3000' - cache-key: 'yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}' + cache-key: 'yarn-packages-{{ checksum "yarn.lock" }}' no-workspace: true # Don't persist workspace post-steps: - store_artifacts: @@ -318,7 +373,7 @@ workflows: - store_test_results: path: cypress/results requires: - - UNIT_TESTS + - UNIT_TESTS_PERSIST_WORKSPACE # Update NPM - NPM_PUBLISH: requires: diff --git a/package.json b/package.json index b47df9ba0..574b57606 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "test:unit:ci": "lerna run test:unit:ci --parallel --stream", "test:e2e": "lerna run test:e2e --stream", "test:e2e:dist": "lerna run test:e2e:dist --stream", + "test:e2e:serve": "lerna run test:e2e:serve --stream", "see-changed": "lerna changed", "docs:publish": "chmod +x ./build-and-publish-docs.sh && ./build-and-publish-docs.sh", "release": "yarn run lerna:version && yarn run lerna:publish",