python-semantic-release / python-semantic-release

Automating Releases via SemVer and Commit Message Conventions
https://python-semantic-release.readthedocs.io
MIT License
822 stars 248 forks source link

Semantic-released error on already released assets #729

Open zckv opened 1 year ago

zckv commented 1 year ago

The problem

An error is produced on publish command when the asset is already in the release. This error is on github.py:263, and is not critical. The program still return 0 as a status code.

The error happen because the return code is 422 on POST request on existing asset: https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#list-release-assets

To reproduce, use python-semantic-release/upload-to-gh-release@main or semantic-release publish on a release where the assets are already in the GitHub release. The problem can happen naturally with a commit that doesn't trigger a new version, where "No release will be made, VERSION has already been released!" message is displayed after semantic-release version

Expected behavior

There are two possible behavior, as the conflict isn't yet documented in the documentation nor in the code:

I lean toward the second option. I think that a release should contain only the assets built on the tagged version. And it is easier to do.

Logs

From this job output: https://github.com/zckv/semantic-versioning-example/actions/runs/6394206017/job/17355099525

Run python-semantic-release/upload-to-gh-release@main
  with:
    github_token: ***
    tag: v0.7.1-rc.1
    root_options: -vv
    directory: .
  env:
    GH_TOKEN: ***
/usr/bin/docker run --name bb3a12d5905664366928da1b2d596e686_d54e32 --label 94351b --workdir /github/workspace --rm -e "GH_TOKEN" -e "INPUT_GITHUB_TOKEN" -e "INPUT_TAG" -e "INPUT_ROOT_OPTIONS" -e "INPUT_DIRECTORY" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e "ACTIONS_ID_TOKEN_REQUEST_URL" -e "ACTIONS_ID_TOKEN_REQUEST_TOKEN" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/semantic-versioning-example/semantic-versioning-example":"/github/workspace" 94351b:b3a12d5905664366928da1b2d596e686
[14:13:21] DEBUG    [semantic_release.cli.commands.main] DEBUG       main.py:104
                    main.main: logging level set to: DEBUG                      
           DEBUG    [semantic_release.cli.commands.main] DEBUG       main.py:122
                    main.main: global cli options:                              
                    GlobalCommandLineOptions(noop=False,                        
                    verbosity=2, config_file='pyproject.toml',                  
                    strict=False)                                               
           INFO     [semantic_release.cli.util] INFO                  util.py:78
                    util.load_raw_config_file: Loading configuration            
                    from pyproject.toml                                         
           DEBUG    [semantic_release.cli.util] DEBUG                 util.py:81
                    util.load_raw_config_file: Trying to parse                  
                    configuration pyproject.toml in TOML format                 
           DEBUG    [semantic_release.cli.config] DEBUG            config.py:235
                    config.select_branch_options: Rejecting group               
                    'main' as '(main|master)' doesn't match                     
                    '2-publish-error-on-existing-asset-when-upload              
                    ing'                                                        
           DEBUG    [semantic_release.cli.config] DEBUG            config.py:235
                    config.select_branch_options: Rejecting group               
                    'dev' as 'dev*' doesn't match                               
                    '2-publish-error-on-existing-asset-when-upload              
                    ing'                                                        
           INFO     [semantic_release.cli.config] INFO             config.py:228
                    config.select_branch_options: Using group                   
                    'publish' options, as                                       
                    '2-publish-error-on-existing-asset-when-upload              
                    ing' matches                                                
                    '2-publish-error-on-existing-asset-when-upload              
                    ing'                                                        
           DEBUG    [semantic_release.hvcs.util] DEBUG                util.py:48
                    util.build_requests_session: setting up default             
                    session authentication                                      
           DEBUG    [semantic_release.changelog.template] DEBUG   template.py:55
                    template.environment: {'template_dir':                      
                    'templates', 'block_start_string': '{%',                    
                    'block_end_string': '%}',                                   
                    'variable_start_string': '{{',                              
                    'variable_end_string': '}}',                                
                    'comment_start_string': '{#',                               
                    'comment_end_string': '#}',                                 
                    'line_statement_prefix': None,                              
                    'line_comment_prefix': None, 'trim_blocks':                 
                    False, 'lstrip_blocks': False,                              
                    'newline_sequence': '\n',                                   
                    'keep_trailing_newline': False, 'extensions':               
                    (), 'autoescape': True, 'autoescape_value':                 
                    True}                                                       
           DEBUG    [semantic_release.version.translator] DEBUG translator.py:40
                    translator._invert_tag_format_to_re:                        
                    inverted tag_format 'v{version}' to                         
                    'v(?P<version>.*)'                                          
           DEBUG    [semantic_release.cli.masking_filter]   masking_filter.py:30
                    DEBUG masking_filter.add_mask_for:                          
                    Adding redact pattern                                       
                    'context.hvcs_client.token' to                              
                    _redact_patterns                                            
           DEBUG    [semantic_release.cli.masking_filter]   masking_filter.py:30
                    DEBUG masking_filter.add_mask_for:                          
                    Adding redact pattern                                       
                    'context.hvcs_client.token' to                              
                    _redact_patterns                                            
           INFO     [semantic_release.cli.commands.publish] INFO   publish.py:48
                    publish.publish: Uploading distributions to                 
                    release                                                     
           DEBUG    [semantic_release.hvcs.github] DEBUG           helpers.py:44
                    helpers._wrapper:                                           
                    upload_dists(<semantic_release.hvcs.github.Git              
                    hub object at 0x7f980dc42530>,                              
                    tag='v0.7.1-rc.1', dist_glob='dist/*')                      
           DEBUG    [semantic_release.hvcs.github] DEBUG           helpers.py:44
                    helpers._wrapper:                                           
                    get_release_id_by_tag(<semantic_release.hvcs.g              
                    ithub.Github object at 0x7f980dc42530>,                     
                    tag='v0.7.1-rc.1')                                          
           DEBUG    [semantic_release.hvcs.github] DEBUG            github.py:73
                    github._get_repository_owner_and_name: getting              
                    repository owner and name from environment                  
                    variables                                                   
           DEBUG    [urllib3.connectionpool] DEBUG        connectionpool.py:1048
                    connectionpool._new_conn: Starting                          
                    new HTTPS connection (1):                                   
                    api.github.com:443                                          
           DEBUG    [urllib3.connectionpool] DEBUG         connectionpool.py:546
                    connectionpool._make_request:                               
                    https://api.github.com:443 "GET                             
                    /repos/zckv/semantic-versioning-exampl                      
                    e/releases/tags/v0.7.1-rc.1 HTTP/1.1"                       
                    200 None                                                    
[14:13:22] DEBUG    [semantic_release.hvcs.github] DEBUG           helpers.py:55
                    helpers._wrapper: Github.get_release_id_by_tag              
                    -> 123507536                                                
           DEBUG    [semantic_release.hvcs.github] DEBUG           helpers.py:44
                    helpers._wrapper:                                           
                    upload_asset(<semantic_release.hvcs.github.Git              
                    hub object at 0x7f980dc42530>, 123507536,                   
                    'dist/hello.txt', )                                         
           DEBUG    [semantic_release.hvcs.github] DEBUG           helpers.py:44
                    helpers._wrapper:                                           
                    asset_upload_url(<semantic_release.hvcs.github              
                    .Github object at 0x7f980dc42530>, 123507536,               
                    )                                                           
           DEBUG    [urllib3.connectionpool] DEBUG         connectionpool.py:546
                    connectionpool._make_request:                               
                    https://api.github.com:443 "GET                             
                    /repos/zckv/semantic-versioning-exampl                      
                    e/releases/123507536 HTTP/1.1" 200                          
                    None                                                        
           DEBUG    [semantic_release.hvcs.github] DEBUG           helpers.py:55
                    helpers._wrapper: Github.asset_upload_url ->                
                    https://uploads.github.com/repos/zckv/semantic              
                    -versioning-example/releases/123507536/assets               
           DEBUG    [urllib3.connectionpool] DEBUG        connectionpool.py:1048
                    connectionpool._new_conn: Starting                          
                    new HTTPS connection (1):                                   
                    uploads.github.com:443                                      
