<commit_before>version: 2
jobs:
  build:
    macos:
      xcode: "11.2.1"
    shell: /bin/bash --login -eo pipefail
    steps:
      - checkout
      - run: git fetch --tags
      - restore_cache:
          key: v1-{{ checksum "setup" }}-{{ checksum "Gemfile.lock" }}-{{ .Environment.HOMEBREW_VERSION }}-{{ .Environment.UNITY_VERSION }}
      - run:
          name: Check Homebrew Version
          command: |
            echo "Checking for Homebrew version $HOMEBREW_VERSION"
            [ `brew --version | sed -n 1p | sed 's/[^0-9.]*\([0-9.]*\).*/\1/'` = $HOMEBREW_VERSION ] || brew update
      - run:
          name: Homebrew Depenendcies
          command: HOMEBREW_NO_AUTO_UPDATE=1 ./setup
      - run:
          name: Ruby Gems
          command: |
            gem update bundler
            bundle check || bundle install --path vendor/bundle
      - save_cache:
          paths:
            - /usr/local/Homebrew/
            - ~/Library/Caches/Homebrew
            - vendor/bundle
          key: v1-{{ checksum "setup" }}-{{ checksum "Gemfile.lock" }}-{{ .Environment.HOMEBREW_VERSION }}-{{ .Environment.UNITY_VERSION }}
      - run:
          name: Build Teak SDK
          command: |
            export UNITY_HOME=/Applications/Unity-$UNITY_VERSION/
            bundle exec rake
            mkdir -p build/$UNITY_VERSION
            mv Teak.unitypackage build/$UNITY_VERSION/Teak.unitypackage
      - run:
          command: |
            mkdir -p /tmp/unity_logs
            cp unity.log /tmp/unity_logs
            bundle exec rake unity:returnlicense
          when: on_fail
      - store_artifacts:
          path: /tmp/unity_logs
      - persist_to_workspace:
          root: .
          paths:
            - build/*
      - run:
          name: ReadTheDocs.org Unified Docs
          command: curl -X POST -d "branches=master" -d "token=$RTD_TOKEN" https://readthedocs.org/api/v2/webhook/teak/41148/
  deploy_versioned:
    docker:
      - image: circleci/ruby:latest
    steps:
      - checkout
      - run: git fetch --tags
      - restore_cache:
          key: v0-{{ checksum "Gemfile.lock" }}
      - run:
          name: Ruby Gems
          command: |
            gem update bundler
            bundle check || bundle install --path vendor/bundle
      - run:
          name: Install AWS CLI
          command: sudo apt-get -y -qq install awscli
      - save_cache:
          paths:
            - vendor/bundle
          key: v0-{{ checksum "Gemfile.lock" }}
      - attach_workspace:
          at: .
      - run:
          name: Upload SDK to S3
          command: |
            aws s3 cp build/$UNITY_VERSION/Teak.unitypackage s3://teak-build-artifacts/unity/Teak-$(git describe --tags --always).unitypackage --acl public-read
      # - run:
      #     name: Trigger Cleanroom Build
      #     command: bundle exec rake build:cleanroom
  deploy_latest:
    docker:
      - image: circleci/ruby:latest
    steps:
      - checkout
      - run: git fetch --tags
      - restore_cache:
          key: v0-{{ checksum "Gemfile.lock" }}
      - run:
          name: Ruby Gems
          command: bundle check || bundle install --path vendor/bundle
      - run:
          name: Install AWS CLI
          command: sudo apt-get -y -qq install awscli
      - save_cache:
          paths:
            - vendor/bundle
          key: v0-{{ checksum "Gemfile.lock" }}
      - attach_workspace:
          at: .
      - run:
          name: Upload SDK to S3
          command: |
            aws s3 cp build/$UNITY_VERSION/Teak.unitypackage s3://teak-build-artifacts/unity/Teak.unitypackage --acl public-read
workflows:
  version: 2
  un-tagged-build:
    jobs:
      - build:
          filters:
            tags:
              ignore: /.*/
  tagged-build:<commit_msg>tag promote<commit_after>version: 2.1

orbs:
  teak: teak/sdk-utils@0.0.3

