Skip to content

feat(ci): add per-integration unit test coverage reporting on PRs#365

Closed
Shubhank-Jonnada wants to merge 3 commits into
masterfrom
feat/unit-test-coverage-reporting
Closed

feat(ci): add per-integration unit test coverage reporting on PRs#365
Shubhank-Jonnada wants to merge 3 commits into
masterfrom
feat/unit-test-coverage-reporting

Conversation

@Shubhank-Jonnada

Copy link
Copy Markdown
Contributor

Summary

  • Adds .github/workflows/coverage.yml that runs on every PR targeting master
  • Detects which integration directories changed and runs coverage only for those (scoped, not full repo)
  • Posts a PR comment per integration showing coverage % with trend vs master baseline (🟢↑ / 🔴↓)
  • Updates .coverage-baselines/ on merge to master so future PRs have a comparison point
  • Uses existing requirements-test.txt which already has pytest-cov — no per-integration changes needed

How it works

  1. Detect — finds changed integration dirs (must have config.json + unit tests)
  2. Matrix job — one job per changed integration, installs deps + runs pytest --cov
  3. Comment — posts/updates a coverage comment on the PR with the result
  4. Baseline — on merge to master, saves coverage JSON to .coverage-baselines/<integration>.json

Test plan

  • Open a PR that touches an integration with unit tests and verify the coverage comment appears
  • Push a new commit to the same PR and verify the comment updates in place (not duplicated)
  • Merge to master and verify .coverage-baselines/ is updated

Adds a coverage.yml workflow that:
- Detects which integration directories changed on a PR
- Runs pytest --cov scoped to each changed integration
- Posts a PR comment with coverage % and trend vs master baseline
- Updates the master baseline on merge via .coverage-baselines/

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a81e6b3d5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +67 to +73
python -m pytest ${{ matrix.integration }}/tests/test_*_unit.py \
--cov=${{ matrix.integration }} \
--cov-report=json:coverage.json \
--cov-report=term-missing \
-m unit \
--tb=short \
-q 2>&1 | tee test_output.txt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve pytest failures through tee

When any unit test fails, this step can still succeed because the workflow uses the unspecified GitHub Actions shell, which runs as bash -e {0} without pipefail; the pipeline therefore returns tee's exit status instead of pytest's. In that scenario the job continues, extracts whatever coverage file exists, and posts a successful coverage comment even though the unit-test command failed.

Useful? React with 👍 / 👎.

Comment on lines +4 to +5
pull_request:
branches: [master, main]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Trigger baseline updates after master merges

With this workflow triggered only by pull_request, the update-baseline job's github.ref_name == 'master' condition is never true for the merge-to-master event; pull_request runs use the PR ref rather than executing after the target branch is updated. As a result .coverage-baselines/ never refreshes on merge, so future PR comments will keep showing no baseline or stale trends.

Useful? React with 👍 / 👎.

Comment on lines +144 to +145
- name: Post coverage comment
uses: actions/github-script@v7

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid posting comments from fork PR runs

For PRs opened from forks that touch an integration, this direct pull_request job attempts to create or update the coverage comment with the downgraded read-only token and will fail the otherwise successful coverage run. The existing validation workflow explicitly avoids direct PR-run commenting for this reason (validate-integration.yml lines 24-28), so coverage comments need the same base-context posting path or a fork-safe guard.

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

🔍 Integration Validation Results

Commit: aa9a0ba63dc3de973e7d71a587435ed65fd9f1c2 · fix(ci): fix python version, pipefail, baseline trigger, fork guard
Updated: 2026-06-11T05:06:34Z

Changed directories: instagram

Check Result
Structure ⚠️ Passed with warnings
Code ✅ Passed
Tests ✅ Passed
README ✅ Passed
Version ✅ Passed
⚠️ Structure Check output
Validating 1 integration(s)...

============================================================
Integration: instagram
============================================================

Warnings (1):
  ⚠️ Integration should use 'Integration.load()' to load the integration

============================================================
SUMMARY
============================================================
Integrations validated: 1
Total errors: 0
Total warnings: 1

⚠️ Validation passed with warnings - please review
✅ Code Check output
----------------------------------------
Checking: instagram
----------------------------------------

📦 Installing dependencies...

🐍 Checking Python syntax...
   ✅ Syntax OK

📥 Checking imports...
   ✅ Imports OK

📄 Checking JSON files...
   ✅ JSON files OK

🔍 Linting with ruff...
   ✅ Lint OK

🎨 Checking formatting with ruff...
   ✅ Formatting OK

🔒 Scanning for security issues with bandit...
   ✅ Security OK

🛡️ Checking dependencies for vulnerabilities with pip-audit...
   ✅ Dependencies OK

🔗 Checking config-code sync...
   ✅ Config-code sync OK

🔄 Checking fetch patterns...
   ✅ Fetch patterns OK

========================================
✅ CODE CHECK PASSED
========================================
✅ Tests Check output

Integration   Tests  Coverage        Status
-------------------------------------------
instagram     57/57       98%      ✅ Passed
-------------------------------------------
Total         57/57            ✅ All passed

✅ Tests passed: instagram
✅ README Check output
========================================
✅ README CHECK PASSED
========================================
✅ Version Check output
✅ instagram: No version bump needed (only tests/docs changed)

========================================
✅ VERSION CHECK PASSED
========================================

@github-actions

Copy link
Copy Markdown

Unit test coverage — instagram

Coverage: 98.3% ⚪ (no baseline yet)

Full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant