From fcef9fa75ea9a74ad33096cea55d1025a9f23577 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Thu, 1 Feb 2018 14:05:47 -0800 Subject: [PATCH] feat: add cache step to circleci --- templates/circle.yml.ejs | 65 ++++++++++++++++++++++++++++------- templates/scripts/greenkeeper | 17 +++++++++ templates/scripts/release | 2 -- templates/scripts/test.ejs | 45 ------------------------ 4 files changed, 69 insertions(+), 60 deletions(-) create mode 100755 templates/scripts/greenkeeper delete mode 100755 templates/scripts/test.ejs diff --git a/templates/circle.yml.ejs b/templates/circle.yml.ejs index adf4dbe0c..ef8920bf3 100644 --- a/templates/circle.yml.ejs +++ b/templates/circle.yml.ejs @@ -9,27 +9,62 @@ jobs: - checkout - restore_cache: &restore_cache keys: - - v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}-{{checksum "yarn.lock"}} - - v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}- - - v0-yarn-{{checksum ".circleci/config.yml"}}-master- - - run: .circleci/test + - v0-{{checksum ".circleci/config.yml"}}-{{ checksum "yarn.lock"}} + - v0-{{checksum ".circleci/config.yml"}} + - v0 + - run: .circleci/setup_git + - run: .circleci/greenkeeper + - run: yarn add -D nyc@11 @anycli/nyc-config@0 mocha-junit-reporter@1<%- semantic_release ? " @commitlint/cli@6 @commitlint/config-conventional@6" : "" %> + <%_ if (mocha) { _%> + - run: + name: yarn test + when: always + environment: {MOCHA_FILE: reports/mocha.xml} + command: | + mkdir -p reports + yarn exec nyc -- --nycrc-path node_modules/@anycli/nyc-config/.nycrc yarn test --reporter mocha-junit-reporter + - run: + name: submit code coverage + command: | + yarn exec nyc -- --nycrc-path node_modules/@anycli/nyc-config/.nycrc report --reporter text-lcov > coverage.lcov + curl -s https://codecov.io/bash | bash + <%_ } else { _%> + - run: yarn test + <%_ } _%> + <%_ if (['single', 'multi', 'plugin'].includes(type)) { _%> + - run: + when: always + command: ./bin/run -v + <%_ } _%> + <%_ if (['single', 'multi'].includes(type)) { _%> + - run: + when: always + command: ./bin/run --help + <%_ } _%> + <%_ if (semantic_release) { _%> + - run: + name: check if commits match conventional-changelog spec + when: always + command: yarn exec commitlint -- -x @commitlint/config-conventional --from origin/master + <%_ } _%> - store_test_results: &store_test_results path: ~/cli/reports - - save_cache: &save_cache - key: v0-yarn-{{checksum ".circleci/config.yml"}}-{{ .Branch }}-{{checksum "yarn.lock"}} - paths: - - ~/cli/node_modules - - /usr/local/share/.cache/yarn - - /usr/local/share/.config/yarn node-8: <<: *test docker: - image: node:8 + cache: + <<: *test steps: - checkout - - restore_cache: *restore_cache - - run: .circleci/test - - store_test_results: *store_test_results + - yarn global add greenkeeper-lockfile@1 + - yarn add -D nyc@11 @anycli/nyc-config@0 mocha-junit-reporter@1<%- semantic_release ? " @commitlint/cli@6 @commitlint/config-conventional@6" : "" %> + - save_cache: + key: v0-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}} + paths: + - ~/cli/node_modules + - /usr/local/share/.cache/yarn + - /usr/local/share/.config/yarn <%_ if (semantic_release) { _%> release: <<: *test @@ -37,6 +72,7 @@ jobs: - add_ssh_keys - checkout - restore_cache: *restore_cache + - run: .circleci/setup_git - run: .circleci/release <%_ } _%> @@ -46,6 +82,9 @@ workflows: jobs: - node-latest - node-8 + - cache: + filters: + branches: {only: master} <%_ if (semantic_release) { _%> - release: context: org-global diff --git a/templates/scripts/greenkeeper b/templates/scripts/greenkeeper new file mode 100755 index 000000000..68a1794b7 --- /dev/null +++ b/templates/scripts/greenkeeper @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -ex + +PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH + +if [[ "$CIRCLE_BRANCH" != greenkeeper/* ]]; then + exit 0 +fi + +if [[ ! -x "$(command -v greenkeeper-lockfile-update)" ]]; then + yarn global add greenkeeper-lockfile@1 +fi + +greenkeeper-lockfile-update +yarn install "$CLI_ENGINE_UTIL_YARN_ARGS" +greenkeeper-lockfile-upload diff --git a/templates/scripts/release b/templates/scripts/release index 1e441bd11..59c79759b 100755 --- a/templates/scripts/release +++ b/templates/scripts/release @@ -2,8 +2,6 @@ set -ex -.circleci/setup_git - PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH yarn global add @anycli/semantic-release@1 semantic-release@12 diff --git a/templates/scripts/test.ejs b/templates/scripts/test.ejs deleted file mode 100755 index 2555270a6..000000000 --- a/templates/scripts/test.ejs +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -.circleci/setup_git - -PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH - -CLI_ENGINE_UTIL_YARN_ARGS="--frozen-lockfile" - -if [[ "$CIRCLE_BRANCH" == greenkeeper/* ]]; then - CLI_ENGINE_GREENKEEPER_BRANCH=1 - CLI_ENGINE_UTIL_YARN_ARGS="" - if [[ ! -x "$(command -v greenkeeper-lockfile-update)" ]]; then - yarn global add greenkeeper-lockfile@1 - fi - greenkeeper-lockfile-update -fi - -yarn install $CLI_ENGINE_UTIL_YARN_ARGS - -if [[ "$CLI_ENGINE_GREENKEEPER_BRANCH" == 1 ]]; then - greenkeeper-lockfile-upload -fi - -yarn add -D nyc@11 @anycli/nyc-config@0 mocha-junit-reporter@1<%- semantic_release ? " @commitlint/cli@6 @commitlint/config-conventional@6" : "" %> - -<%_ if (type === 'single' || type === 'multi') { _%> -./bin/run -v -./bin/run --help -<%_ } else if (type === 'plugin') { _%> -./bin/run --help -<%_ } _%> - -mkdir -p reports -NYC=(yarn exec nyc -- --nycrc-path node_modules/@anycli/nyc-config/.nycrc) - -MOCHA_FILE=reports/mocha.xml "${NYC[@]}" yarn test --reporter mocha-junit-reporter - -"${NYC[@]}" report --reporter text-lcov > coverage.lcov -curl -s https://codecov.io/bash | bash -<%_ if (semantic_release) { _%> - -yarn exec commitlint -- -x @commitlint/config-conventional --from origin/master -<%_ } _%>