Skip to content

Commit

Permalink
Add CI tests for template (#132)
Browse files Browse the repository at this point in the history
* Add CI tests for template

Generate the default project.
Check pre-commit is OK.
Check pytests suite is OK.

* Fix missing working-directory key

* Use instance creation script to have same code

* Fix generated folder name used in CI

* Remove Python 3.7 and Windows

Windows is failing for an not yet understand reason and Windows is not a really
a supported OS for Home Assistant development.
Python 3.7 is no more supported by the lib used for pytest suite.

* Update CONTRIBUTING documentation
  • Loading branch information
oncleben31 committed Jan 24, 2021
1 parent 31f4f54 commit 77f62ec
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
97 changes: 97 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Tests
on:
push:
branches:
- main
pull_request:

jobs:
tests:
strategy:
fail-fast: false
matrix:
include:
- { python-version: 3.9, os: ubuntu-latest }
# - { python-version: 3.9, os: windows-latest }
- { python-version: 3.9, os: macos-latest }
- { python-version: 3.8, os: ubuntu-latest }
# - { python-version: 3.7, os: ubuntu-latest }
name: Python ${{ matrix.python-version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2.3.4
with:
path: cookiecutter-homeassistant-custom-component
- uses: actions/setup-python@v2.2.0
with:
python-version: ${{ matrix.python-version }}
- name: Install tools using pip
working-directory: cookiecutter-homeassistant-custom-component
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install --constraint=.github/workflows/constraints.txt cookiecutter
- name: Generate project using Cookiecutter
run: cookiecutter-homeassistant-custom-component/scripts/gen_instance
- name: Create git repository
if: matrix.os != 'windows-latest'
run: |
git init
git config --local user.name "GitHub Action"
git config --local user.email "action@github.com"
git add .
git commit --message="Initial import"
working-directory: cookiecutter-homeassistant-custom-component-instance
- name: Create git repository (Windows)
if: matrix.os == 'windows-latest'
run: |
git init
git config --local user.name "GitHub Action"
git config --local user.email "action@github.com"
# https://github.com/cookiecutter/cookiecutter/issues/405
$ErrorActionPreference = "Continue"
git add .
$ErrorActionPreference = "Stop"
git add --renormalize .
git commit --message="Initial import"
working-directory: cookiecutter-homeassistant-custom-component-instance
- name: Compute cache key for pre-commit
if: matrix.os != 'windows-latest'
id: cache_key
shell: python
run: |
import hashlib
import sys
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest)
print("::set-output name=result::{}".format(result))
- uses: actions/cache@v2.1.3
if: matrix.os != 'windows-latest'
with:
path: ~/.cache/pre-commit
key: ${{ steps.cache_key.outputs.result }}-${{ hashFiles('cookiecutter-homeassistant-custom-component-instance/.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.cache_key.outputs.result }}-
- name: Install Python modules
run: |
pip install --constraint=.github/workflows/constraints.txt pre-commit black flake8 reorder-python-imports
pip install -r requirements_test.txt
working-directory: cookiecutter-homeassistant-custom-component-instance

- name: Run pre-commit on all files
run: |
pre-commit run --all-files --show-diff-on-failure --color=always
working-directory: cookiecutter-homeassistant-custom-component-instance

- name: Tests suite
run: |
pytest \
--timeout=9 \
--durations=10 \
-n auto \
-p no:sugar \
tests
working-directory: cookiecutter-homeassistant-custom-component-instance
5 changes: 4 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ from your development version:
How to test the project
-----------------------

You can manually test the generated integration with different tools implemented in Github workflows.
This template repository has a Continuous Integration workflow that generate a default project
from the cookiecutter template and run tests on it.

You can also manually test the generated integration with different tools implemented in Github workflows.

This template repository is linked to a generated `instance repository`_ for testing purpose.
You can generate this instance by using the following command:
Expand Down

0 comments on commit 77f62ec

Please sign in to comment.