Continuous Integration with Circle CI v2 with Node.js and PHP examples

Second version of Circle CI configuration changed significantly.

It introduced workflows, and they are used in pipes meaning.

Every workflow can include multiple steps.

Node.js example:

# .circleci/config.yml
version: 2
jobs:
  build:
    working_directory: ~/attraction-wars-server
    docker:
      - image: circleci/node:10.0.0
    steps:
      - checkout
      - run:
          name: install-npm
          command: 'sudo npm install -g npm@latest'
      - restore_cache: # special step to restore the dependency cache
          key: dependency-cache-{{ checksum "package.json" }}
      - run:
          name: install-dependencies
          command: npm install
      - save_cache: # special step to save the dependency cache
          key: dependency-cache-{{ checksum "package.json" }}
          paths:
            - ./node_modules
      - run:
          name: lint
          command: npm run lint

Cache is used to increase speed of future runs.

Working command described in package.json (eslint/tslint, or any other)

Example of run for php:

version: 2

jobs:
  build:
    docker:
      - image: circleci/php:7.2-cli-node-browsers
    steps:
      - checkout
      - restore_cache:
          keys:
          - composer-{{ checksum "composer.lock" }}
      - run:
          name: install
          command: composer install
      - save_cache:
          key: composer-{{ checksum "composer.lock" }}
          paths:
            - ./vendor
      - run:
          name: lint
          command: ./vendor/bin/php-cs-fixer --diff --dry-run --verbose fix ./src

Vendor sources are also cached there.

Resources

  1. https://circleci.com/docs/2.0/
  2. https://circleci.com/docs/2.0/language-javascript/
  3. https://circleci.com/docs/2.0/language-php/
  4. https://github.com/harentius/attraction-wars-server/blob/master/.circleci/config.yml