version: 2

jobs:
    build:
        docker:
            - image: circleci/node:8
        working_directory: ~/protocol
        steps:
            - checkout
            - run:
                name: npm install
                command: npm install
            - save_cache:
                key: protocol-{{ .Environment.CIRCLE_SHA1 }}
                paths:
                    - ~/protocol
    lint:
        docker:
            - image: circleci/node:8
        working_directory: ~/protocol
        steps:
            - restore_cache:
                keys:
                    - protocol-{{ .Environment.CIRCLE_SHA1 }}
            - run: 
                name: Run linting
                command: npm run lint
    test-contracts:
        docker: 
            - image: circleci/node:8
        environment:
            SOLC_VERSION: '0.4.25'
        working_directory: ~/protocol
        steps:
            - restore_cache:
                keys:
                    - protocol-{{ .Environment.CIRCLE_SHA1 }}
            - setup_remote_docker:
                version: 17.09.0-ce
            - run:
                name: Install Dockerized solc
                command: docker pull ethereum/solc:$SOLC_VERSION
            - run:
                name: Compile contracts
                command: npm run compile
            - run: 
                name: Run unit tests with coverage reporting
                command: npm run test:coverage:coveralls
            - run:
                name: Run integration tests
                command: npm run test:integration

workflows:
    version: 2
    main:
        jobs:
            - build
            - lint:
                requires:
                    - build
            - test-contracts:
                requires:
                    - build
            
version: 2

jobs:
    build:
        docker:
            - image: circleci/node:8
        working_directory: ~/protocol
        steps:
            - checkout
            - run:
                name: npm install
                command: npm install
            - save_cache:
                key: protocol-{{ .Environment.CIRCLE_SHA1 }}
                paths:
                    - ~/protocol
    lint:
        docker:
            - image: circleci/node:8
        working_directory: ~/protocol
        steps:
            - restore_cache:
                keys:
                    - protocol-{{ .Environment.CIRCLE_SHA1 }}
            - run: 
                name: Run linting
                command: npm run lint
    test-contracts:
        docker: 
            - image: circleci/node:8
        environment:
            SOLC_VERSION: '0.4.25'
        working_directory: ~/protocol
        steps:
            - restore_cache:
                keys:
                    - protocol-{{ .Environment.CIRCLE_SHA1 }}
            - setup_remote_docker:
                version: 17.09.0-ce
            - run:
                name: Install Dockerized solc
                command: docker pull ethereum/solc:$SOLC_VERSION
            - run: 
                name: Run tests with coverage reporting
                command: npm run test:coverage:coveralls
                no_output_timeout: 20m

workflows:
    version: 2
    main:
        jobs:
            - build
            - lint:
                requires:
                    - build
            - test-contracts:
                requires:
                    - build
            
Extend CircleCI test-contracts no_output_timeout to 20m
Extend CircleCI test-contracts no_output_timeout to 20m