[14:13:23] DEBUG    [urllib3.connectionpool] DEBUG         connectionpool.py:546
                    connectionpool._make_request:                               
                    https://uploads.github.com:443 "POST                        
                    /repos/zckv/semantic-versioning-exampl                      
                    e/releases/123507536/assets?name=hello                      
                    .txt HTTP/1.1" 422 206                                      
           ERROR    [semantic_release.hvcs.github] ERROR           github.py:263
                    github.upload_dists: error uploading asset                  
                    dist/hello.txt                                              
                    ╭──── Traceback (most recent call last) ─────╮              
                    │ /usr/local/lib/python3.10/site-packages/se │              
                    │ mantic_release/hvcs/github.py:260 in       │              
                    │ upload_dists                               │              
                    │                                            │              
                    │   257 │   │   │   f for f in glob.glob(dis │              
                    │   258 │   │   ):                           │              
                    │   259 │   │   │   try:                     │              
                    │ ❱ 260 │   │   │   │   self.upload_asset(re │              
                    │   261 │   │   │   │   n_succeeded += 1     │              
                    │   262 │   │   │   except HTTPError:  # noq │              
                    │   263 │   │   │   │   log.exception("error │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/se │              
                    │ mantic_release/helpers.py:52 in _wrapper   │              
                    │                                            │              
                    │    49 │   │   │   )                        │              
                    │    50 │   │   │                            │              
                    │    51 │   │   │   # Call function          │              
                    │ ❱  52 │   │   │   result = func(*args, **k │              
                    │    53 │   │   │                            │              
                    │    54 │   │   │   # Log result             │              
                    │    55 │   │   │   logger.debug("%s -> %s", │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/se │              
                    │ mantic_release/hvcs/github.py:222 in       │              
                    │ upload_asset                               │              
                    │                                            │              
                    │   219 │   │   )                            │              
                    │   220 │   │                                │              
                    │   221 │   │   with open(file, "rb") as dat │              
                    │ ❱ 222 │   │   │   response = self.session. │              
                    │   223 │   │   │   │   url,                 │              
                    │   224 │   │   │   │   params={"name": os.p │              
                    │   225 │   │   │   │   headers={            │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/re │              
                    │ quests/sessions.py:637 in post             │              
                    │                                            │              
                    │   634 │   │   :rtype: requests.Response    │              
                    │   635 │   │   """                          │              
                    │   636 │   │                                │              
                    │ ❱ 637 │   │   return self.request("POST",  │              
                    │   638 │                                    │              
                    │   639 │   def put(self, url, data=None, ** │              
                    │   640 │   │   r"""Sends a PUT request. Ret │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/re │              
                    │ quests/sessions.py:589 in request          │              
                    │                                            │              
                    │   586 │   │   │   "allow_redirects": allow │              
                    │   587 │   │   }                            │              
                    │   588 │   │   send_kwargs.update(settings) │              
                    │ ❱ 589 │   │   resp = self.send(prep, **sen │              
                    │   590 │   │                                │              
                    │   591 │   │   return resp                  │              
                    │   592                                      │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/re │              
                    │ quests/sessions.py:710 in send             │              
                    │                                            │              
                    │   707 │   │   r.elapsed = timedelta(second │              
                    │   708 │   │                                │              
                    │   709 │   │   # Response manipulation hook │              
                    │ ❱ 710 │   │   r = dispatch_hook("response" │              
                    │   711 │   │                                │              
                    │   712 │   │   # Persist cookies            │              
                    │   713 │   │   if r.history:                │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/re │              
                    │ quests/hooks.py:30 in dispatch_hook        │              
                    │                                            │              
                    │   27 │   │   if hasattr(hooks, "__call__") │              
                    │   28 │   │   │   hooks = [hooks]           │              
                    │   29 │   │   for hook in hooks:            │              
                    │ ❱ 30 │   │   │   _hook_data = hook(hook_da │              
                    │   31 │   │   │   if _hook_data is not None │              
                    │   32 │   │   │   │   hook_data = _hook_dat │              
                    │   33 │   return hook_data                  │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/se │              
                    │ mantic_release/hvcs/util.py:34 in <lambda> │              
                    │                                            │              
                    │   31 │   """                               │              
                    │   32 │   session = Session()               │              
                    │   33 │   if raise_for_status:              │              
                    │ ❱ 34 │   │   session.hooks = {"response":  │              
                    │   35 │                                     │              
                    │   36 │   if retry:                         │              
                    │   37 │   │   if isinstance(retry, bool):   │              
                    │                                            │              
                    │ /usr/local/lib/python3.10/site-packages/re │              
                    │ quests/models.py:1021 in raise_for_status  │              
                    │                                            │              
                    │   1018 │   │   │   )                       │              
                    │   1019 │   │                               │              
                    │   1020 │   │   if http_error_msg:          │              
                    │ ❱ 1021 │   │   │   raise HTTPError(http_er │              
                    │   1022 │                                   │              
                    │   1023 │   def close(self):                │              
                    │   1024 │   │   """Releases the connection  │              
                    ╰────────────────────────────────────────────╯              
                    HTTPError: 422 Client Error: Unprocessable                  
                    Entity for url:                                             
                    https://uploads.github.com/repos/zckv/semantic              
                    -versioning-example/releases/123507536/assets?              
                    name=hello.txt                                              
           DEBUG    [semantic_release.hvcs.github] DEBUG           helpers.py:55
                    helpers._wrapper: Github.upload_dists -> 0                  
0s
github-actions[bot] commented 2 months ago

It has been 60 days since the last update on this confirmed issue. @python-semantic-release/team can you provide an update on the status of this issue?

codejedi365 commented 2 months ago

Unfortunately, no update as of yet, still in the backlog.

github-actions[bot] commented 1 week ago

It has been 60 days since the last update on this confirmed issue. @python-semantic-release/team can you provide an update on the status of this issue?

codejedi365 commented 1 week ago

Still in the backlog