From e44e8375e874b582beaaf3c40eeeda71b9d0e7e4 Mon Sep 17 00:00:00 2001 From: Jacques Dafflon Date: Thu, 9 May 2019 04:48:16 +0200 Subject: [PATCH] Fix CI --- .circleci/config.yml | 185 ++++++++++++++++++++++---------------- .circleci/deploy-check.sh | 35 ++++++++ package.json | 2 +- 3 files changed, 144 insertions(+), 78 deletions(-) create mode 100755 .circleci/deploy-check.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f40655..b1a1b8d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,92 +1,125 @@ -aliases: - - &update-npm - name: Update npm to the latest version - command: sudo npm install -g npm@latest +version: 2.1 - - &save-dependencies-cache - key: v1-dependency-cache-{{ checksum "package.json" }} - paths: - - ./node_modules +executors: + node: + docker: + - image: circleci/node:11.10.0 + working_directory: ~/ERC777 - - &restore-dependencies-cache - keys: - - v1-dependency-cache-{{ checksum "package.json" }} - - v1-dependency-cache- - - - &save-build-cache - key: v1-build-cache-{{ .BuildNum }} - paths: - - ./artifacts - - - &restore-build-cache - keys: - - v1-build-cache-{{ .BuildNum }} - - v1-build-cache- - - &filter-all-tags - tags: - only: /.*/ +commands: + restore-dependencies: + steps: + - restore_cache: + keys: + - v1-dependency-cache-{{ checksum "package.json" }} + - v1-dependency-cache- -defaults: &defaults - docker: - - image: circleci/node:10.6.0 - working_directory: ~/erc777 + restore-build: + steps: + - restore_cache: + keys: + - v1-build-cache-{{ .BuildNum }} + - v1-build-cache- -version: 2 + restore-solc: + steps: + - run: + name: Set write permissions + command: sudo chmod go+w /opt + - restore_cache: + keys: + - v1-solc-cache-{{ .BuildNum }} + - v1-solc-cache- + - run: + name: Update $PATH + command: echo 'export PATH="/opt:$PATH"' >> $BASH_ENV jobs: - install-dependencies: - <<: *defaults + install solc: + executor: node + steps: + - run: + name: Download solc + command: curl -L "https://github.com/ethereum/solidity/releases/download/v0.5.3/solc-static-linux" -o /tmp/solc + - run: + name: Verify solc download + command: echo "be08eb95cb3a1da52e918cf51a0c0397fbe7f0693145eb31835bf2924209f1e0 /tmp/solc" | sha256sum -c - + - run: + name: Make solc executable + command: chmod +x /tmp/solc + - run: + name: Install solc + command: sudo mv /tmp/solc /opt/solc + - save_cache: + key: v1-solc-cache-{{ .BuildNum }} + paths: + - /opt/solc + - run: + name: Solc version + command: /opt/solc --version + + install dependencies: + executor: node steps: - - run: *update-npm - checkout - run: name: Install npm dependencies with npm ci command: npm ci - - save_cache: *save-dependencies-cache + - save_cache: + key: v1-dependency-cache-{{ checksum "package.json" }} + paths: + - ./node_modules + build: - <<: *defaults + executor: node steps: - - run: *update-npm - checkout - - restore_cache: *restore-dependencies-cache + - restore-solc + - restore-dependencies - run: name: Build Solidity command: npm run build - - save_cache: *save-build-cache - lint-solidity: - <<: *defaults + - save_cache: + key: v1-build-cache-{{ .BuildNum }} + paths: + - ./artifacts + + lint solidity: + executor: node steps: - checkout - - restore_cache: *restore-dependencies-cache + - restore-dependencies - run: name: Lint Solidity command: npm run lint:sol - lint-javascript: - <<: *defaults + + lint javascript: + executor: node steps: - - run: *update-npm - checkout - - restore_cache: *restore-dependencies-cache + - restore-dependencies - run: - name: Lint Javascript + name: Lint JavaScript command: npm run lint:js + test: - <<: *defaults + executor: node steps: - - run: *update-npm - checkout - - restore_cache: *restore-dependencies-cache - - restore_cache: *restore-build-cache + - restore-dependencies + - restore-build + - restore-solc - run: name: Test command: npm run test + coverage: - <<: *defaults + executor: node steps: - - run: *update-npm - checkout - - restore_cache: *restore-dependencies-cache - - restore_cache: *restore-build-cache + - restore-dependencies + - restore-build + - restore-solc - run: name: Tests with coverage command: npm run coverage @@ -99,13 +132,17 @@ jobs: - run: name: Enforce minimum coverage threshold command: npx istanbul check-coverage --statements 95 --functions 95 --branches 95 --lines 95 + publish: - <<: *defaults + executor: node steps: - - run: *update-npm - checkout - - restore_cache: *restore-dependencies-cache - - restore_cache: *restore-build-cache + - run: + name: Verify branch & version tag + command: .circleci/deploy-check.sh + - restore-dependencies + - restore-build + - restore-solc - run: name: Set npm auth token command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc @@ -117,37 +154,31 @@ workflows: version: 2 ci_cd: jobs: - - install-dependencies: - filters: *filter-all-tags + - install solc + - install dependencies - build: requires: - - install-dependencies - filters: *filter-all-tags - - lint-solidity: + - install solc + - install dependencies + - lint solidity: requires: - - install-dependencies - filters: *filter-all-tags - - lint-javascript: + - install dependencies + - lint javascript: requires: - - install-dependencies - filters: *filter-all-tags + - install dependencies - test: requires: + - lint solidity + - lint javascript - build - filters: *filter-all-tags - coverage: requires: + - lint solidity + - lint javascript - build - filters: *filter-all-tags - publish: requires: - - build - test - - coverage - - lint-solidity - - lint-javascript filters: - tags: - only: /v[0-9]+(\.[0-9]+)*/ branches: - ignore: /.*/ + only: master diff --git a/.circleci/deploy-check.sh b/.circleci/deploy-check.sh new file mode 100755 index 0000000..8e13b74 --- /dev/null +++ b/.circleci/deploy-check.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Simple script to make sure the current build is on the production branch and +# has the correct version tag. +# This script is used as a check to prevent from deploying a wrong version to +# the docs. + +DIR=$(dirname "$(realpath $0)") + +say() { + printf "[%s] %s\n" "$0" "$*" >&2 +} + +die() { + say "$*" + exit 100 +} + +check_branch() { + if [[ "$CIRCLE_BRANCH" != "master" ]]; then + die "Error: Invalid branch name '$CIRCLE_BRANCH', expected master" + fi +} + +check_tag() { + NPM_VERSION=$(node -p "require('${DIR}/../package.json').version") + DISTANCE=$(git rev-list --count "v$NPM_VERSION..HEAD") + if [[ "$DISTANCE" != "0" ]]; then + die "Error: Production branch must point to the current version tag ($DISTANCE commits ahead)" + fi +} + +check_branch +check_tag + diff --git a/package.json b/package.json index ffeb3ce..1138ead 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "build": "npm run clean && npm run build:sol", "test": "mocha", "test-old": "scripts/test.sh --network 'test-old'", - "coverage": "SOLIDITY_COVERAGE=true scripts/test.sh", + "coverage": "echo 'Coverage not supported with Solidity v0.5' && exit 1", "check": "npm run lint && npm run build && npm run test", "clean": "rm -rf ./build ./coverage ./coverage.json" },