Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates were rejected because the tag already exists in the remote #803

Closed
rosaLux161 opened this issue Jan 11, 2024 · 4 comments · Fixed by #870
Closed

Updates were rejected because the tag already exists in the remote #803

rosaLux161 opened this issue Jan 11, 2024 · 4 comments · Fixed by #870
Labels
bug Something isn't working properly

Comments

@rosaLux161
Copy link

rosaLux161 commented Jan 11, 2024

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 rosaLux161 added the bug Something isn't working properly label Jan 11, 2024
@codejedi365
Copy link
Contributor

@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 #724 (comment), 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
Copy link
Contributor

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

@rosaLux161
Copy link
Author

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

codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Mar 23, 2024
…ated

Restricts the git push command to only push the explicit tag we created
which will eliminate the possibility of pushing another tag that could
cause an error.

Resolves: python-semantic-release#803
codejedi365 added a commit that referenced this issue Mar 24, 2024
…ated

Restricts the git push command to only push the explicit tag we created
which will eliminate the possibility of pushing another tag that could
cause an error.

Resolves: #803
@codejedi365
Copy link
Contributor

Resolved only push new tag in v9.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working properly
Projects
None yet
2 participants