jobs:
  build:
    macos:
      xcode: "11.2.1"
    shell: /bin/bash --login -eo pipefail
    steps:
      - checkout
      - run: git fetch --tags
      - restore_cache:
          key: v1-{{ checksum "setup" }}-{{ checksum "Gemfile.lock" }}-{{ .Environment.HOMEBREW_VERSION }}-{{ .Environment.UNITY_VERSION }}
      - run:
          name: Check Homebrew Version
          command: |
            echo "Checking for Homebrew version $HOMEBREW_VERSION"
            [ `brew --version | sed -n 1p | sed 's/[^0-9.]*\([0-9.]*\).*/\1/'` = $HOMEBREW_VERSION ] || brew update
      - run:
          name: Homebrew Depenendcies
          command: HOMEBREW_NO_AUTO_UPDATE=1 ./setup
      - run:
          name: Ruby Gems
          command: |
            gem update bundler
            bundle check || bundle install --path vendor/bundle
      - save_cache:
          paths:
            - /usr/local/Homebrew/
            - ~/Library/Caches/Homebrew
            - vendor/bundle
          key: v1-{{ checksum "setup" }}-{{ checksum "Gemfile.lock" }}-{{ .Environment.HOMEBREW_VERSION }}-{{ .Environment.UNITY_VERSION }}
      - run:
          name: Build Teak SDK
          command: |
            export UNITY_HOME=/Applications/Unity-$UNITY_VERSION/
            bundle exec rake
            mkdir -p build/$UNITY_VERSION
            mv Teak.unitypackage build/$UNITY_VERSION/Teak.unitypackage
      - run:
          command: |
            mkdir -p /tmp/unity_logs
            cp unity.log /tmp/unity_logs
            bundle exec rake unity:returnlicense
          when: on_fail
      - store_artifacts:
          path: /tmp/unity_logs
      - persist_to_workspace:
          root: .
          paths:
            - build/*
      - run:
          name: ReadTheDocs.org Unified Docs
          command: curl -X POST -d "branches=master" -d "token=$RTD_TOKEN" https://readthedocs.org/api/v2/webhook/teak/41148/

  tag_build:
    docker:
      - image: circleci/ruby:latest
    steps:
      - checkout
      - teak/tag-promote:
          fingerprint: "dc:b5:97:f2:a5:40:5e:ba:03:dd:83:fb:78:88:5e:bd"

  deploy_versioned:
    docker:
      - image: circleci/ruby:latest
    steps:
      - checkout
      - run: git fetch --tags
      - restore_cache:
          key: v0-{{ checksum "Gemfile.lock" }}
      - run:
          name: Ruby Gems
          command: |
            gem update bundler
            bundle check || bundle install --path vendor/bundle
      - run:
          name: Install AWS CLI
          command: sudo apt-get -y -qq install awscli
      - save_cache:
          paths:
            - vendor/bundle
          key: v0-{{ checksum "Gemfile.lock" }}
      - attach_workspace:
          at: .
      - run:
          name: Upload SDK to S3
          command: |
            aws s3 cp build/$UNITY_VERSION/Teak.unitypackage s3://teak-build-artifacts/unity/Teak-$(git describe --tags --always).unitypackage --acl public-read
      # - run:
      #     name: Trigger Cleanroom Build
      #     command: bundle exec rake build:cleanroom

  deploy_latest:
    docker:
      - image: circleci/ruby:latest
    steps:
      - checkout
      - run: git fetch --tags
      - restore_cache:
          key: v0-{{ checksum "Gemfile.lock" }}
      - run:
          name: Ruby Gems
          command: bundle check || bundle install --path vendor/bundle
      - run:
          name: Install AWS CLI
          command: sudo apt-get -y -qq install awscli
      - save_cache:
          paths:
            - vendor/bundle
          key: v0-{{ checksum "Gemfile.lock" }}
      - attach_workspace:
          at: .
      - run:
          name: Upload SDK to S3
          command: |
            aws s3 cp build/$UNITY_VERSION/Teak.unitypackage s3://teak-build-artifacts/unity/Teak.unitypackage --acl public-read
workflows:
  version: 2
  un-tagged-build:
    jobs:
      - build:
          filters:
            tags:
              ignore: /.*/
      - tag_build:
          requires:
            - build
          filters:
            tags:
              ignore: /.*/

  tagged-build:
{'fraction_non_alphanumeric': 0.11219327093346826, 'fraction_numerical': 0.010498355679230964, 'mean_word_length': 1.5457179652285897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '192336', 'n_tokens_mistral': 2511, 'n_tokens_neox': 2419, 'n_words': 584}