mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Added support for mypy_primer workflow.
This commit is contained in:
parent
c8e72e70f3
commit
37de82f374
69
.github/workflows/mypy_primer.yaml
vendored
Normal file
69
.github/workflows/mypy_primer.yaml
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
name: Run mypy_primer
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'pyright/**'
|
||||
- 'pyright-internal/src/**'
|
||||
- 'pyright-internal/typeshed-fallback/**'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
mypy_primer:
|
||||
name: Run mypy_primer
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
strategy:
|
||||
matrix:
|
||||
shard-index: [0, 1, 2]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: pyright_to_test
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- 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"
|
||||
|
||||
echo ''
|
||||
cd ..
|
||||
# fail action if exit code isn't zero or one
|
||||
(
|
||||
mypy_primer \
|
||||
--repo pyright_to_test \
|
||||
--type-checker pyright \
|
||||
--new $GITHUB_SHA \
|
||||
--num-shards 3 --shard-index ${{ matrix.shard-index }} \
|
||||
--debug \
|
||||
--output concise \
|
||||
| tee diff_${{ matrix.shard-index }}.txt
|
||||
) || [ $? -eq 1 ]
|
||||
- name: Upload mypy_primer diff
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: mypy_primer_diffs
|
||||
path: diff_${{ matrix.shard-index }}.txt
|
||||
- if: ${{ matrix.shard-index }} == 0
|
||||
name: Save PR number
|
||||
run: |
|
||||
echo ${{ github.event.pull_request.number }} | tee pr_number.txt
|
||||
- if: ${{ matrix.shard-index }} == 0
|
||||
name: Upload PR number
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: mypy_primer_diffs
|
||||
path: pr_number.txt
|
98
.github/workflows/mypy_primer_comment.yaml
vendored
Normal file
98
.github/workflows/mypy_primer_comment.yaml
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
name: Comment with mypy_primer diff
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows:
|
||||
- Run mypy_primer
|
||||
types:
|
||||
- completed
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
comment:
|
||||
name: Comment PR from mypy_primer
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
steps:
|
||||
- name: Download diffs
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: ${{ github.event.workflow_run.id }},
|
||||
});
|
||||
const [matchArtifact] = artifacts.data.artifacts.filter((artifact) =>
|
||||
artifact.name == "mypy_primer_diffs");
|
||||
|
||||
const download = await github.rest.actions.downloadArtifact({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
artifact_id: matchArtifact.id,
|
||||
archive_format: "zip",
|
||||
});
|
||||
fs.writeFileSync("diff.zip", Buffer.from(download.data));
|
||||
|
||||
- run: unzip diff.zip
|
||||
- run: |
|
||||
cat diff_*.txt | tee fulldiff.txt
|
||||
|
||||
- name: Post comment
|
||||
id: post-comment
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const MAX_CHARACTERS = 30000
|
||||
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3
|
||||
|
||||
const fs = require('fs')
|
||||
let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' })
|
||||
|
||||
function truncateIfNeeded(original, maxLength) {
|
||||
if (original.length <= maxLength) {
|
||||
return original
|
||||
}
|
||||
let truncated = original.substring(0, maxLength)
|
||||
// further, remove last line that might be truncated
|
||||
truncated = truncated.substring(0, truncated.lastIndexOf('\n'))
|
||||
let lines_truncated = original.split('\n').length - truncated.split('\n').length
|
||||
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...`
|
||||
}
|
||||
|
||||
const projects = data.split('\n\n')
|
||||
// don't let one project dominate
|
||||
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n')
|
||||
// posting comment fails if too long, so truncate
|
||||
data = truncateIfNeeded(data, MAX_CHARACTERS)
|
||||
|
||||
console.log("Diff from mypy_primer:")
|
||||
console.log(data)
|
||||
|
||||
let body
|
||||
if (data.trim()) {
|
||||
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 + '```'
|
||||
} else {
|
||||
body = "According to [mypy_primer](https://github.com/hauntsaninja/mypy_primer), this change doesn't affect type check results on a corpus of open source code. ✅"
|
||||
}
|
||||
const prNumber = parseInt(fs.readFileSync("pr_number.txt", { encoding: "utf8" }))
|
||||
await github.rest.issues.createComment({
|
||||
issue_number: prNumber,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body
|
||||
})
|
||||
return prNumber
|
||||
|
||||
- name: Hide old comments
|
||||
# v0.4.0
|
||||
uses: kanga333/comment-hider@c12bb20b48aeb8fc098e35967de8d4f8018fffdf
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
leave_visible: 1
|
||||
issue_number: ${{ steps.post-comment.outputs.result }}
|
Loading…
Reference in New Issue
Block a user