feat(cli): add codecarbon ci-report - #1364
Open
davidberenstein1957 wants to merge 2 commits into
Open
Conversation
Summarise an emissions.csv for CI pipelines: aggregate the rows of the most recent run, optionally diff against a baseline CSV, render markdown or JSON, and exit non-zero above an optional threshold. CI-agnostic on purpose, so GitLab, Jenkins and Buildkite get it too. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1364 +/- ##
==========================================
+ Coverage 91.39% 91.56% +0.16%
==========================================
Files 49 50 +1
Lines 5056 5134 +78
==========================================
+ Hits 4621 4701 +80
+ Misses 435 433 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
FileOutput.out() discards the delta it is handed and writes the running total, so summing the rows of a run double-counts: a run flushing twice before stopping was reported at 2.9x its real emissions and its duration was the sum of the elapsed times. Take the last row of the last run_id instead, and rebuild the test fixture from a CSV a real run produced. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
davidberenstein1957
marked this pull request as ready for review
August 12, 2026 19:14
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
A new CLI command,
codecarbon ci-report, that turns theemissions.csva CI job leaves behind into something the pipeline can actually show or gate on. It reads the rows of the most recent run (CodeCarbon appends one delta row per flush, all sharing arun_id, so those rows are summed), optionally diffs against a baseline CSV from the target branch, and prints markdown or JSON.Nothing here is specific to a CI provider — GitLab, Jenkins and Buildkite get it for free alongside GitHub Actions.
User-facing surface
--csv PATHemissions.csv--baseline PATH--format markdown|jsonmarkdown--label TEXT--threshold-kg FLOATOn GitHub Actions the markdown goes straight to a job summary with no token and no extra permissions:
Implementation is
codecarbon/cli/ci_report.py(stdlibcsv, no new dependency and no new extra) plus the Typer command registered next tomonitoranddetect. Docs go indocs/reference/cli.mdalongside the other commands, including an explicit caveat that hosted runners have no RAPL and fall back to the CPU-model TDP estimate, so values are comparable between identical runners rather than absolute.How it was verified
uv run pytest tests/cli tests/test_docs_examples.py tests/test_package_integrity.py -q— 94 passed, 13 of them the newtests/cli/test_cli_ci_report.py, covering multi-row aggregation byrun_id, positive/negative/zero deltas, a zero baseline (noZeroDivisionError), a missing baseline, missing/empty/foreign CSVs exiting cleanly without a traceback, JSON keys, and both sides of the threshold.black --checkandruff checkwere run scoped to the touched files; the remaining ruff findings are pre-existing repo-wide style rules (Optional[...], blindexcept Exception) that the surrounding code already follows.Deliberately left out
The composite GitHub Action, PR-comment posting, and base-branch artifact download. Those are thin wrappers over this command and carry CI-specific maintenance (token permissions, fork-PR degradation, floating tag policy, marketplace packaging) that shouldn't gate the portable half. A job summary already covers the useful case with no permissions at all. Happy to follow up with the action once this command has settled.
Closes #1351
🤖 Generated with Claude Code