Drop python 3.8 #347
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |