初始化上传
Some checks failed
Run mypy_primer on push / Run mypy_primer on push (push) Has been cancelled
Validation / Typecheck (push) Has been cancelled
Validation / Style (push) Has been cancelled
Validation / Test macos-latest (push) Has been cancelled
Validation / Test ubuntu-latest (push) Has been cancelled
Validation / Test windows-latest (push) Has been cancelled
Validation / Build (push) Has been cancelled
Validation / Required (push) Has been cancelled

This commit is contained in:
2026-07-24 17:08:39 +08:00
commit e9e4693333
7516 changed files with 768821 additions and 0 deletions

69
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,69 @@
name: 'Build'
env:
NODE_VERSION: '22.x' # Shipped with VS Code.
ARTIFACT_NAME_VSIX: vsix
VSIX_NAME: vscode-pyright.vsix
on:
push:
tags:
- '1.1.[0-9][0-9][0-9]'
jobs:
build:
if: github.repository == 'microsoft/pyright'
runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- uses: ./.github/actions/npm-cache-dir
- run: npm run install:all
- name: Build VSIX
working-directory: packages/vscode-pyright
run: |
npm run package
mv pyright-*.vsix ${{ env.VSIX_NAME }}
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME_VSIX }}
path: packages/vscode-pyright/${{ env.VSIX_NAME }}
create_release:
if: github.repository == 'microsoft/pyright'
runs-on: ubuntu-latest
name: Create release
needs: [build]
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
# TODO: If the release already exists (tag created via the GUI), reuse it.
- name: Create release
id: create_release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Published ${{ github.ref_name }}
draft: true
artifacts: ./artifacts/${{ env.ARTIFACT_NAME_VSIX }}/${{ env.VSIX_NAME }}
artifactContentType: application/zip

View File

@@ -0,0 +1,104 @@
# This workflow runs when the "Run mypy_primer on PR" workflow completes.
# It downloads the diff from the other workflow instances and creates
# a summary comment in the PR.
name: Comment with mypy_primer diff
on:
workflow_run:
workflows:
- Run mypy_primer on PR
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@v7
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 matchedArtifacts = artifacts.data.artifacts.filter((artifact) =>
artifact.name.startsWith("mypy_primer_diffs"));
for (let i = 0; i < matchedArtifacts.length; i++) {
const matchArtifact = matchedArtifacts[i];
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_${i}.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@v7
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 }}

122
.github/workflows/mypy_primer_pr.yaml vendored Normal file
View File

