version: 2.1 ### ABOUT # # This configuration powers our Circleci.io integration # # Note: # Netlify works independently from this configuration to # create pull request previews and to update `https://docs.ohif.org` ### orbs: codecov: codecov/codecov@1.0.5 defaults: &defaults docker: - image: circleci/node:10.16.0 working_directory: ~/repo jobs: PR_UNIT_TESTS: <<: *defaults steps: # 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- - 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" }} # 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" MERGE_UNIT_TESTS: <<: *defaults steps: # 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- - 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" }} # 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: root: ~/repo paths: . e2e_test: working_directory: ~/repo docker: - image: cypress/base:8 environment: ## this enables colors in the output TERM: xterm steps: - attach_workspace: at: ~/repo - 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- # - run: $(yarn bin)/cypress run --record # Shouldn't be needed if we're using a package cache that contains Cypress # Could do a check here, if it doesn't exist, install cypress? - run: yarn install - run: yarn run test:e2e:ci npm_publish: <<: *defaults steps: - attach_workspace: at: ~/repo - run: name: Avoid hosts unknown for github command: mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config # --no-ci argument is not ideal; however, semantic-rlease thinks we're # attempting to run it from a `pr`, which is not the case - run: name: Publish using Semantic Release command: npx semantic-release --debug # Persist :+1: - persist_to_workspace: root: ~/repo paths: . docs_publish: <<: *defaults steps: - attach_workspace: at: ~/repo - run: name: Avoid hosts unknown for github command: mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config - run: git config --global user.email "gh-pages@localhost" - run: git config --global user.name "npm gh-pages" - run: yarn global add gh-pages - run: name: Generate Docs command: yarn run staticDeploy - run: name: Publish Docs command: yarn run docs:publish docker_publish: <<: *defaults steps: - attach_workspace: at: ~/repo - setup_remote_docker: docker_layer_caching: true - run: name: Build and push Docker image command: | # This file will exist if a new version was published by # our `semantic-release` command in the previous job if [[ ! -e tmp/updated-version.txt ]]; then exit 0 else # Remove npm config rm -f ./.npmrc # Set our version number using vars export IMAGE_VERSION=$(cat tmp/updated-version.txt) export IMAGE_VERSION_FULL=v$IMAGE_VERSION.${CIRCLE_BUILD_NUM} echo $IMAGE_VERSION echo $IMAGE_VERSION_FULL # Build our image, auth, and push docker build --tag ohif/$IMAGE_NAME:$IMAGE_VERSION_FULL --tag ohif/$IMAGE_NAME:latest . echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin docker push ohif/$IMAGE_NAME:$IMAGE_VERSION_FULL docker push ohif/$IMAGE_NAME:latest fi build_demo_site: <<: *defaults steps: # Download and cache dependencies - checkout - restore_cache: name: Restore Yarn 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- - run: name: Install Dependencies command: yarn install --frozen-lockfile - save_cache: name: Save Yarn Package Cache paths: - ~/.cache/yarn key: yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }} # Build & Test - run: name: "Build Demo Site, Upload SourceMaps, Send Deploy Notification" command: | yarn build:demo:ci perl -i -pe 's##`cat .circleci/rollbar.html` #e' build/index.html export FILE_1=$(find ./build/static/js -type f -name "2.*.js" -exec basename {} \;) export FILE_MAIN=$(find ./build/static/js -type f -name "main.*.js" -exec basename {} \;) export FILE_RUNTIME_MAIN=$(find ./build/static/js -type f -name "runtime~main.*.js" -exec basename {} \;) curl https://api.rollbar.com/api/1/sourcemap -F source_map=@build/static/js/$FILE_1.map -F access_token=$ROLLBAR_TOKEN -F version=$CIRCLE_SHA1 -F minified_url=https://$GOOGLE_STORAGE_BUCKET/static/js/$FILE_1 curl https://api.rollbar.com/api/1/sourcemap -F source_map=@build/static/js/$FILE_MAIN.map -F access_token=$ROLLBAR_TOKEN -F version=$CIRCLE_SHA1 -F minified_url=https://$GOOGLE_STORAGE_BUCKET/static/js/$FILE_MAIN curl https://api.rollbar.com/api/1/sourcemap -F source_map=@build/static/js/$FILE_RUNTIME_MAIN.map -F access_token=$ROLLBAR_TOKEN -F version=$CIRCLE_SHA1 -F minified_url=https://$GOOGLE_STORAGE_BUCKET/static/js/$FILE_RUNTIME_MAIN curl --request POST https://api.rollbar.com/api/1/deploy/ -F access_token=$ROLLBAR_TOKEN -F environment=$GOOGLE_STORAGE_BUCKET -F revision=$CIRCLE_SHA1 -F local_username=CircleCI # Persist :+1: - persist_to_workspace: root: ~/repo paths: . demo_site_publish: working_directory: ~/repo docker: - image: google/cloud-sdk steps: - attach_workspace: at: ~/repo - setup_remote_docker: docker_layer_caching: true - run: name: Deploy latest version to viewer.ohif.org command: | # This file will exist if a new version was published by # our `semantic-release` command in the previous job #if [[ ! -e tmp/updated-version.txt ]]; then # exit 0 #else echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=- gcloud --quiet config set project ${GOOGLE_PROJECT_ID} gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE} gsutil -m rm gs://$GOOGLE_STORAGE_BUCKET/** gsutil -m rsync -R build gs://$GOOGLE_STORAGE_BUCKET #fi workflows: version: 2 # PULL REQUESTS pull_requests: jobs: - PR_UNIT_TESTS: filters: branches: ignore: - master - feature/* - hotfix/* # MERGE TO MASTER cut_release: jobs: - MERGE_UNIT_TESTS: filters: branches: only: master - e2e_test: requires: - MERGE_UNIT_TESTS # Update NPM - npm_publish: requires: - e2e_test # Update docs.ohif.org - docs_publish: requires: - e2e_test # Update hub.docker.org - docker_publish: requires: - npm_publish # Update viewer.ohif.org - build_demo_site: requires: - e2e_test - demo_site_publish: requires: - build_demo_site