<commit_before>version: 2
jobs:

  frontend-build:
    working_directory: ~/pixel
    docker:
      - image: circleci/node:8
        environment:
          CI_BUILD_FRONTEND: 1
    steps:
      - checkout
      - restore_cache:
          keys:
            - frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
      - run:
          name: Install dependencies & build styles
          command: make bootstrap
      - save_cache:
          paths:
            - ~/pixel/static
            - ~/pixel/node_modules
          key: frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}

  backend-build:
    machine: true
    working_directory: ~/pixel
    steps:
      - checkout
      - restore_cache:
          keys:
            - frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
      - restore_cache:
          keys:
            - docker-v1-{{ .Branch }}
      - run:
          name: Load cached container
          command: |
            if [[ -e ~/docker/pixel.tgz ]]
            then
              gunzip -c ~/docker/pixel.tgz | docker load
            fi
      - run:
          name: Build container
          command: docker build --pull --no-cache -t pixel .
      - run:
          name: Save container
          command: |
            mkdir -p ~/docker
            docker save pixel | gzip > ~/docker/pixel.tgz
      - save_cache:
          paths:
            - ~/docker
          key: docker-v1-{{ .Branch }}

  backend-test:
    machine: true
    working_directory: ~/pixel
    steps:
      - checkout
      - restore_cache:
          keys:
            - frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
      - run:
          name: Lint the code
          command: make lint
      - run:
          name: Test the code & report coverage
          command: |
            set -x
            make test-ci

  hub:
    machine: true
    steps:
      - restore_cache:
          keys:
            - docker-v1-{{ .Branch }}
      - run:
          name: Load cached container
          command: gunzip -c ~/docker/pixel.tgz | docker load
      - run:
          name: Login to DockerHub
          command: docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
      - run:
          name: Get Docker tag
          command: echo 'export DOCKER_TAG=$(if [[ -z "$CIRCLE_TAG" ]]; then echo "latest"; else echo "$CIRCLE_TAG"; fi)' >> "$BASH_ENV"
      - run:
          name: Tag container
          command: |
            echo "Docker tag: $DOCKER_TAG"
            docker tag pixel "candihub/pixel:$DOCKER_TAG"
      - run:
          name: Publish tagged container
          command: docker push "candihub/pixel:$DOCKER_TAG"


workflows:
  version: 2

  pixel:<commit_msg>Fix circle cache id for docker<commit_after>version: 2
jobs:

  frontend-build:
    working_directory: ~/pixel
    docker:
      - image: circleci/node:8
        environment:
          CI_BUILD_FRONTEND: 1
    steps:
      - checkout
      - restore_cache:
          keys:
            - frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
      - run:
          name: Install dependencies & build styles
          command: make bootstrap
      - save_cache:
          paths:
            - ~/pixel/static
            - ~/pixel/node_modules
          key: frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}

  backend-build:
    machine: true
    working_directory: ~/pixel
    steps:
      - checkout
      - restore_cache:
          keys:
            - frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
      - restore_cache:
          keys:
            - docker-v2-{{ .Revision }}
      - run:
          name: Load cached container
          command: |
            if [[ -e ~/docker/pixel.tgz ]]
            then
              gunzip -c ~/docker/pixel.tgz | docker load
            fi
      - run:
          name: Build container
          command: docker build --pull --no-cache -t pixel .
      - run:
          name: Save container
          command: |
            mkdir -p ~/docker
            docker save pixel | gzip > ~/docker/pixel.tgz
      - save_cache:
          paths:
            - ~/docker
          key: docker-v2-{{ .Revision }}

  backend-test:
    machine: true
    working_directory: ~/pixel
    steps:
      - checkout
      - restore_cache:
          keys:
            - frontend-deps-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
      - run:
          name: Lint the code
          command: make lint
      - run:
          name: Test the code & report coverage
          command: |
            set -x
            make test-ci

  hub:
    machine: true
    steps:
      - restore_cache:
          keys:
            - docker-v2-{{ .Revision }}
      - run:
          name: Load cached container
          command: gunzip -c ~/docker/pixel.tgz | docker load
      - run:
          name: Login to DockerHub
          command: docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
      - run:
          name: Get Docker tag
          command: echo 'export DOCKER_TAG=$(if [[ -z "$CIRCLE_TAG" ]]; then echo "latest"; else echo "$CIRCLE_TAG"; fi)' >> "$BASH_ENV"
      - run:
          name: Tag container
          command: |
            echo "Docker tag: $DOCKER_TAG"
            docker tag pixel "candihub/pixel:$DOCKER_TAG"
      - run:
          name: Publish tagged container
          command: docker push "candihub/pixel:$DOCKER_TAG"


workflows:
  version: 2

  pixel:
{'fraction_non_alphanumeric': 0.1122846025569761, 'fraction_numerical': 0.0040763387066889015, 'mean_word_length': 1.418458781362007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1028514', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1620, 'n_words': 424}