@@ -0,0 +1,122 @@
# 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).
# This workflow definition borrows liberally from the mypy repo. The original
# 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.
name: Run mypy_primer on PR
env:
NODE_VERSION: '22.x' # Shipped with VS Code.
on:
# Run on the creation or update of a PR.
pull_request:
paths:
- 'packages/pyright/**'
- 'packages/pyright-internal/src/**'
- 'packages/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 on PR
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
shard-index: [0, 1, 2, 3, 4, 5, 6, 7]
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
path: pyright_to_test
fetch-depth: 2
fetch-tags: false
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: 'pyright_to_test/**/package-lock.json'
- 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
env:
# mypy_primer installs both the PR and base commits. The base commit can contain
# historical peer dependency conflicts that should not block primer comparisons.
NPM_CONFIG_LEGACY_PEER_DEPS: 'true'
run: |
cd pyright_to_test
echo "new commit"
git rev-list --format=%s --max-count=1 $GITHUB_SHA
git branch new_commit $GITHUB_SHA
MERGE_BASE=$(git rev-parse "$GITHUB_SHA^1")
git checkout -b base_commit $MERGE_BASE
echo "base commit"
git rev-list --format=%s --max-count=1 base_commit
# Keep the old checker source at the merge base, but use this PR's
# dependency and bundler metadata so the old checkout can install and build.
mapfile -t BASE_BUILD_FILES < <(
git ls-tree -r --name-only "$GITHUB_SHA" |
grep -E '^(package(-lock)?\.json|packages/[^/]+/package(-lock)?\.json|packages/[^/]+/rspack\.config\.js)$'
)
echo "Using build metadata for mypy_primer base:"
printf '%s\n' "${BASE_BUILD_FILES[@]}"
git checkout $GITHUB_SHA -- "${BASE_BUILD_FILES[@]}"
printf 'legacy-peer-deps=true\n' > .npmrc
git add .npmrc "${BASE_BUILD_FILES[@]}"
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -m "Configure build dependencies for mypy_primer base"
echo "Prepared mypy_primer base_commit with generated package and rspack build metadata."
echo ''
cd ..
npm config set legacy-peer-deps true --location=user
npm config get legacy-peer-deps
# fail action if exit code isn't zero or one
(
mypy_primer \
--repo pyright_to_test \
--type-checker pyright \
--new new_commit --old base_commit \
--num-shards 8 --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@v4
with:
name: mypy_primer_diffs_${{ matrix.shard-index }}
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@v4
with:
name: mypy_primer_diffs_pr_number
path: pr_number.txt

79
.github/workflows/mypy_primer_push.yaml vendored Normal file
View File

@@ -0,0 +1,79 @@
# 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 commit and the last release tag and
# compares the output of both. It uploads the diffs as an artifact.
name: Run mypy_primer on push
env:
NODE_VERSION: '22.x' # Shipped with VS Code.
on:
# Run on all pushes to main.
push:
branches:
- main
paths:
- 'packages/pyright/**'
- 'packages/pyright-internal/src/**'
- 'packages/pyright-internal/typeshed-fallback/**'
# Also run manually if requested.
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
mypy_primer:
name: Run mypy_primer on push
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
path: pyright_to_test
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: 'pyright_to_test/**/package-lock.json'
- 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
env:
# mypy_primer installs both the new and old commits. The old commit can contain
# historical peer dependency conflicts that should not block primer comparisons.
NPM_CONFIG_LEGACY_PEER_DEPS: 'true'
run: |
cd pyright_to_test
echo "new commit"
git rev-list --format=%s --max-count=1 $GITHUB_SHA
cd ..
npm config set legacy-peer-deps true --location=user
npm config get legacy-peer-deps
# fail action if exit code isn't zero or one
(
mypy_primer \
--repo pyright_to_test \
--type-checker pyright \
--new $GITHUB_SHA \
--debug \
--output concise \
| tee diff.txt
) || [ $? -eq 1 ]
- name: Upload mypy_primer diff
uses: actions/upload-artifact@v4
with:
name: mypy_primer_diffs
path: diff.txt

166
.github/workflows/validation.yml vendored Normal file
View File

@@ -0,0 +1,166 @@
name: 'Validation'
env:
NODE_VERSION: '22.x' # Shipped with VS Code.
PYTHON_VERSION: 3.11
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
typecheck:
if: github.repository == 'microsoft/pyright'
runs-on: ubuntu-latest
name: Typecheck
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- uses: ./.github/actions/npm-cache-dir
- run: npm run install:all
- run: npx lerna exec --stream --no-bail -- "tsc --noEmit"
style:
if: github.repository == 'microsoft/pyright'
runs-on: ubuntu-latest
name: Style
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- uses: ./.github/actions/npm-cache-dir
- run: npm run install:all
- name: Check diff after npm install
run: git diff --exit-code --name-only
- run: npm run check
test:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
name: Test ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: typecheck
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- uses: ./.github/actions/npm-cache-dir
- run: npm run install:all
- name: npm test (pyright-internal)
run: npm test
working-directory: packages/pyright-internal
# Install python so we can create a VENV for tests
- name: Use Python ${{env.PYTHON_VERSION}}
uses: actions/setup-python@v5
id: install_python
with:
python-version: ${{env.PYTHON_VERSION}}
- name: Create Venv
run: |
${{ steps.install_python.outputs.python-path }} -m venv .venv
- name: Activate and install pytest (linux)
if: runner.os != 'Windows'
run: |
source .venv/bin/activate
python -m pip install pytest
python -c "import sys;print('python_venv_path=' + sys.executable)" >> $GITHUB_ENV
- name: Activate and install pytest (windows)
if: runner.os == 'Windows'
run: |
.venv\scripts\activate
python -m pip install pytest
python -c "import sys;print('python_venv_path=' + sys.executable)" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Echo python_venv_path
run: |
echo python_venv_path=${{env.python_venv_path}}
- name: Run import tests with venv
env:
CI_IMPORT_TEST_VENVPATH: '../../'
CI_IMPORT_TEST_VENV: '.venv'
run: npm run test:imports
working-directory: packages/pyright-internal
- name: Run import tests with pythonpath
env:
CI_IMPORT_TEST_PYTHONPATH: ${{env.python_venv_path}}
run: npm run test:imports
working-directory: packages/pyright-internal
build:
runs-on: ubuntu-latest
name: Build
needs: typecheck
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- uses: ./.github/actions/choose-npm-install
- run: npm publish --dry-run
working-directory: packages/pyright
- run: npm publish --dry-run
working-directory: packages/pyright-typeserver
- run: npm run package
working-directory: packages/vscode-pyright
required:
runs-on: ubuntu-latest
name: Required
needs:
- typecheck
- style
- test
- build
steps:
- run: echo All required jobs succeeded.