name: "main"

on: ["workflow_dispatch", "push"]

jobs:
  changes:
    runs-on: "{{ actions_runner }}"
    steps:
      - uses: "actions/checkout@v3"
      - uses: "dorny/paths-filter@v2"
        id: "filter"
        with:
          filters: |
            template:
              - "template/**"
    outputs:
      template: "{% raw %}${{ steps.filter.outputs.template }}{% endraw %}"
  bump_template:
    needs: "changes"
    if: "{% raw %}${{ needs.changes.outputs.template == 'true' }}{% endraw %}"
    runs-on: "{{ actions_runner }}"
    steps:
      - uses: "actions/checkout@v3"
      - uses: "actions/setup-python@v4"
        with:
          python-version: "{{ python_version }}"
      - run: |-
          python -m pip install -U pip
          pip install -U setuptools wheel
          pip install copier
          copier -f -r $(git rev-parse HEAD:template)
      - uses: "stefanzweifel/git-auto-commit-action@v4"
        with:
          commit_message: "Update repo to latest template"
  isort:
    needs: "bump_template"
    if: "{% raw %}${{ !failure() }}{% endraw %}"
    runs-on: "{{ actions_runner }}"
    steps:
      - uses: "blakeNaccarato/copier-python-workflow-setup@v0.0.11"
        with:
          python-version: "{{ python_version }}"
      - run: "isort --check-only ."
  flake8:
    needs: "bump_template"
    if: "{% raw %}${{ !failure() }}{% endraw %}"
    runs-on: "{{ actions_runner }}"
    steps:
      - uses: "blakeNaccarato/copier-python-workflow-setup@v0.0.11"
        with:
          python-version: "{{ python_version }}"
      - run: "flake8"
  pyright:
    needs: "bump_template"
    if: "{% raw %}${{ !failure() }}{% endraw %}"
    runs-on: "{{ actions_runner }}"
    steps:
      - uses: "blakeNaccarato/copier-python-workflow-setup@v0.0.11"
        with:
          python-version: "{{ python_version }}"
      - run: "pyright"
  pytest-cov:
    needs: "bump_template"
    if: "{% raw %}${{ !failure() }}{% endraw %}"
    runs-on: "{{ actions_runner }}"
    steps:
      - uses: "blakeNaccarato/copier-python-workflow-setup@v0.0.11"
        with:
          python-version: "{{ python_version }}"
      - run: "pytest --cov"
      - uses: "codecov/codecov-action@v3.1.1"
