← 输入框|github.com|刷新
Skip to content

fix(hvcs-gitea): raise AssetUploadError when release asset uploads fail - #1516

Open
qianeric-backup wants to merge 1 commit into
python-semantic-release:masterfrom
qianeric-backup:fix/gitea-asset-upload-error
Open

qianeric-backup wants to merge 1 commit into
python-semantic-release:masterfrom
qianeric-backup:fix/gitea-asset-upload-error

Conversation

@qianeric-backup

Copy link
Copy Markdown

Purpose

Gitea.upload_dists() reports success when every asset upload failed.

except HTTPError: logs the failure and moves on, so the returned count is just "how many worked". When all of them fail it returns 0, publish_distributions() ignores the count, and semantic-release publish exits 0. CI reads that as a successful release while nothing was attached to it.

# every asset upload answers 500
$ semantic-release publish
...
Uploading distributions to release
error uploading asset dist/demo_pkg-0.1.0.tar.gz
semantic-release completed successfully.
$ echo $?
0

Rationale

GitHub.upload_dists() does the same job and gets it right. The two methods are otherwise line-for-line the same, so diff -u of github.py:458-486 against gitea.py:318-335 has exactly one functional difference, and it is this one: GitHub collects the failed (file, status) pairs and ends with

        if errors:
            raise AssetUploadError("\n".join(errors))

gitea.py already imports AssetUploadError (line 16) and already raises it on the analogous path in Gitea.create_release():

            except HTTPError:
                raise IncompleteReleaseError("Failed to upload asset(s) to release!")

so the swallow looks like an omission rather than a deliberate choice. semantic-release/cli/commands/publish.py:101 already handles it:

    except AssetUploadError as err:
        click.echo(err, err=True)
        ctx.exit(1)

The change copies the GitHub body verbatim, which also means a partial failure now reports which assets failed and with what status instead of silently attaching some of them:

$ semantic-release publish
Failed to upload asset 'dist/demo_pkg-0.1.0.tar.gz' to release (HTTP 500)
$ echo $?
1

Nothing about a successful upload changes — n_succeeded is still returned, and a release that doesn't exist still logs the warning and returns 0, matching the other backend.

How did you test?

New tests in tests/unit/semantic_release/hvcs/test_gitea.py: test_upload_dists_fails_with_http_error (parametrized over 429/500/503 — all assets fail, AssetUploadError raised, message names the file and the status) and test_upload_dists_partial_failure (one success, one failure — still raises, and the count is not reported as success).

  • Red, on master with only the tests added: 8 failed, 23 passed
  • Green, with the change: 31 passed
  • Whole unit suite: 4293 passed, 1 failed before and after; comm -3 of the FAILED lines differs only by the new test ids. The one pre-existing failure is test_toml_declaration_from_definition[Default number format for project.version], a local tomlkit version difference, present on both trees.
  • Seven valid calls (successful upload, missing release, empty glob, --noop, the four URL builders, owner/repo parsing) produce byte-identical output before and after.
  • ruff==0.6.1 (the pin in uv.lock): ruff check and ruff format --check clean, on both trees.

No AI assistance was used to write the tests' expectations; the assertions were read off the existing test_github.py equivalents so the two backends are checked the same way.

Gitea.upload_dists() logs an HTTPError and moves on, so when every asset
fails to upload it returns 0 and `semantic-release publish` exits 0 -- a
release with nothing attached reports as successful.

GitHub.upload_dists() does the same job and collects the failures into an
AssetUploadError, which publish.py already turns into a non-zero exit.
This copies that body, so the two backends behave the same.
@qianeric-backup
qianeric-backup marked this pull request as ready for review November 27, 2026 06:36

This branch has not been deployed

No deployments
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