Skip to content

Add upload diagnostics and fail-on-error option#6

Merged
joshhale merged 5 commits into
mainfrom
joshhale/improve-upload-diagnostics
May 22, 2026
Merged

Add upload diagnostics and fail-on-error option#6
joshhale merged 5 commits into
mainfrom
joshhale/improve-upload-diagnostics

Conversation

@joshhale
Copy link
Copy Markdown
Collaborator

@joshhale joshhale commented May 18, 2026

Summary

Adds detailed diagnostic output and a fail-on-error option to the upload action, integrated into the upload_coverage.py script framework introduced in PR #7.

Changes

upload_coverage.py

  • Diagnostic logging: Logs upload parameters (commit SHA, ref, PR number, language, label, file path and size) in a collapsed ::group:: block before uploading.
  • Response handling: Distinguishes between all API response codes:
    • 201: Success message logged.
    • 200: Emits a ::warning:: with the API message (typically "commit is not the latest on branch").
    • 403 "not authorized": Emits a ::error:: with permissions guidance.
    • Other 4xx/5xx: Emits a ::error:: with status code and response body.
    • Network failure: Emits a ::error:: indicating the API was unreachable.
    • All error annotations include a hint about the fail-on-error: false option.
  • fail-on-error support: Reads FAIL_ON_ERROR from the environment. When "false", upload failures (4xx, 5xx, network errors) exit 0 instead of 1. Local configuration errors (missing file, missing ref+PR) always exit 1 regardless of this setting.

action.yml

  • Adds fail-on-error input (default: true).
  • Passes FAIL_ON_ERROR env var to the Python script.

test_upload_coverage.py

Expanded from 11 to 29 unit tests covering:

  • HTTP 201 success with log message
  • HTTP 200 with message, without message, and with invalid JSON
  • HTTP 403 (permissions vs. other)
  • HTTP 400 and 500 with status and body in output
  • Network errors (URLError)
  • Unexpected status codes (e.g. 202)
  • fail-on-error: true exits 1 on 4xx, 5xx, and network errors
  • fail-on-error: false exits 0 on 4xx, 5xx, and network errors
  • fail-on-error: false still exits 1 on config errors (missing file, missing ref+PR)
  • All error annotations include the fail-on-error hint
  • Diagnostic parameter logging (group block contents)
  • Payload structure and encoding

README.md

Documents the fail-on-error input, error handling behavior, and permissions requirements.

Backward compatibility

The default behavior is unchanged: the action exits 1 on upload failures. The new fail-on-error: false input provides an opt-out for workflows where coverage upload is best-effort.

Copilot AI review requested due to automatic review settings May 18, 2026 14:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves diagnostics for the code coverage upload step by surfacing upload parameters in a collapsed log group and reporting the HTTP status code (including differentiating 201 stored vs 200 accepted-but-not-stored) along with the response body to aid troubleshooting.

Changes:

  • Log key upload parameters in a grouped section to keep workflow logs readable.
  • Capture and report the HTTP status code and response body from the upload API call.
  • Emit warnings/notices for non-201 outcomes to make “green but no report” scenarios easier to diagnose.
Show a summary per file
File Description
action.yml Adds grouped parameter logging and expands upload handling to parse/report HTTP status and response body.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread action.yml Outdated
Comment thread action.yml Outdated
@joshhale joshhale force-pushed the joshhale/improve-upload-diagnostics branch from 90e0795 to 4681ec5 Compare May 18, 2026 14:25
@joshhale joshhale changed the title Improve upload diagnostics in workflow logs Add upload diagnostics and fail-on-error option May 18, 2026
Surface the HTTP status code and response body in the action output so
that users can distinguish between a true 201 (report stored) and a 200
(report silently rejected, e.g. commit not latest on branch). Parameters
are logged in a collapsed group to avoid noise.

Add a fail-on-error input (default: false) so that upload failures do
not break existing workflows. Users who want strict behaviour can opt in.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshhale joshhale force-pushed the joshhale/improve-upload-diagnostics branch from 4681ec5 to 6d6f740 Compare May 18, 2026 15:27
@joshhale
Copy link
Copy Markdown
Collaborator Author

joshhale commented May 18, 2026

Testing the fail-on-error behaviour

First, against the current version of upload-code-coverage I verified that a 4xx upload failure causes the action run to fail:

https://github.com/joshhale/code-coverage-test/actions/runs/26042852804/job/76558955955?pr=1

image

Same behaviour when fail-on-error: true is set: https://github.com/joshhale/code-coverage-test/actions/runs/26043212473/job/76560259021

When fail-on-error: true is removed and we default to false the workflow passes, although it still logs the error (as intended):

image

https://github.com/joshhale/code-coverage-test/actions/runs/26043964721/job/76562969572?pr=1

Testing the logging

We see the upload parameters in the log. On 200 we get a warning that no action was taken:

image

No warning on 201:

image

Strip carriage returns before splitting headers from body so that
the blank-line separator is matched correctly on responses with
CRLF line endings from gh api --include.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshhale
Copy link
Copy Markdown
Collaborator Author

Retesting after tweaks

Success case:

image

200 case:

image

The previous default of false silently swallowed upload errors, which is
a change from the original behaviour where the action exited 1 on API
errors. Default to true so workflows fail visibly on upload errors, and
mention the opt-out in error messages and the README.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cassiomarques
cassiomarques previously approved these changes May 21, 2026
Resolve conflicts after PR #7 (refactor to Python script) merged to
main. The upload logic now lives in upload_coverage.py rather than
inline bash in action.yml.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshhale
Copy link
Copy Markdown
Collaborator Author

This has been refactored after switching to a python script for the bulk of the behaviour.

I've therefore done some retesting.

This workflow run illustrates the case when we upload coverage for not-the-latest-commit:

image

And this workflow run tests when we upload coverage for the latest commit:

image

@joshhale
Copy link
Copy Markdown
Collaborator Author

joshhale commented May 22, 2026

This workflow run tests the case where CQ is not enabled and we didn't use the fail-on-error setting:

image

The workflow failed (as expected).

@joshhale
Copy link
Copy Markdown
Collaborator Author

joshhale commented May 22, 2026

This workflow run tests the case where CQ is not enabled but we set fail-on-error: false:

image

The workflow succeeded (as expected).

@cassiomarques
Copy link
Copy Markdown

@joshhale Should we already have docs at https://docs.github.com/rest/code-quality/code-coverage or is the URL shown in the workflow runs just a placeholder for now? When I visit that URL I get 404.

@joshhale
Copy link
Copy Markdown
Collaborator Author

joshhale commented May 22, 2026

Should we already have docs at https://docs.github.com/rest/code-quality/code-coverage or is the URL shown in the workflow runs just a placeholder for now? When I visit that URL I get 404.

Good spot. We expect to add that for GA, so I better not include it yet.

https://github.com/github/code-scanning/issues/23011

The API response includes a documentation_url field that currently
404s since docs are not yet published. Extract just the message field
for display. Added TODO comments to restore it for GA.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@joshhale joshhale merged commit b51da2c into main May 22, 2026
1 check passed
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.

3 participants