ci: also run on pushes to main #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration | |
on: | |
workflow_dispatch: | |
workflow_call: | |
pull_request: | |
types: [opened, reopened, synchronize, ready_for_review] | |
branches: | |
- main | |
push: | |
branches: [main] | |
env: | |
PYTHON_VERSION: 3.9 | |
jobs: | |
changes: | |
name: Check for Python file changes | |
runs-on: ubuntu-latest | |
if: ${{ !github.event.pull_request.draft }} | |
outputs: | |
python: ${{steps.filter.outputs.python}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
filters: | | |
python: | |
- '**/*.py' | |
- 'pyproject.toml' | |
- 'pdm.lock' | |
- '.github/workflows/continuous_integration.yml' | |
mypy: | |
name: Typecheck with mypy | |
needs: [changes] | |
if: ${{needs.changes.outputs.python == 'true' && !github.event.pull_request.draft }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup reviewdog | |
uses: reviewdog/action-setup@v1 | |
- name: Set up Python ${{ env.PYTHON_VERSION }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Setup PDM | |
uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: true | |
- name: Install dependencies | |
run: | | |
pdm install | |
- name: Run mypy with reviewdog | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITHUB_EVENT_NAME: ${{ github.event_name }} | |
run: | | |
exit_val="0" | |
[[ $GITHUB_EVENT_NAME == "pull_request" ]] && reporter="github-pr-review" || reporter="github-check" | |
pdm run mypy \ | |
--show-column-numbers \ | |
--show-absolute-path \ | |
--no-error-summary . 2>&1 | reviewdog \ | |
-efm="%f:%l:%c: %t%*[^:]: %m" \ | |
-name="mypy" \ | |
-filter-mode=nofilter \ | |
-fail-on-error \ | |
-reporter="${reporter}" || exit_val="$?" | |
if [[ "${exit_val}" -ne '0' ]]; then | |
exit 1 | |
fi | |
flake8: | |
name: Lint with flake8 | |
needs: [changes] | |
if: ${{needs.changes.outputs.python == 'true' && !github.event.pull_request.draft }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup reviewdog | |
uses: reviewdog/action-setup@v1 | |
- name: Set up Python ${{ env.PYTHON_VERSION }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Setup PDM | |
uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: true | |
- name: Install dependencies | |
run: | | |
pdm install | |
- name: Run flake8 | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITHUB_EVENT_NAME: ${{ github.event_name }} | |
run: | | |
exit_val="0" | |
[[ $GITHUB_EVENT_NAME == "pull_request" ]] && reporter="github-pr-review" || reporter="github-check" | |
pdm run flake8 \ | |
--format=default . 2>&1 | reviewdog \ | |
-f=pep8 \ | |
-name="flake8" \ | |
-fail-on-error \ | |
-filter-mode=file \ | |
-reporter="${reporter}" || exit_val="$?" | |
if [[ "${exit_val}" -ne '0' ]]; then | |
exit 1 | |
fi | |
precommit: | |
name: Lint with pre-commit | |
runs-on: ubuntu-latest | |
if: ${{ !github.event.pull_request.draft }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup reviewdog | |
uses: reviewdog/action-setup@v1 | |
- name: Set up Python ${{ env.PYTHON_VERSION }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Setup PDM | |
uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: true | |
- name: Install pre-commit | |
run: | | |
pip install pre-commit | |
- name: Run pre-commit hook | |
id: run-pre-commit-hooks | |
run: | | |
git add .pre-commit-config.yaml | |
pre-commit run --color=always --all-files | |
- name: Annotate any changes using reviewdog | |
if: ${{ failure() }} | |
id: reviewdog-suggester | |
uses: reviewdog/action-suggester@v1 | |
with: | |
tool_name: pre-commit |