| 1 |
name: Run pydoctor_primer |
| 2 |
|
| 3 |
on: |
| 4 |
# Only run on PR, since we diff against master |
| 5 |
pull_request: |
| 6 |
paths-ignore: |
| 7 |
- 'pydoctor/test/**' |
| 8 |
- 'docs/**' |
| 9 |
- '*.rst' |
| 10 |
- '*.txt' |
| 11 |
- '*.in' |
| 12 |
- '*.md' |
| 13 |
- '.*' |
| 14 |
- 'setup.py' |
| 15 |
|
| 16 |
|
| 17 |
jobs: |
| 18 |
pydoctor_primer: |
| 19 |
name: Run pydoctor_primer |
| 20 |
runs-on: ubuntu-latest |
| 21 |
permissions: |
| 22 |
contents: read |
| 23 |
pull-requests: write |
| 24 |
steps: |
| 25 |
- uses: actions/checkout@v4 |
| 26 |
with: |
| 27 |
path: pydoctor_to_test |
| 28 |
fetch-depth: 0 |
| 29 |
- uses: actions/setup-python@v5 |
| 30 |
with: |
| 31 |
python-version: "3.12" |
| 32 |
- name: Install pydoctor_primer |
| 33 |
run: | |
| 34 |
python -m pip install -U pip |
| 35 |
pip install git+https://github.com/twisted/pydoctor_primer.git |
| 36 |
- name: Run pydoctor_primer |
| 37 |
shell: bash |
| 38 |
run: | |
| 39 |
cd pydoctor_to_test |
| 40 |
echo "new commit" |
| 41 |
git rev-list --format=%s --max-count=1 $GITHUB_SHA |
| 42 |
|
| 43 |
MERGE_BASE=$(git merge-base $GITHUB_SHA origin/$GITHUB_BASE_REF) |
| 44 |
git checkout -b base_commit $MERGE_BASE |
| 45 |
echo "base commit" |
| 46 |
git rev-list --format=%s --max-count=1 base_commit |
| 47 |
|
| 48 |
echo '' |
| 49 |
cd .. |
| 50 |
# fail action if exit code isn't zero or one |
| 51 |
( |
| 52 |
pydoctor_primer \ |
| 53 |
--repo pydoctor_to_test \ |
| 54 |
--new $GITHUB_SHA --old base_commit \ |
| 55 |
--debug \ |
| 56 |
--output concise \ |
| 57 |
-j 8 \ |
| 58 |
| tee diff.txt |
| 59 |
) || [ $? -eq 1 ] |
| 60 |
|
| 61 |
- name: Post comment |
| 62 |
id: post-comment |
| 63 |
uses: actions/github-script@v6 |
| 64 |
with: |
| 65 |
github-token: ${{ secrets.GITHUB_TOKEN }} |
| 66 |
script: | |
| 67 |
const MAX_CHARACTERS = 30000 |
| 68 |
const MAX_CHARACTERS_PER_PROJECT = MAX_CHARACTERS / 3 |
| 69 |
|
| 70 |
const fs = require('fs') |
| 71 |
let data = fs.readFileSync('diff.txt', { encoding: 'utf8' }) |
| 72 |
|
| 73 |
function truncateIfNeeded(original, maxLength) { |
| 74 |
if (original.length <= maxLength) { |
| 75 |
return original |
| 76 |
} |
| 77 |
let truncated = original.substring(0, maxLength) |
| 78 |
// further, remove last line that might be truncated |
| 79 |
truncated = truncated.substring(0, truncated.lastIndexOf('\n')) |
| 80 |
let lines_truncated = original.split('\n').length - truncated.split('\n').length |
| 81 |
return `${truncated}\n\n... (truncated ${lines_truncated} lines) ...` |
| 82 |
} |
| 83 |
|
| 84 |
const projects = data.split('\n\n') |
| 85 |
// don't let one project dominate |
| 86 |
data = projects.map(project => truncateIfNeeded(project, MAX_CHARACTERS_PER_PROJECT)).join('\n\n') |
| 87 |
// posting comment fails if too long, so truncate |
| 88 |
data = truncateIfNeeded(data, MAX_CHARACTERS) |
| 89 |
|
| 90 |
console.log("Diff from pydoctor_primer:") |
| 91 |
console.log(data) |
| 92 |
|
| 93 |
let body |
| 94 |
if (data.trim()) { |
| 95 |
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 + '```' |
| 96 |
} else { |
| 97 |
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. ✅" |
| 98 |
} |
| 99 |
const ev = JSON.parse( |
| 100 |
fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8') |
| 101 |
) |
| 102 |
const prNumber = ev.pull_request.number |
| 103 |
|
| 104 |
await github.rest.issues.createComment({ |
| 105 |
issue_number: prNumber, |
| 106 |
owner: context.repo.owner, |
| 107 |
repo: context.repo.repo, |
| 108 |
body |
| 109 |
}) |
| 110 |
return prNumber |
| 111 |
|
| 112 |
- name: Hide old comments |
| 113 |
uses: kanga333/[email protected] |
| 114 |
with: |
| 115 |
github_token: ${{ secrets.GITHUB_TOKEN }} |
| 116 |
leave_visible: 1 |
| 117 |
issue_number: ${{ steps.post-comment.outputs.result }} |