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
132 changes: 132 additions & 0 deletions .github/workflows/pyreverse_primer_comment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Pyreverse Primer / Comment

on:
workflow_run:
workflows: [Pyreverse Primer / Run]
types:
- completed

env:
CACHE_VERSION: 1
KEY_PREFIX: venv-pyreverse-primer
DEFAULT_PYTHON: "3.13"
COMMENT_MARKER: "<!-- pyreverse-primer-comment -->"

permissions:
contents: read
pull-requests: write

jobs:
primer-comment:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: Run
runs-on: ubuntu-latest
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml',
'requirements_test.txt', 'requirements_test_min.txt',
'requirements_test_pre_commit.txt') }}
- name: Download outputs
id: download-outputs
uses: actions/[email protected]
with:
script: |
const fs = require('fs');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const wantedNames = new Set([
'pyreverse_primer_output_main',
'pyreverse_primer_output_pr',
'pr_number',
]);
const wanted = artifacts.data.artifacts.filter((artifact) => wantedNames.has(artifact.name));
core.setOutput('found', wanted.length === wantedNames.size ? 'true' : 'false');
for (const artifact of wanted) {
const downloaded = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
fs.writeFileSync(`${artifact.name}.zip`, Buffer.from(downloaded.data));
}
- name: Unzip outputs
if: steps.download-outputs.outputs.found == 'true'
run: |
unzip pyreverse_primer_output_main.zip
unzip pyreverse_primer_output_pr.zip
unzip pr_number.zip
- name: Check label state
id: check-label
if: steps.download-outputs.outputs.found == 'true'
uses: actions/[email protected]
with:
script: |
const fs = require('fs');
const prNumber = parseInt(fs.readFileSync('pr_number.txt', { encoding: 'utf8' }));
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const hasLabel = pr.data.labels.some((label) => label.name === 'pyreverse');
core.setOutput('has-label', hasLabel ? 'true' : 'false');
core.setOutput('pr-number', `${prNumber}`);
- name: Compare outputs
if: steps.check-label.outputs.has-label == 'true'
run: |
. venv/bin/activate
python tests/primer/pyreverse_primer.py compare \
--commit=${{ github.event.workflow_run.head_sha }} \
--base-file=pyreverse_output_${{ env.DEFAULT_PYTHON }}_main.txt \
--new-file=pyreverse_output_${{ env.DEFAULT_PYTHON }}_pr.txt
- name: Create or update comment
if: steps.check-label.outputs.has-label == 'true'
uses: actions/[email protected]
with:
script: |
const fs = require('fs');
const comment = fs.readFileSync('tests/.pyreverse_primer_tests/comment.txt', { encoding: 'utf8' });
const prNumber = parseInt(fs.readFileSync('pr_number.txt', { encoding: 'utf8' }));
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
const existing = comments.data.find((candidate) =>
candidate.body && candidate.body.includes(process.env.COMMENT_MARKER)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: comment,
});
return existing.id;
}
const created = await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
});
return created.data.id;
116 changes: 116 additions & 0 deletions .github/workflows/pyreverse_primer_run_main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Pyreverse Primer / Main

on:
push:
branches:
- main
paths:
- "pylint/pyreverse/**"
- "pylint/testutils/_primer/**"
- "tests/primer/packages_to_prime.json"
- "tests/primer/pyreverse_primer.py"
- "tests/primer/pyreverse_targets_to_prime.json"
- "tests/primer/test_primer_stdlib.py"
- "tests/pyreverse/**"
- "requirements*"
- ".github/workflows/pyreverse_primer*.yaml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CACHE_VERSION: 1
KEY_PREFIX: venv-pyreverse-primer
DEFAULT_PYTHON: "3.13"

permissions:
contents: read

jobs:
run-primer:
name: Run
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
check-latest: true
- name: Restore Python virtual environment cache
id: cache-venv
uses: actions/cache/[email protected]
with:
path: venv
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml',
'requirements_test.txt', 'requirements_test_min.txt',
'requirements_test_pre_commit.txt') }}
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip
pip install --upgrade --requirement requirements_test.txt
- name: Save Python virtual environment to cache
if: steps.cache-venv.outputs.cache-hit != 'true'
uses: actions/cache/[email protected]
with:
path: venv
key: >-
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml',
'requirements_test.txt', 'requirements_test_min.txt',
'requirements_test_pre_commit.txt') }}
- name: Get commit string
id: commitstring
run: |
. venv/bin/activate
python tests/primer/pyreverse_primer.py prepare --make-commit-string
output=$(python tests/primer/pyreverse_primer.py prepare --read-commit-string)
echo "commitstring=$output" >> $GITHUB_OUTPUT
- name: Restore projects cache
id: cache-projects
uses: actions/cache/[email protected]
with:
path: tests/.pylint_primer_tests/
key: >-
${{ runner.os }}-${{ env.DEFAULT_PYTHON }}-${{
steps.commitstring.outputs.commitstring }}-pyreverse-primer
- name: Regenerate cache
if: steps.cache-projects.outputs.cache-hit != 'true'
run: |
. venv/bin/activate
python tests/primer/pyreverse_primer.py prepare --clone
- name: Save projects cache
if: steps.cache-projects.outputs.cache-hit != 'true'
uses: actions/cache/[email protected]
with:
path: tests/.pylint_primer_tests/
key: >-
${{ runner.os }}-${{ env.DEFAULT_PYTHON }}-${{
steps.commitstring.outputs.commitstring }}-pyreverse-primer
- name: Upload commit string
uses: actions/[email protected]
with:
name: pyreverse_primer_commitstring
path:
tests/.pyreverse_primer_tests/commit_string_${{ env.DEFAULT_PYTHON }}.txt
- name: Run pyreverse primer
run: |
. venv/bin/activate
pip install . --no-deps
python tests/primer/pyreverse_primer.py run --type=main
- name: Upload output
uses: actions/[email protected]
with:
name: pyreverse_primer_output_main
path:
tests/.pyreverse_primer_tests/pyreverse_output_${{ env.DEFAULT_PYTHON
}}_main.txt
Loading
Loading