| 1 |
name: Run mypy_primer |
| 2 |
|
| 3 |
on: |
| 4 |
# Only run on PR, since we diff against main |
| 5 |
pull_request: |
| 6 |
paths: |
| 7 |
- ".github/workflows/mypy_primer.yml" |
| 8 |
- ".github/workflows/mypy_primer_comment.yml" |
| 9 |
- "numpy/**/*.pyi" |
| 10 |
- "numpy/_typing/*.py" |
| 11 |
- "numpy/typing/*.py" |
| 12 |
- "!numpy/typing/tests/**" |
| 13 |
- "numpy/py.typed" |
| 14 |
|
| 15 |
concurrency: |
| 16 |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} |
| 17 |
cancel-in-progress: true |
| 18 |
|
| 19 |
permissions: |
| 20 |
contents: read |
| 21 |
|
| 22 |
jobs: |
| 23 |
mypy_primer: |
| 24 |
name: Run |
| 25 |
runs-on: ubuntu-latest |
| 26 |
strategy: |
| 27 |
matrix: |
| 28 |
shard-index: [0] # e.g. change this to [0, 1, 2] and --num-shards below to 3 |
| 29 |
fail-fast: false |
| 30 |
steps: |
| 31 |
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 32 |
with: |
| 33 |
path: numpy_to_test |
| 34 |
fetch-depth: 0 |
| 35 |
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 |
| 36 |
with: |
| 37 |
python-version: "3.12" |
| 38 |
- name: Install dependencies |
| 39 |
run: pip install git+https://github.com/hauntsaninja/mypy_primer.git |
| 40 |
- name: Run mypy_primer |
| 41 |
shell: bash |
| 42 |
run: | |
| 43 |
cd numpy_to_test |
| 44 |
MYPY_VERSION=$(grep mypy== requirements/test_requirements.txt | sed -n 's/mypy==\([^;]*\).*/\1/p') |
| 45 |
|
| 46 |
echo "new commit" |
| 47 |
git checkout $GITHUB_SHA |
| 48 |
git rev-list --format=%s --max-count=1 HEAD |
| 49 |
|
| 50 |
MERGE_BASE=$(git merge-base $GITHUB_SHA origin/$GITHUB_BASE_REF) |
| 51 |
git worktree add ../numpy_base $MERGE_BASE |
| 52 |
cd ../numpy_base |
| 53 |
|
| 54 |
echo "base commit" |
| 55 |
git rev-list --format=%s --max-count=1 HEAD |
| 56 |
|
| 57 |
echo '' |
| 58 |
cd .. |
| 59 |
# fail action if exit code isn't zero or one |
| 60 |
# TODO: note that we don't build numpy, so if a project attempts to use the |
| 61 |
# numpy mypy plugin, we may see some issues involving version skew. |
| 62 |
( |
| 63 |
mypy_primer \ |
| 64 |
--new v${MYPY_VERSION} --old v${MYPY_VERSION} \ |
| 65 |
--known-dependency-selector numpy \ |
| 66 |
--old-prepend-path numpy_base --new-prepend-path numpy_to_test \ |
| 67 |
--num-shards 1 --shard-index ${{ matrix.shard-index }} \ |
| 68 |
--debug \ |
| 69 |
--output concise \ |
| 70 |
| tee diff_${{ matrix.shard-index }}.txt |
| 71 |
) || [ $? -eq 1 ] |
| 72 |
- if: ${{ matrix.shard-index == 0 }} |
| 73 |
name: Save PR number |
| 74 |
run: | |
| 75 |
echo ${{ github.event.pull_request.number }} | tee pr_number.txt |
| 76 |
- name: Upload mypy_primer diff + PR number |
| 77 |
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 78 |
if: ${{ matrix.shard-index == 0 }} |
| 79 |
with: |
| 80 |
name: mypy_primer_diffs-${{ matrix.shard-index }} |
| 81 |
path: | |
| 82 |
diff_${{ matrix.shard-index }}.txt |
| 83 |
pr_number.txt |
| 84 |
- name: Upload mypy_primer diff |
| 85 |
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 86 |
if: ${{ matrix.shard-index != 0 }} |
| 87 |
with: |
| 88 |
name: mypy_primer_diffs-${{ matrix.shard-index }} |
| 89 |
path: diff_${{ matrix.shard-index }}.txt |
| 90 |
|
| 91 |
join_artifacts: |
| 92 |
name: Join artifacts |
| 93 |
runs-on: ubuntu-latest |
| 94 |
needs: [mypy_primer] |
| 95 |
permissions: |
| 96 |
contents: read |
| 97 |
steps: |
| 98 |
- name: Merge artifacts |
| 99 |
uses: actions/upload-artifact/merge@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 |
| 100 |
with: |
| 101 |
name: mypy_primer_diffs |
| 102 |
pattern: mypy_primer_diffs-* |
| 103 |
delete-merged: true |