Refactor upload logic into testable Python script#7
Open
joshhale wants to merge 2 commits into
Open
Conversation
Move the upload logic (file validation, gzip/base64 encoding, payload construction, HTTP request, error handling) out of action.yml into upload_coverage.py. The action.yml is now a minimal harness that resolves GitHub context (event type, commit SHA, ref, PR number) and calls the script. This makes the behaviour testable without running the action. The test suite covers: file not found, successful upload (201), PR-based vs ref-based payloads, 403 permissions errors, 403 other, 400, 500, network errors, missing ref/PR number, and payload encoding correctness. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Run unit tests | ||
| run: python3 -m unittest test_upload_coverage.py -v |
cassiomarques
approved these changes
May 21, 2026
cassiomarques
approved these changes
May 21, 2026
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.
Summary
Extracts the upload logic from inline bash in
action.ymlinto a standalone Python script (upload_coverage.py) so that the behaviour can be unit tested without running the action.Changes
upload_coverage.py: Handles file validation, gzip/base64 encoding, JSON payload construction, HTTP PUT request, and error handling with Actions annotations. Uses only Python stdlib.action.yml: Now a minimal harness that resolves GitHub context (merge queue skip, fork PR skip, commit SHA, ref, PR number) and delegates to the Python script.test_upload_coverage.py: 11 unit tests covering every response code and input configuration (file not found, 201 success, PR-based payload, ref-based payload, missing ref+PR, 403 permissions, 403 other, 400, 500, network error, payload encoding)..github/workflows/ci.yml: Runs the unit tests on push to main and on PRs..gitignore: Ignores__pycache__/.Motivation
Per discussion in Slack, the inline bash in
action.ymlwas getting complex and difficult to test. Moving logic into a script makes it possible to regression-test API response handling without deploying the action.