From 2e8c69003315ce6d9c463be8150aead9c2b97a96 Mon Sep 17 00:00:00 2001
From: Jason Hu <awarecan@users.noreply.github.com>
Date: Thu, 28 Mar 2019 09:54:49 -0700
Subject: [PATCH] A very basic Circleci setup (#22503)

* Add circleci support

* Add buildpack-deps

* Install libudev-dev

* sudo

* always run test

* Add test report

* no sugar

* quite pytest

* better junit test result

* Add $CODE_COVERAGE env var
---
 .circleci/config.yml | 79 ++++++++++++++++++++++++++++++++++++++++++++
 .gitignore           |  1 +
 2 files changed, 80 insertions(+)
 create mode 100644 .circleci/config.yml

diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 00000000000..b6a57a28381
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,79 @@
+# Python CircleCI 2.0 configuration file
+#
+# Check https://circleci.com/docs/2.0/language-python/ for more details
+#
+version: 2.1
+jobs:
+  build:
+    docker:
+      # specify the version you desire here
+      # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
+      - image: circleci/python:3.7.2
+
+      # Specify service dependencies here if necessary
+      # CircleCI maintains a library of pre-built images
+      # documented at https://circleci.com/docs/2.0/circleci-images/
+      # - image: circleci/postgres:9.4
+      - image: circleci/buildpack-deps:stretch
+
+    working_directory: ~/repo
+
+    steps:
+      - checkout
+
+      - run:
+          name: setup docker prereqs
+          command: sudo apt-get update && sudo apt-get install -y --no-install-recommends libudev-dev
+
+      # Download and cache dependencies
+      - restore_cache:
+          keys:
+            - v1-dependencies-{{ checksum "requirements_all.txt" }}
+            # fallback to using the latest cache if no exact match is found
+            - v1-dependencies-
+
+      - run:
+          name: install dependencies
+          command: |
+            python3 -m venv venv
+            . venv/bin/activate
+            pip install --progress-bar off -r requirements_all.txt -r requirements_test.txt -c homeassistant/package_constraints.txt
+
+      - save_cache:
+          paths:
+            - ./venv
+          key: v1-dependencies-{{ checksum "requirements_all.txt" }}
+
+      - run:
+          name: install
+          command: |
+            . venv/bin/activate
+            pip install --progress-bar off -e .
+
+      - run:
+          name: run lint
+          command: |
+            . venv/bin/activate
+            python script/gen_requirements_all.py validate
+            flake8
+            pylint homeassistant
+
+      - run:
+          name: run tests
+          command: |
+            . venv/bin/activate
+            if [ -z "$CODE_COVERAGE" ]; then CC_SWITCH=""; else CC_SWITCH="--cov --cov-report html:htmlcov"; fi
+            pytest --timeout=9 --duration=10 --junitxml=test-reports/homeassistant/results.xml -qq -o junit_family=xunit2 -o junit_suite_name=homeassistant -o console_output_style=count -p no:sugar $CC_SWITCH
+            script/check_dirty
+          when: always
+
+      - store_test_results:
+          path: test-reports
+
+      - store_artifacts:
+          path: htmlcov
+          destination: cov-reports
+
+      - store_artifacts:
+          path: test-reports
+          destination: test-reports
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 91b8d024aed..b486032c741 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,7 @@ pip-log.txt
 .tox
 nosetests.xml
 htmlcov/
+test-reports/
 
 # Translations
 *.mo
-- 
GitLab