2023-06-09 08:09:15 +03:00
|
|
|
# This workflow runs mypy_primer, a tool that runs pyright on a variety
|
|
|
|
# of open-source Python projects that are known to type check with pyright.
|
|
|
|
# It builds pyright from the latest PR commit and the merge base of the PR
|
|
|
|
# and compares the output of both. It uploads the diffs as an artifact and
|
|
|
|
# creates a PR comment with the results (with the help of the
|
|
|
|
# mypy_primer_comment action).
|
|
|
|
|
2023-06-09 08:23:47 +03:00
|
|
|
# This workflow definition borrows liberally from the mypy repo. The original
|
2023-06-09 08:09:15 +03:00
|
|
|
# workflow was designed to work in a sharded manner where n copies of
|
|
|
|
# mypy_primer are started in parallel. Each instance runs 1/n of the projects.
|
|
|
|
# For now, we run only one instance because pyright is fast, and the number
|
|
|
|
# of projects that use pyright for type checking is small. To change this in
|
|
|
|
# the future, change the 'shard_index' matrix to [0, 1, ..., n-1] and set
|
|
|
|
# 'num-shards' to n.
|
|
|
|
|
2023-06-09 07:45:10 +03:00
|
|
|
name: Run mypy_primer on PR
|
2023-06-09 06:47:21 +03:00
|
|
|
|
|
|
|
on:
|
2023-06-09 08:09:15 +03:00
|
|
|
# Run on the creation or update of a PR.
|
2023-06-09 06:47:21 +03:00
|
|
|
pull_request:
|
|
|
|
paths:
|
2023-06-09 07:03:29 +03:00
|
|
|
- 'packages/pyright/**'
|
|
|
|
- 'packages/pyright-internal/src/**'
|
|
|
|
- 'packages/pyright-internal/typeshed-fallback/**'
|
2023-06-09 06:47:21 +03:00
|
|
|
|
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
mypy_primer:
|
2023-06-09 07:45:10 +03:00
|
|
|
name: Run mypy_primer on PR
|
2023-06-09 06:47:21 +03:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
strategy:
|
|
|
|
matrix:
|
2023-06-15 03:36:01 +03:00
|
|
|
shard-index: [0, 1]
|
2023-06-09 06:47:21 +03:00
|
|
|
fail-fast: false
|
|
|
|
steps:
|
2024-05-22 22:31:23 +03:00
|
|
|
- uses: actions/checkout@v4
|
2023-06-09 06:47:21 +03:00
|
|
|
with:
|
|
|
|
path: pyright_to_test
|
|
|
|
fetch-depth: 0
|
2024-05-22 22:31:23 +03:00
|
|
|
- uses: actions/setup-python@v5
|
2023-06-09 06:47:21 +03:00
|
|
|
with:
|
2023-06-09 07:03:29 +03:00
|
|
|
python-version: '3.10'
|
2023-06-09 06:47:21 +03:00
|
|
|
- name: Install dependencies
|
|
|
|
run: |
|
|
|
|
python -m pip install -U pip
|
|
|
|
pip install git+https://github.com/hauntsaninja/mypy_primer.git
|
|
|
|
- name: Run mypy_primer
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
cd pyright_to_test
|
|
|
|
echo "new commit"
|
2023-06-09 07:45:10 +03:00
|
|
|
git rev-list --format=%s --max-count=1 $GITHUB_SHA
|
|
|
|
|
|
|
|
MERGE_BASE=$(git merge-base $GITHUB_SHA origin/$GITHUB_BASE_REF)
|
|
|
|
git checkout -b base_commit $MERGE_BASE
|
|
|
|
echo "base commit"
|
|
|
|
git rev-list --format=%s --max-count=1 base_commit
|
2023-06-09 06:47:21 +03:00
|
|
|
|
|
|
|
echo ''
|
|
|
|
cd ..
|
|
|
|
# fail action if exit code isn't zero or one
|
|
|
|
(
|
|
|
|
mypy_primer \
|
|
|
|
--repo pyright_to_test \
|
|
|
|
--type-checker pyright \
|
2023-06-09 07:45:10 +03:00
|
|
|
--new $GITHUB_SHA --old base_commit \
|
2023-06-15 03:36:01 +03:00
|
|
|
--num-shards 2 --shard-index ${{ matrix.shard-index }} \
|
2023-06-09 06:47:21 +03:00
|
|
|
--debug \
|
|
|
|
--output concise \
|
|
|
|
| tee diff_${{ matrix.shard-index }}.txt
|
|
|
|
) || [ $? -eq 1 ]
|
|
|
|
- name: Upload mypy_primer diff
|
2024-05-22 22:31:23 +03:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-06-09 06:47:21 +03:00
|
|
|
with:
|
2024-05-22 22:31:23 +03:00
|
|
|
name: mypy_primer_diffs_${{ matrix.shard-index }}
|
2023-06-09 06:47:21 +03:00
|
|
|
path: diff_${{ matrix.shard-index }}.txt
|
2024-05-22 22:31:23 +03:00
|
|
|
- if: ${{ matrix.shard-index == 0 }}
|
2023-06-09 06:47:21 +03:00
|
|
|
name: Save PR number
|
|
|
|
run: |
|
|
|
|
echo ${{ github.event.pull_request.number }} | tee pr_number.txt
|
2024-05-22 22:31:23 +03:00
|
|
|
- if: ${{ matrix.shard-index == 0 }}
|
2023-06-09 06:47:21 +03:00
|
|
|
name: Upload PR number
|
2024-05-22 22:31:23 +03:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-06-09 06:47:21 +03:00
|
|
|
with:
|
2024-05-22 22:31:23 +03:00
|
|
|
name: mypy_primer_diffs_pr_number
|
2023-06-09 06:47:21 +03:00
|
|
|
path: pr_number.txt
|