<commit_before>aliases:
  - &opam_env
    TERM: dumb
    OPAMYES: true

  - &docker_opam
    docker:
      - image: ocaml/opam:debian-8_ocaml-4.05.0
        environment:
          <<: *opam_env
    working_directory: ~/flow

  - &docker_node
    docker:
      - image: circleci/node:8
    working_directory: ~/flow

  - &opam_deps
    name: Install deps from opam
    command: |
      eval $(opam config env)
      opam pin add -n flowtype-ci . | cat
      opam depext flowtype-ci | cat
      opam install --deps-only flowtype-ci | cat

  - &restore_opam_cache
    keys:
      - opam-cache-{{ arch }}-opam_1_2_2-ocaml_4_05_0-{{ checksum "opam" }}
      - opam-cache-{{ arch }}-opam_1_2_2-ocaml_4_05_0
      - opam-cache-{{ arch }}-opam_1_2_2

  - &save_opam_cache
    key: opam-cache-{{ arch }}-opam_1_2_2-ocaml_4_05_0-{{ checksum "opam" }}
    paths:
      - ~/.opam

  - &run_on_tags
    filters:
      tags:
        only: /.*/

version: 2
jobs:
  checkout:
    <<: *docker_node
    steps:
      - checkout
      - persist_to_workspace:
          root: .
          paths: .

  build_linux:
    <<: *docker_opam
    steps:
      - attach_workspace:
          at: ~/flow
      - run:
          # TODO: move this to a custom docker image
          name: Install deps
          command: sudo apt-get update && sudo apt-get install zip
      - restore_cache: *restore_opam_cache
      - run:
          name: Update opam repo
          command: |
            opam remote list -s | grep upstream >/dev/null || \
              opam remote add upstream https://opam.ocaml.org | cat
            opam update | cat
      - run: *opam_deps
      - save_cache: *save_opam_cache
      - run:
          name: Build flow
          command: opam config exec -- make
      - run:
          name: Build libflowparser
          command: opam config exec -- make -C src/parser dist/libflowparser.zip
      - run:
          name: Create artifacts
          command: |
            mkdir -p bin/linux && cp bin/flow bin/linux/flow
            opam config exec -- make dist/flow.zip
            cp dist/flow.zip dist/flow-linux64.zip
            cp src/parser/dist/libflowparser.zip dist/libflowparser-linux64.zip
      - persist_to_workspace:
          root: .
          paths:
            - bin/linux/flow
            - dist/flow-linux64.zip
            - dist/libflowparser-linux64.zip
      - store_artifacts:
          path: dist/flow-linux64.zip
          destination: flow-linux64.zip
      - store_artifacts:
          path: dist/libflowparser-linux64.zip
          destination: libflowparser-linux64.zip

  build_macos:
    macos:
      xcode: "9.0"
    environment:
      <<: *opam_env
    working_directory: ~/flow
    steps:
      - attach_workspace:
          at: ~/flow
      - restore_cache:
          keys:
            - brew-cache-{{ arch }}-v2
      - run:<commit_msg>[PR] Build flow.js and flow_parser.js in Circle<commit_after>aliases:
  - &opam_env
    TERM: dumb
    OPAMYES: true

  - &docker_opam
    docker:
      - image: ocaml/opam:debian-8_ocaml-4.05.0
        environment:
          <<: *opam_env
    working_directory: ~/flow

  - &docker_node
    docker:
      - image: circleci/node:8
    working_directory: ~/flow

  - &opam_deps
    name: Install deps from opam
    command: |
      eval $(opam config env)
      opam pin add -n flowtype-ci . | cat
      opam depext flowtype-ci | cat
      opam install --deps-only flowtype-ci | cat

  - &restore_opam_cache
    keys:
      - opam-cache-{{ arch }}-opam_1_2_2-ocaml_4_05_0-{{ checksum "opam" }}
      - opam-cache-{{ arch }}-opam_1_2_2-ocaml_4_05_0
      - opam-cache-{{ arch }}-opam_1_2_2

  - &save_opam_cache
    key: opam-cache-{{ arch }}-opam_1_2_2-ocaml_4_05_0-{{ checksum "opam" }}
    paths:
      - ~/.opam

  - &run_on_tags
    filters:
      tags:
        only: /.*/

version: 2
jobs:
  checkout:
    <<: *docker_node
    steps:
      - checkout
      - persist_to_workspace:
          root: .
          paths: .

  build_linux:
    <<: *docker_opam
    steps:
      - attach_workspace:
          at: ~/flow
      - run:
          # TODO: move this to a custom docker image
          name: Install deps
          command: sudo apt-get update && sudo apt-get install zip
      - restore_cache: *restore_opam_cache
      - run:
          name: Update opam repo
          command: |
            opam remote list -s | grep upstream >/dev/null || \
              opam remote add upstream https://opam.ocaml.org | cat
            opam update | cat
      - run: *opam_deps
      - run:
        name: Install extra deps from opam
        command: |
          opam install js_of_ocaml.3.1.0 | cat
      - save_cache: *save_opam_cache
      - run:
          name: Build flow
          command: opam config exec -- make
      - run:
          name: Build libflowparser
          command: opam config exec -- make -C src/parser dist/libflowparser.zip
      - run:
          name: Build flow.js
          command: opam config exec -- make js
      - run:
          name: Build flow_parser.js
          command: opam config exec -- make -C src/parser js
      - run:
          name: Create artifacts
          command: |
            mkdir -p bin/linux && cp bin/flow bin/linux/flow
            opam config exec -- make dist/flow.zip
            cp dist/flow.zip dist/flow-linux64.zip
            cp src/parser/dist/libflowparser.zip dist/libflowparser-linux64.zip
            cp src/parser/flow_parser.js dist/flow_parser.js
      - persist_to_workspace:
          root: .
          paths:
            - bin/linux/flow
            - bin/flow.js
            - dist/flow-linux64.zip
            - dist/libflowparser-linux64.zip
            - dist/flow_parser.js
      - store_artifacts:
          path: dist/flow-linux64.zip
          destination: flow-linux64.zip
      - store_artifacts:
          path: dist/libflowparser-linux64.zip
          destination: libflowparser-linux64.zip
      - store_artifacts:
          path: bin/flow.js
          destination: flow.js
      - store_artifacts:
          path: dist/flow_parser.js
          destination: flow_parser.js

  build_macos:
    macos:
      xcode: "9.0"
    environment:
      <<: *opam_env
    working_directory: ~/flow
    steps:
      - attach_workspace:
          at: ~/flow
      - restore_cache:
          keys:
            - brew-cache-{{ arch }}-v2
      - run:
{'fraction_non_alphanumeric': 0.1024275646045419, 'fraction_numerical': 0.016131558339859044, 'mean_word_length': 1.6193601312551271, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6232367', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2109, 'n_words': 480}