python-semantic-release icon indicating copy to clipboard operation
python-semantic-release copied to clipboard

Updates were rejected because the tag already exists in the remote

Open rosaLux161 opened this issue 2 years ago • 3 comments

The problem

semantic-release version determines a new version, runs the build command and fails with failed to push some refs. Version number in pyproject.toml is not updated. However the new tag is successfully created and changelog is pushed.

Expected behavior

No error.

Environment

Please state which OS you are using and provide the output of the following commands:

python 3.11
semantic-release 8.7.0

Configuration

(config meanwhile completely mixed up by trying around with many different values, so I'm not sure anymore what is required and why)

[tool.poetry]
name = "xxx"
version = "0.0.0"
description = "xxx"
authors = ["xxx"]
readme = "README.md"
packages = [{include = "xxx"}]

[tool.poetry.dependencies]
python = "~3.11"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.4"
python-semantic-release = "^8.7.0"
twine = "^4.0.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.semantic_release]
version_variable = [
    "xxx/__init__.py:__version__",
    "pyproject.toml:version"
]

branch = "main"
#upload_to_release = false
build_command = "poetry build"
commit_version_number = true
commit_subject = "doc: Changelog {version}"
version_source = "commit"

[tool.semantic_release.remote]
name = "origin"
type = "gitlab"
ignore_token_for_push = false
hvcs = "gitlab"
hvcs_domain = "gitlab.xxx"
hvcs_api_domain = "gitlab.xxx/api/v4"


[tool.semantic_release.remote.token]
env = "GITLAB_TOKEN"

[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = false

Logs

Please provide debug logs for the command you are using with the -vv flag, e.g.

$ semantic-release version
1.0.1
The next version is: 1.0.1! 🚀
🛠 Running build command: poetry build
Building xxx (0.0.0)
  - Building sdist
  - Built xxx-0.0.0.tar.gz
  - Building wheel
  - Built xxx-0.0.0-py3-none-any.whl
Traceback (most recent call last):
  File "/venv/bin/semantic-release", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/semantic_release/cli/commands/version.py", line 556, in version
    repo.git.push("--tags", remote_url, active_branch)
  File "/venv/lib/python3.11/site-packages/git/cmd.py", line 800, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/git/cmd.py", line 1386, in _call_process
    return self.execute(call, **exec_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/git/cmd.py", line 1183, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git push --tags https://*****:*****@gitlab.xxx/xx/xxx.git main
  stderr: 'To https://gitlab.xxx/xx/xxx.git
 * [new tag]         v1.0.1 -> v1.0.1
 ! [rejected]        v0.0.1 -> v0.0.1 (already exists)
error: failed to push some refs to 'https://gitlab.xxx/xx/xxx.git'
hint: Updates were rejected because the tag already exists in the remote.'
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1

EDIT:

I've tried to remove all tags, now i get this:

$ semantic-release version
Traceback (most recent call last):
  File "/venv/bin/semantic-release", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/semantic_release/cli/commands/version.py", line 288, in version
    new_version = next_version(
                  ^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/semantic_release/version/algorithm.py", line 288, in next_version
    merge_base = merge_bases[0]
                 ~~~~~~~~~~~^^^
IndexError: list index out of range

rosaLux161 avatar Jan 11 '24 14:01 rosaLux161

@rosaLux161, the first error where it pushed both 0.0.1, and 1.0.1, is very odd to me. I don't know why that would happen.

However, your second bug I have seen before, especially since you are using GitLab. I detail the answer here https://github.com/python-semantic-release/python-semantic-release/issues/724#issuecomment-1866625336, but basically the algorithm cannot find the merge-base commit because you likely have a shallow repo. Try the unshallow fix from the other post and let me know if it fixes it.

codejedi365 avatar Jan 11 '24 23:01 codejedi365

I might see if I can change the push command to only push the new tag to avoid the first failure.

codejedi365 avatar Jan 11 '24 23:01 codejedi365

I've implemented your fix and this seems to work.

rosaLux161 avatar Jan 15 '24 10:01 rosaLux161

Resolved only push new tag in v9.3.1

codejedi365 avatar Mar 24 '24 05:03 codejedi365