Repository navigation
90 lines (83 loc) · 3.06 KB
/
Copy pathtype-check-python.yml
File metadata and controls
90 lines (83 loc) · 3.06 KB
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
name: Python Type Check
on:
push:
branches: [main]
paths:
- "ods/**/*.py"
- "ods/extensions/services/*/requirements.lock"
- ".github/mypy-baseline.json"
- ".github/scripts/mypy-ratchet.py"
- ".github/scripts/test_mypy_ratchet.py"
- ".github/workflows/type-check-python.yml"
pull_request:
branches: [main]
paths:
- "ods/**/*.py"
- "ods/extensions/services/*/requirements.lock"
- ".github/mypy-baseline.json"
- ".github/scripts/mypy-ratchet.py"
- ".github/scripts/test_mypy_ratchet.py"
- ".github/workflows/type-check-python.yml"
permissions:
contents: read
# mypy and each service's locked dependencies are pinned, so a run's result depends
# only on the code. Existing errors are recorded in .github/mypy-baseline.json; a job
# fails when a change adds a new one. See .github/scripts/mypy-ratchet.py.
jobs:
mypy:
name: mypy (${{ matrix.target }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: dashboard-api
directory: ods/extensions/services/dashboard-api
sources: .
- target: token-spy
directory: ods/extensions/services/token-spy
sources: .
- target: privacy-shield
directory: ods/extensions/services/privacy-shield
sources: .
- target: scripts
directory: ods/scripts
sources: "*.py"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: "3.11"
- name: Install mypy and the locked dependencies
working-directory: ${{ matrix.directory }}
shell: bash
run: |
python -m pip install 'mypy==2.4.0'
if [[ -f requirements.lock ]]; then
python -m pip install --require-hashes -r requirements.lock
fi
- name: Self-test the ratchet
run: python -m unittest discover -s .github/scripts -p test_mypy_ratchet.py
- name: Type check ${{ matrix.target }}
working-directory: ${{ matrix.directory }}
shell: bash
env:
TARGET: ${{ matrix.target }}
DIRECTORY: ${{ matrix.directory }}
SOURCES: ${{ matrix.sources }}
run: |
status=0
# shellcheck disable=SC2086 # SOURCES is a glob or a directory
mypy $SOURCES --ignore-missing-imports --no-strict-optional --check-untyped-defs \
> "$RUNNER_TEMP/mypy.txt" || status=$?
cat "$RUNNER_TEMP/mypy.txt"
# mypy exits 1 when it reports errors, which the ratchet judges; any other
# nonzero status means mypy itself failed.
if [[ "$status" -gt 1 ]]; then
exit "$status"
fi
python "$GITHUB_WORKSPACE/.github/scripts/mypy-ratchet.py" \
--target "$TARGET" --prefix "$DIRECTORY" < "$RUNNER_TEMP/mypy.txt"