-
Notifications
You must be signed in to change notification settings - Fork 49
117 lines (104 loc) · 3.87 KB
/
pydoctor_primer.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Run pydoctor_primer
on:
# Only run on PR, since we diff against master
pull_request:
paths-ignore:
- 'pydoctor/test/**'
- 'docs/**'
- '*.rst'
- '*.txt'
- '*.in'
- '*.md'
- '.*'
- 'setup.py'
jobs:
pydoctor_primer:
name: Run pydoctor_primer
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
path: pydoctor_to_test
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install pydoctor_primer
run: |
python -m pip install -U pip
pip install git+https://github.com/twisted/pydoctor_primer.git
- name: Run pydoctor_primer
shell: bash
run: |
cd pydoctor_to_test
echo "new commit"
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
echo ''
cd ..
# fail action if exit code isn't zero or one
(
pydoctor_primer \
--repo pydoctor_to_test \
--new $GITHUB_SHA --old base_commit \
--debug \
--output concise \
-j 8 \
| tee diff.txt
) || [ $? -eq 1 ]
- 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('diff.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 pydoctor_primer:")
console.log(data)
let body
if (data.trim()) {
body = 'Diff from [pydoctor_primer](https://github.com/tristanlatr/pydoctor_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'
} else {
body = "According to [pydoctor_primer](https://github.com/tristanlatr/pydoctor_primer), this change doesn't affect pydoctor warnings on a corpus of open source code. ✅"
}
const ev = JSON.parse(
fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')
)
const prNumber = ev.pull_request.number
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
return prNumber
- name: Hide old comments
uses: kanga333/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
leave_visible: 1
issue_number: ${{ steps.post-comment.outputs.result }}