From 6d17f0c5493deb9c9847d39a2c81ab0a897e8c17 Mon Sep 17 00:00:00 2001 From: William Durand Date: Wed, 21 Apr 2021 21:46:29 +0200 Subject: [PATCH] Add Circle CI config (#1) --- .circleci/config.yml | 110 +++++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 + .npmignore | 3 ++ .npmrc | 2 + package.json | 3 +- 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 .circleci/config.yml create mode 100644 .npmignore create mode 100644 .npmrc diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..4c31182 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,110 @@ +# These environment variables must be set in CircleCI UI +# +# NPM_TOKEN - A valid NPM token for releases +version: 2.1 + +references: + defaults: &defaults + working_directory: ~/addons-moz-compare + docker: + # This is the NodeJS version we run in production. + - image: circleci/node:12 + + defaults-next: &defaults-next + working_directory: ~/addons-moz-compare + docker: + # This is the next NodeJS version we will support. + - image: circleci/node:14 + + restore_build_cache: &restore_build_cache + restore_cache: + name: restore yarn package cache + keys: + - yarn-packages-{{ checksum "yarn.lock" }} + + run_yarn_install: &run_yarn_install + run: + name: install dependencies + # See: https://github.com/mozilla/addons-frontend/issues/3034 + command: yarn install --pure-lockfile + + save_build_cache: &save_build_cache + save_cache: + name: save yarn package cache + key: yarn-packages-{{ checksum "yarn.lock" }} + paths: + - ~/.cache/yarn + + restore_next_build_cache: &restore_next_build_cache + restore_cache: + name: restore yarn package cache + keys: + - next-yarn-packages-{{ checksum "yarn.lock" }} + + save_next_build_cache: &save_next_build_cache + save_cache: + name: save yarn package cache + key: next-yarn-packages-{{ checksum "yarn.lock" }} + paths: + - ~/.cache/yarn + +jobs: + test: + <<: *defaults + steps: + - checkout + - *restore_build_cache + - *run_yarn_install + - *save_build_cache + - run: + name: unit tests + command: yarn test-ci + # Make sure we can build a production package. + - run: yarn pack + # Set up a workspace to share data between this job and the `release-tag` + # one when we want to publish a new npm version. + - persist_to_workspace: + root: ~/addons-moz-compare + paths: . + - store_artifacts: + path: coverage + + test-next: + <<: *defaults-next + steps: + - checkout + - *restore_next_build_cache + - *run_yarn_install + - *save_next_build_cache + - run: yarn test-ci + + release-tag: + <<: *defaults + steps: + - attach_workspace: + at: ~/addons-moz-compare + - run: + name: authenticate with registry + # We don't want to expand the token in this file, npm will do it. + command: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/addons-moz-compare/.npmrc + - run: + name: publish package + command: npm publish + +workflows: + version: 2 + default-workflow: + jobs: + - test: + filters: # required since `release-tag` has tag filters AND requires `test` + tags: + only: /.*/ + - test-next + - release-tag: + requires: + - test + filters: + tags: + only: /.*/ + branches: + ignore: /.*/ diff --git a/.gitignore b/.gitignore index c2658d7..0cf8be0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +coverage/ node_modules/ +*.tgz diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..e00efba --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +.* +coverage/ +tests/ diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..7729f3f --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +tag-version-prefix = "" +message = ":arrow_up: release %s" diff --git a/package.json b/package.json index 6ca897d..2fcad18 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "author": "Mozilla Add-ons Team", "license": "MPL-2.0", "scripts": { - "test": "jest" + "test": "jest", + "test-ci": "jest" }, "devDependencies": { "jest": "^26.6.3"