diff --git a/.github/workflows/matchers/check-toml.json b/.github/workflows/matchers/check-toml.json new file mode 100644 index 0000000..a1a9b0e --- /dev/null +++ b/.github/workflows/matchers/check-toml.json @@ -0,0 +1,16 @@ +{ + "problemMatcher": [ + { + "owner": "check-toml", + "pattern": [ + { + "regexp": "^(.+\\.toml):\\s(.+line\\s(\\d+)\\scolumn\\s(\\d+).+)$", + "file": 1, + "message": 2, + "line": 3, + "column": 4 + } + ] + } + ] +} diff --git a/.github/workflows/matchers/check-yaml.json b/.github/workflows/matchers/check-yaml.json new file mode 100644 index 0000000..ae5446a --- /dev/null +++ b/.github/workflows/matchers/check-yaml.json @@ -0,0 +1,19 @@ +{ + "problemMatcher": [ + { + "owner": "check-yaml", + "pattern": [ + { + "regexp": "^(.+)$", + "message": 1 + }, + { + "regexp": "^ in \"(.+\\.ya?ml)\", line (\\d+), column (\\d+)$", + "file": 1, + "line": 2, + "column": 3 + } + ] + } + ] +} diff --git a/.github/workflows/matchers/flake8.json b/.github/workflows/matchers/flake8.json new file mode 100644 index 0000000..4738c2e --- /dev/null +++ b/.github/workflows/matchers/flake8.json @@ -0,0 +1,32 @@ +{ + "__comment": "Credits to: https://github.com/home-assistant/core/blob/d32c364d7f9e138e0dd9363b34b3cb39f4afcd06/.github/workflows/matchers/flake8.json", + "problemMatcher": [ + { + "owner": "flake8-error", + "severity": "error", + "pattern": [ + { + "regexp": "^(.+):(\\d+):(\\d+):\\s(([EF]\\d{3})\\s.*)$", + "file": 1, + "line": 2, + "column": 3, + "message": 4, + "code": 5 + } + ] + }, + { + "owner": "flake8-warning", + "severity": "warning", + "pattern": [ + { + "regexp": "^(.+):(\\d+):(\\d+):\\s(([CDNW]\\d{3})\\s.*)$", + "file": 1, + "line": 2, + "column": 3, + "message": 4 + } + ] + } + ] +} diff --git a/.github/workflows/run_precommit.yaml b/.github/workflows/run_precommit.yaml new file mode 100644 index 0000000..1c6aefe --- /dev/null +++ b/.github/workflows/run_precommit.yaml @@ -0,0 +1,40 @@ +name: Run pre-commit + +on: [push, pull_request] + +jobs: + run_precommit: + name: Run pre-commit + runs-on: ubuntu-latest + + steps: + # Checkout repository + - uses: actions/checkout@v2 + + # Setup Python and install pre-commit + - uses: actions/setup-python@v2 + with: + python-version: "3.9" + - name: Install pre-commit + run: | + pip install -U pre-commit + + # Load cached pre-commit environment + - name: set PY + run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV + - uses: actions/cache@v2 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + + # Register problem matchers + - name: Register problem matchers + run: | + echo "::add-matcher::.github/workflows/matchers/check-toml.json" + echo "::add-matcher::.github/workflows/matchers/check-yaml.json" + echo "::add-matcher::.github/workflows/matchers/flake8.json" + + # Run pre-commit + - name: Run pre-commit + run: | + pre-commit run --show-diff-on-failure --color=never --all-files --verbose