From 4c13a88bc7a25f9c2ccc9ab09cfbabaff4e91560 Mon Sep 17 00:00:00 2001 From: Jason Ye <40873183+jye-sf@users.noreply.github.com> Date: Mon, 18 Apr 2022 00:31:06 -0700 Subject: [PATCH] chore: standardize release script (#270) * chore: standardize release script * chore: add explicit registry * chore: add circleci script for publishing to npm --- .circleci/config.yml | 94 ++++++++++++++++++++++++++++++++++++-------- package.json | 4 +- 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 09f53bc4..353b5b74 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,25 +1,85 @@ -version: 2 -jobs: - build: +version: 2.1 + +deploy_filters: &deploy_filters + filters: + branches: + ignore: /.*/ + tags: + # Trigger on tags that begin with `v` + only: /^v.*/ + + +executors: + node: docker: - - image: circleci/node:lts + - image: circleci/node:14 - steps: - - checkout +commands: + save_yarn_cache: + description: Save 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-dependencies-{{ checksum "yarn.lock" }} - - v1-dependencies- + - v1-yarn-deps-{{ checksum "yarn.lock" }} - - run: yarn install --frozen-lock +jobs: + build: + executor: node + steps: + - checkout + - restore_yarn_cache + - run: + name: Install dependencies and build + command: yarn install --frozen-lockfile + - save_yarn_cache + - run: + name: Check License Headers + command: yarn check-license-headers + - run: + name: Check formatting + command: yarn format:check + - run: + name: Run linter + command: yarn lint + - run: + name: Run unit tests + command: yarn test - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "yarn.lock" }} + deploy: + executor: 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 - - run: yarn check-license-headers - - run: yarn format:check - - run: yarn lint - - run: yarn test +workflows: + workflow: + jobs: + - build + build_and_test: + jobs: + - build + build_and_test_and_deploy: + jobs: + - build: + <<: *deploy_filters + - deploy: + <<: *deploy_filters + requires: + - build diff --git a/package.json b/package.json index 413a8c5f..508cc973 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "lint": "eslint src/ tests/", "format": "prettier --write '**/*.{js,json,md,html,css}'", "format:check": "prettier --check '**/*.{js,json,md,html,css}'", - "release": "npm publish --access public", + "release": "yarn release:publish", + "release:version": "npm version", + "release:publish": "npm publish --access public --registry=https://registry.npmjs.org", "test": "jest" }, "dependencies": {