diff --git a/.github/pr-agent-context-template.md b/.github/pr-agent-context-template.md new file mode 100644 index 0000000..89a796c --- /dev/null +++ b/.github/pr-agent-context-template.md @@ -0,0 +1,11 @@ +{{ prompt_preamble }} + +{{ opening_instructions }} + +{{ copilot_comments_section }} + +{{ review_comments_section }} + +{{ failing_checks_section }} + +{{ patch_coverage_section }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ead1484..b387d1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,9 @@ jobs: matrix: python-version: ["3.11", "3.12"] + env: + COVERAGE_FILE: .coverage.py${{ matrix.python-version }} + steps: - uses: actions/checkout@v4 @@ -30,13 +33,22 @@ jobs: uv pip install \ pydantic pyyaml jinja2 soundfile numpy scipy \ click rich jsonlines \ - pytest pytest-asyncio + pytest pytest-asyncio pytest-cov - name: Install package run: uv pip install --no-deps -e . - name: Run tests - run: .venv/bin/pytest tests/ -v --tb=short + run: .venv/bin/pytest tests/ -v --tb=short --cov avdp --cov-branch --cov-report= + + - name: Upload raw coverage artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: pr-agent-context-coverage-py${{ matrix.python-version }} + path: .coverage* + include-hidden-files: true + if-no-files-found: ignore lint: name: "Lint & type-check" @@ -66,3 +78,63 @@ jobs: - name: mypy run: .venv/bin/mypy avdp/ --ignore-missing-imports + + coverage: + name: "Combine coverage & generate XML" + runs-on: ubuntu-latest + needs: [test] + if: always() + + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + version: "latest" + enable-cache: true + python-version: "3.11" + + - name: Install coverage + run: uv pip install coverage[toml] + + - name: Download raw coverage artifacts + uses: actions/download-artifact@v4 + with: + pattern: pr-agent-context-coverage-* + path: coverage-data + merge-multiple: true + + - name: Combine coverage and generate XML + run: | + .venv/bin/coverage combine coverage-data/ + .venv/bin/coverage report + .venv/bin/coverage xml + + - name: Upload combined coverage XML + uses: actions/upload-artifact@v4 + with: + name: coverage-xml + path: coverage.xml + if-no-files-found: warn + + pr-agent-context: + name: "PR agent context" + if: ${{ always() && github.event_name == 'pull_request' }} + needs: [lint, test, coverage] + permissions: + contents: read + actions: read + pull-requests: write + uses: shaypal5/pr-agent-context/.github/workflows/pr-agent-context.yml@v4 + with: + tool_ref: v4 + target_patch_coverage: "100" + include_review_comments: true + include_failing_checks: true + include_patch_coverage: true + patch_coverage_source_mode: coverage_xml_artifact + coverage_report_artifact_name: coverage-xml + coverage_report_filename: coverage.xml + prompt_template_file: .github/pr-agent-context-template.md + debug_artifacts: true diff --git a/.github/workflows/pr-agent-context-refresh.yml b/.github/workflows/pr-agent-context-refresh.yml new file mode 100644 index 0000000..7d9a76b --- /dev/null +++ b/.github/workflows/pr-agent-context-refresh.yml @@ -0,0 +1,55 @@ +name: pr-agent-context-refresh + +on: + pull_request_review: + types: [submitted, edited, dismissed] + pull_request_review_comment: + types: [created, edited, deleted] + check_run: + types: [completed] + status: + +concurrency: + group: >- + ${{ github.workflow }}-${{ + github.event.pull_request.number || + github.event.pull_request_review.pull_request.number || + github.event.pull_request_review_comment.pull_request.number || + github.event.check_run.head_sha || + github.event.sha || + github.sha + }} + cancel-in-progress: true + +jobs: + pr-agent-context-refresh: + name: "PR agent context refresh" + if: >- + github.event_name == 'pull_request_review' || + github.event_name == 'pull_request_review_comment' || + (github.event_name == 'check_run' && + github.event.action == 'completed' && + toJson(github.event.check_run.pull_requests) != '[]') || + (github.event_name == 'status' && github.event.state != 'pending') + permissions: + contents: read + actions: read + pull-requests: write + uses: shaypal5/pr-agent-context/.github/workflows/pr-agent-context.yml@v4 + with: + tool_ref: v4 + execution_mode: refresh + publish_mode: append + publish_all_clear_comments_in_refresh: false + wait_for_reviews_to_settle: true + target_patch_coverage: "100" + include_review_comments: true + include_failing_checks: true + include_patch_coverage: true + patch_coverage_source_mode: coverage_xml_artifact + coverage_report_artifact_name: coverage-xml + coverage_report_filename: coverage.xml + enable_cross_run_coverage_lookup: true + coverage_source_workflows: CI + prompt_template_file: .github/pr-agent-context-template.md + debug_artifacts: true diff --git a/pyproject.toml b/pyproject.toml index 5bcfe0a..0f898f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,3 +84,20 @@ ignore_missing_imports = true [tool.pytest.ini_options] testpaths = ["tests"] asyncio_mode = "auto" + +[tool.coverage.run] +source = ["avdp"] +branch = true +relative_files = true + +[tool.coverage.paths] +source = [ + "avdp", + "/home/runner/work/*/*/avdp", +] + +[tool.coverage.report] +show_missing = true + +[tool.coverage.xml] +output = "coverage.xml"