Skip to content

Commit 42aa9f3

Browse files
authored
mypy_primer: add to CI (#9686)
This will run mypy_primer on mypy PRs. Changes on the open source corpus are reported as comments on the PR. We integrated this into typeshed CI; you can see examples here: python/typeshed#3183 python/typeshed#4734 This might be a little slow. On typeshed this runs in 10 minutes, but it's using a mypyc compiled wheel. It looks like it takes three minutes to compile a MYPYC_OPT_LEVEL=0 wheel in our CI currently (for a ~2x speedup), so that's probably worth it. Co-authored-by: hauntsaninja <>
1 parent 1e6063d commit 42aa9f3

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

.github/workflows/mypy_primer.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Run mypy_primer
2+
3+
on:
4+
# Only run on PR, since we diff against master
5+
# pull_request_target gives us access to a write token
6+
pull_request_target:
7+
paths-ignore:
8+
- 'docs/**'
9+
- '**/*.rst'
10+
- '**/*.md'
11+
- 'mypyc/**'
12+
13+
jobs:
14+
mypy_primer:
15+
name: Run mypy_primer
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
with:
20+
path: mypy_to_test
21+
fetch-depth: 0
22+
# pull_request_target checks out the PR base branch by default
23+
ref: refs/pull/${{ github.event.pull_request.number }}/merge
24+
- uses: actions/setup-python@v2
25+
with:
26+
python-version: 3.8
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install -U pip
30+
pip install git+https://github.com/hauntsaninja/mypy_primer.git
31+
- name: Run mypy_primer
32+
shell: bash
33+
run: |
34+
cd mypy_to_test
35+
echo "new commit"
36+
COMMIT=$(git rev-parse HEAD)
37+
git rev-list --format=%s --max-count=1 $COMMIT
38+
git checkout -b upstream_master origin/master
39+
echo "base commit"
40+
git rev-list --format=%s --max-count=1 upstream_master
41+
echo ''
42+
cd ..
43+
( mypy_primer --repo mypy_to_test --new $COMMIT --old upstream_master --mypyc-compile-level 0 -o concise | tee diff.txt ) || [ $? -eq 1 ]
44+
- name: Post comment
45+
uses: actions/github-script@v3
46+
with:
47+
github-token: ${{secrets.GITHUB_TOKEN}}
48+
script: |
49+
const fs = require('fs').promises;
50+
try {
51+
data = await fs.readFile('diff.txt', 'utf-8')
52+
if (data.trim()) {
53+
await github.issues.createComment({
54+
issue_number: context.issue.number,
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
body: 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
58+
})
59+
}
60+
} catch (error) {
61+
console.log(error)
62+
}

0 commit comments

Comments
 (0)