Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/typing-coverage-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Typing coverage comment

on:
workflow_run:
workflows: ["Typing coverage"]
types: [completed]

permissions:
contents: read
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.id }}
cancel-in-progress: false

jobs:
comment:
name: Post typing coverage report
runs-on: ubuntu-latest
if: >-
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion != 'cancelled'
steps:
- name: Download typing coverage report
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: typing-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
path: report

- name: Create or update sticky PR comment
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require("fs");
const path = require("path");

const prNumberPath = path.join("report", "pr-number.txt");
const commentPath = path.join("report", "comment.md");
if (!fs.existsSync(prNumberPath) || !fs.existsSync(commentPath)) {
core.info("Typing coverage report artifact missing; skipping PR comment.");
return;
}

const issueNumber = Number.parseInt(
fs.readFileSync(prNumberPath, "utf8").trim(),
10
);
if (!Number.isInteger(issueNumber) || issueNumber <= 0) {
core.setFailed(`Invalid PR number in artifact: ${issueNumber}`);
return;
}

const body = fs.readFileSync(commentPath, "utf8").trim();
const marker = "<!-- rope-typing-coverage -->";
if (!body.startsWith(marker)) {
core.setFailed("Report artifact is missing expected comment marker.");
return;
}

const { owner, repo } = context.repo;
const comments = await github.paginate(
github.rest.issues.listComments,
{ owner, repo, issue_number: issueNumber, per_page: 100 }
);
const existing = comments.find(
(c) =>
c.user &&
c.user.type === "Bot" &&
typeof c.body === "string" &&
c.body.includes(marker)
);

if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
core.info(`Updated typing coverage comment #${existing.id} on PR #${issueNumber}.`);
} else {
const created = await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body,
});
core.info(`Created typing coverage comment #${created.data.id} on PR #${issueNumber}.`);
}
88 changes: 88 additions & 0 deletions .github/workflows/typing-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Typing coverage

on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
typing-coverage:
name: Typing coverage
runs-on: ubuntu-latest
env:
MYPY_VERSION: "2.4.1"
COVERAGE_THRESHOLD: "50.0"
MAX_DROP_PP: "5.0"
OVERRIDE_LABEL: "allow-typing-regression"
steps:
- name: Check out PR head
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: pr

- name: Check out base branch
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base

- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.13"

- name: Install mypy
run: python -m pip install --no-cache-dir "mypy==${MYPY_VERSION}"

- name: Compare typing coverage
id: compare
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
HAS_OVERRIDE_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'allow-typing-regression') }}
run: |
mkdir -p report
printf '%s\n' "${PR_NUMBER}" > report/pr-number.txt

extra_args=()
if [ "${HAS_OVERRIDE_LABEL}" = "true" ]; then
extra_args+=(--allow-regression)
fi

status=0
python pr/bin/typing-coverage.py \
--base-dir base \
--pr-dir pr \
--package rope \
--threshold "${COVERAGE_THRESHOLD}" \
--max-drop "${MAX_DROP_PP}" \
--override-label "${OVERRIDE_LABEL}" \
--base-ref "${BASE_REF}" \
--pr-sha "${PR_SHA}" \
--markdown-out report/comment.md \
--json-out report/results.json \
"${extra_args[@]}" || status=$?

if [ -f report/comment.md ]; then
cat report/comment.md >> "${GITHUB_STEP_SUMMARY}"
fi
exit "${status}"

- name: Upload typing coverage report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: typing-coverage-report
path: |
report/pr-number.txt
report/comment.md
report/results.json
retention-days: 7
if-no-files-found: warn
Loading
Loading