diff --git a/.circleci/config.yml b/.circleci/config.yml index 489bf13..47fc5ba 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,6 +2,31 @@ version: 2.1 supported-eslint-versions: &supported-eslint-versions ["local", "7"] +deploy_filters: &deploy_filters + filters: + branches: + ignore: /.*/ + tags: + # Trigger on tags that begin with `v` + only: /^v.*/ + +commands: + save_yarn_cache: + description: Save Yarn cache for future build + steps: + - save_cache: + key: v1-yarn-deps-{{ checksum "yarn.lock" }} + paths: + - ~/.cache/yarn + + restore_yarn_cache: + description: Restore cache from previous build + steps: + - restore_cache: + keys: + - v1-yarn-deps-{{ checksum "yarn.lock" }} + + jobs: build: parameters: @@ -15,18 +40,12 @@ jobs: - image: circleci/node steps: - checkout + - restore_yarn_cache + - run: + name: Install dependencies and build + command: yarn install --frozen-lockfile - - restore_cache: - keys: - - v1-dependencies-{{ checksum "yarn.lock" }} - - v1-dependencies- - - - run: yarn install --frozen-lock - - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "yarn.lock" }} + - save_yarn_cache - when: condition: not: @@ -35,9 +54,32 @@ jobs: - run: name: Override version of eslint@<> command: yarn add eslint@<> --dev - - run: yarn format:check - - run: yarn lint - - run: yarn test + - run: + name: Check formatting + command: yarn format:check + - run: + name: Run linter + command: yarn lint + - run: + name: Run unit tests + command: yarn test + + deploy: + docker: + - image: circleci/node + steps: + - checkout + - restore_yarn_cache + - run: + name: Install dependencies and build + command: yarn install --frozen-lockfile + - run: + name: Configure NPM authentication + command: npm config set "//registry.npmjs.org/:_authToken" "$NPM_AUTOMATION_TOKEN" + - run: + name: Publish package + command: yarn release:publish + workflows: build_and_test: @@ -46,3 +88,15 @@ workflows: matrix: parameters: eslint-version: *supported-eslint-versions + build_and_test_and_deploy: + jobs: + - build: + <<: *deploy_filters + matrix: + parameters: + eslint-version: *supported-eslint-versions + + - deploy: + <<: *deploy_filters + requires: + - build diff --git a/package.json b/package.json index e8c32ae..1ecbec8 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "format": "prettier --write --ignore-path .gitignore \"**/*.{js,md}\"", "format:check": "prettier --check --ignore-path .gitignore \"**/*.{js,md}\"", "lint": "eslint lib/ test/", - "test": "nyc mocha" + "test": "nyc mocha", + "release:version": "npm version", + "release:publish": "npm publish --registry=https://registry.npmjs.org" }, "devDependencies": { "@babel/core": "^7.17.8",