Skip to content

Commit

Permalink
Rework template CI (#76)
Browse files Browse the repository at this point in the history
* Activate dependabot

* Rework CI

* Code style

* Patch wrong code style generated

* Update documentation with pre-commit
  • Loading branch information
oncleben31 authored Nov 22, 2020
1 parent ae17360 commit 18cc719
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 86 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Features
- Development and testing in Visual Studio Code development container
- HACS_ ready
- Continuous integration with `GitHub Actions`_
- Settings for pre-commit

You can find a repository created with this cookiecutter template
in the `cookiecutter-homeassistant-custom-component-instance`_ example.
Expand Down
24 changes: 24 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python
import json
from pathlib import Path


def reindent_cookiecutter_json():
"""Indent .cookiecutter.json using two spaces.
The jsonify extension distributed with Cookiecutter uses an indentation
width of four spaces. This conflicts with the default indentation width of
Prettier for JSON files. Prettier is run as a pre-commit hook in CI.
"""
path = Path(".cookiecutter.json")

with path.open() as io:
data = json.load(io)

with path.open(mode="w") as io:
json.dump(data, io, sort_keys=True, indent=2)
io.write("\n")


if __name__ == "__main__":
reindent_cookiecutter_json()
10 changes: 10 additions & 0 deletions {{cookiecutter.project_name}}/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
- package-ecosystem: pip
directory: "/.github/workflows"
schedule:
interval: daily
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pip==20.2.4
pre-commit==2.9.0
black==20.8b1
flake8==3.8.4
reorder-python-imports==2.3.6
21 changes: 0 additions & 21 deletions {{cookiecutter.project_name}}/.github/workflows/cron.yaml

This file was deleted.

31 changes: 0 additions & 31 deletions {{cookiecutter.project_name}}/.github/workflows/pull.yml

This file was deleted.

34 changes: 0 additions & 34 deletions {{cookiecutter.project_name}}/.github/workflows/push.yml

This file was deleted.

61 changes: 61 additions & 0 deletions {{cookiecutter.project_name}}/.github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
on:
push:
branches:
- main
- master
- dev
pull_request:
schedule:
- cron: "0 0 * * *"

env:
DEFAULT_PYTHON: 3.9

jobs:
pre-commit:
runs-on: "ubuntu-latest"
name: Pre-commit
steps:
- name: Check out the repository
uses: actions/checkout@v2.3.4

- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@v2.1.4
with:
python-version: ${{ env.DEFAULT_PYTHON }}

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip --version
- name: Install Python modules
run: |
pip install --constraint=.github/workflows/constraints.txt pre-commit black flake8 reorder-python-imports
- name: Run pre-commit on all files
run: |
pre-commit run --all-files --show-diff-on-failure --color=always
hacs:
runs-on: "ubuntu-latest"
name: HACS
steps:
- name: Check out the repository
uses: "actions/checkout@v2.3.4"

- name: HACS validation
uses: "hacs/action@20.11.1"
with:
category: "integration"
ignore: brands

hassfest:
runs-on: "ubuntu-latest"
name: Hassfest
steps:
- name: Check out the repository
uses: "actions/checkout@v2.3.4"

- name: Hassfest validation
uses: "home-assistant/actions/hassfest@master"
2 changes: 2 additions & 0 deletions {{cookiecutter.project_name}}/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__pycache__
.python-version
.vscode/settings.json
2 changes: 2 additions & 0 deletions {{cookiecutter.project_name}}/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ activate the settings of the repository:
```console
$ pre-commit install
```

Now the pre-commit tests will be done every time you commit.

You can run the tests on all repository file with the command:

```console
$ pre-commit run --all-files
```

## License

By contributing, you agree that your contributions will be licensed under its MIT License.

0 comments on commit 18cc719

Please sign in to comment.