Repository navigation
Conversation
When GitHub returns HTTP 422 with an already_exists error code on asset upload, log a warning and return False instead of raising HTTPError so publish skips existing assets while still failing on other 422 errors. Resolves: python-semantic-release#729
This branch has not been deployed
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.
Purpose
Prevent
semantic-release publish(and GitHub release asset uploads) from failing when an asset with the same filename has already been uploaded to the target GitHub release.Rationale
When
semantic-release publishruns on a branch where the latest version tag and release assets have already been published (for example, aftersemantic-release versionreports that no new release will be made), GitHub'sPOST /repos/{owner}/{repo}/releases/{release_id}/assetsendpoint responds with422 Unprocessable Entityand a structured validation payload containingerrors[*].code == "already_exists". BecauseGithub.sessionregisters araise_for_status()response hook,self.session.post(...)raisedHTTPErrorandGithub.upload_dists()failed withAssetUploadError.To handle already-published assets safely without masking genuine upload failures:
_is_asset_already_exists_error(err: HTTPError) -> boolinsrc/semantic_release/hvcs/github.pyto match HTTP422responses whose JSONerrorslist contains an entry with"code": "already_exists".Github.upload_release_asset()to catchHTTPErroraround the uploadPOST, log a warning (Asset '<name>' already exists on release <id>, skipping upload), and returnFalsewhen_is_asset_already_exists_error()matches, while re-raisingHTTPErrorfor all other errors.Github.upload_dists()to incrementn_succeededonly whenself.upload_release_asset()returnsTrue, allowing any remaining new distribution files indist_globto still be uploaded.Skipping (rather than deleting and re-uploading) avoids overwriting artifacts built from the original tagged commit and remains compatible with GitHub's immutable releases setting. Narrowly matching
errors[*].code == "already_exists"ensures other422errors—such as"Cannot upload assets to an immutable release"(#1478), other validation failures, or non-JSON422responses—still raiseHTTPError/AssetUploadErrorand exit non-zero.How did you test?
tests/e2e/cmd_publish/test_publish.py):test_publish_succeeds_when_github_asset_already_exists: verifiessemantic-release publish --tag latestlogs a warning for an asset returning HTTP422withcode == "already_exists", continues uploading remaining distribution files, and exits with code0.test_publish_fails_on_github_non_duplicate_422: verifiessemantic-release publish --tag lateststill fails with exit code1when GitHub returns HTTP422withoutalready_exists(e.g., an immutable release response).tests/unit/semantic_release/hvcs/test_github.py):test_upload_release_asset_skips_when_already_exists: verifiesGithub.upload_release_asset()returnsFalseand emits a warning log when GitHub returns422withalready_exists.test_upload_release_asset_fails_on_other_422_errors: verifiesGithub.upload_release_asset()re-raisesHTTPErroracross immutable-release JSON, other validation error codes, non-dict JSON, and plain-text422responses.test_upload_dists_when_release_id_found: verifiesGithub.upload_dists()returns the count of newly uploaded assets whenupload_release_asset()returns[False, True]or[False, False].How to Verify
test(cmd-publish)) and run:test_publish_succeeds_when_github_asset_already_existsfails with exit code1(AssetUploadError ... (HTTP 422)).PR Completion Checklist
Reviewed & followed the Contributor Guidelines
Changes Implemented & Validation pipeline succeeds
Commits follow the Conventional Commits standard
and are separated into the proper commit type and scope (recommended order: test, build, feat/fix, docs)
Appropriate Unit tests added/updated
Appropriate End-to-End tests added/updated
Appropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)