Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjac committed May 9, 2019
1 parent 540cfa2 commit 30ebba7
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 78 deletions.
185 changes: 108 additions & 77 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
35 changes: 35 additions & 0 deletions .circleci/deploy-check.sh
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 30ebba7

Please sign in to comment.