-
Notifications
You must be signed in to change notification settings - Fork 20
98 lines (86 loc) · 2.98 KB
/
mypy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# We do not include mypy as a pre-commit hook because pre-commit hooks
# are installed in their own virtual environment, so mypy cannot
# use stubs from imports
name: mypy
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
mypy:
runs-on: ubuntu-latest
permissions:
pull-requests: write
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref }}"
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- name: Cache venv
uses: actions/[email protected]
id: cache_venv
with:
path: |
.venv
key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
- name: Set up Python
uses: actions/setup-python@v4
id: setup_python
if: steps.cache_venv.outputs.cache-hit != 'true'
with:
python-version: "3.9"
- name: Install dependencies
shell: bash
if: steps.cache_venv.outputs.cache-hit != 'true'
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Cache mypy cache
uses: actions/[email protected]
with:
path: .mypy_cache
key: ${{ runner.os }}-mypy-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
- name: Run mypy
id: mypy
continue-on-error: true
run: |
source .venv/bin/activate
if mypy src; then
echo "mypy check passed"
echo "mypy_failed=0" >> $GITHUB_OUTPUT
else
echo "mypy check failed"
echo "mypy_failed=1" >> $GITHUB_OUTPUT
fi
- name: Find Comment
uses: peter-evans/find-comment@v2
id: find_comment
if: ${{github.event_name == 'pull_request'}}
continue-on-error: true
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: ✨ Looks like mypy failed ✨
- uses: mshick/add-pr-comment@v2
if: ${{ steps.mypy.outputs.mypy_failed == 1 && github.event_name == 'pull_request'}}
id: add_comment
with:
message: |
✨ Looks like mypy failed ✨
If you want to fix this, we recommend doing it locally by:
1. Installing mypy, which is included in the dev dependencies: `pip install -e ".[dev]"`
2. Diagnosing the errors by running `mypy .`
- uses: mshick/add-pr-comment@v2
if: ${{ steps.mypy.outputs.mypy_failed == 0 && steps.find_comment.outputs.comment-id != '' && github.event_name == 'pull_request'}}
with:
message-id: ${{ steps.find_comment.outputs.comment-id }}
message: |
🌟 mypy succeeds! 🌟
- name: fail run if mypy failed
id: fail_run
if: ${{steps.mypy.outputs.mypy_failed == 1}}
run: |
exit 1