Skip to content

Commit 93e8fdf

Browse files
committed
Add comment workflow to show how changes affect stdlib docstrings
1 parent 3362df8 commit 93e8fdf

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = async ({ github, context }) => {
2+
const fs = require("fs");
3+
4+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
5+
owner: context.repo.owner,
6+
repo: context.repo.repo,
7+
run_id: context.payload.workflow_run.id,
8+
});
9+
const [matchArtifact] = artifacts.data.artifacts.filter(
10+
(artifact) => artifact.name == "docstring-adder-diff",
11+
);
12+
const download = await github.rest.actions.downloadArtifact({
13+
owner: context.repo.owner,
14+
repo: context.repo.repo,
15+
artifact_id: matchArtifact.id,
16+
archive_format: "zip",
17+
});
18+
19+
fs.writeFileSync("diff.zip", Buffer.from(download.data));
20+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = async ({ github, context }) => {
2+
const fs = require("fs");
3+
4+
let data = fs.readFileSync("docstring-adder-diff.txt", { encoding: "utf8" });
5+
// posting comment fails if too long, so truncate
6+
if (data.length > 30000) {
7+
let truncated_data = data.substring(0, 30000);
8+
let lines_truncated =
9+
data.split("\n").length - truncated_data.split("\n").length;
10+
data =
11+
truncated_data + `\n\n... (truncated ${lines_truncated} lines) ...\n`;
12+
}
13+
14+
const body = data.trim()
15+
? "⚠ Diff showing the effect of this PR on the typeshed stdlib: \n```diff\n" +
16+
data +
17+
"\n```"
18+
: "This change has no effect on the docstrings that would be added to typeshed. 🤖🎉";
19+
const issue_number = parseInt(
20+
fs.readFileSync("pr_number.txt", { encoding: "utf8" }),
21+
);
22+
await github.rest.issues.createComment({
23+
issue_number,
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
body,
27+
});
28+
29+
return issue_number;
30+
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: typeshed_primer
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
11+
cancel-in-progress: true
12+
13+
env:
14+
FORCE_COLOR: 1
15+
CLICOLOR_FORCE: 1 # recognized by uv
16+
17+
jobs:
18+
typeshed_primer:
19+
timeout-minutes: 5
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout docstring-adder on target branch
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.base_ref }}
26+
path: old_codemod
27+
- name: Checkout docstring-adder on PR branch
28+
uses: actions/checkout@v4
29+
with:
30+
path: new_codemod
31+
- name: Checkout typeshed
32+
uses: actions/checkout@v4
33+
with:
34+
repository: python/typeshed
35+
path: typeshed
36+
- uses: astral-sh/setup-uv@v6
37+
- name: Setup git
38+
run: |
39+
git config --global user.name stubdefaulter
40+
git config --global user.email ''
41+
- name: Codemod typeshed using target branch
42+
run: |
43+
uvx --python=3.13 --from=./old_codemod add-docstrings --stdlib-path ./typeshed/stdlib
44+
uvx --python=3.9 --from=./old_codemod add-docstrings --stdlib-path ./typeshed/stdlib
45+
uvx --directory=typeshed black stdlib|| true
46+
git -C typeshed commit -a -m "With old stubdefaulter"
47+
- name: Codemod typeshed using PR branch
48+
run: |
49+
git -C typeshed checkout HEAD~1 -- stdlib
50+
git -C typeshed restore --staged stdlib
51+
uvx --python=3.13 --from=./new_codemod add-docstrings --stdlib-path ./typeshed/stdlib
52+
uvx --python=3.9 --from=./new_codemod add-docstrings --stdlib-path ./typeshed/stdlib
53+
uvx --directory=typeshed black stdlib || true
54+
- name: Get the diff between the two docstring-adder runs
55+
run: git -C typeshed diff | tee docstring-adder-diff.txt
56+
- name: Save PR number
57+
run: echo ${{ github.event.pull_request.number }} | tee pr_number.txt
58+
- name: Upload diff and PR number
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: docstring-adder-diff
62+
path: |
63+
docstring-adder-diff.txt
64+
pr_number.txt
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Post typeshed_primer comment
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- typeshed_primer
7+
types:
8+
- completed
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
env:
15+
FORCE_COLOR: 1
16+
CLICOLOR_FORCE: 1 # recognized by uv
17+
18+
jobs:
19+
comment:
20+
name: Comment PR from typeshed_primer
21+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Download diff
26+
uses: actions/github-script@v7
27+
with:
28+
script: await require('.github/scripts/typeshed_primer_download_diff.js')({github, context})
29+
- run: unzip diff.zip
30+
- name: Post comment
31+
id: post-comment
32+
uses: actions/github-script@v7
33+
with:
34+
github-token: ${{secrets.GITHUB_TOKEN}}
35+
script: return await require('.github/scripts/typeshed_primer_post_comment.js')({github, context})
36+
- name: Hide old comments
37+
# v0.4.0
38+
uses: kanga333/comment-hider@c12bb20b48aeb8fc098e35967de8d4f8018fffdf
39+
with:
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
leave_visible: 1
42+
issue_number: ${{ steps.post-comment.outputs.result }}

0 commit comments

Comments
 (0)