Skip to content

Configured tag_format is ignored if there are no tags in the repository #1137

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

Closed
tcjennings opened this issue Jan 10, 2025 · 2 comments · Fixed by #1138
Closed

Configured tag_format is ignored if there are no tags in the repository #1137

tcjennings opened this issue Jan 10, 2025 · 2 comments · Fixed by #1138
Assignees
Labels
bug Something isn't working properly confirmed Prevent from becoming stale

Comments

@tcjennings
Copy link

tcjennings commented Jan 10, 2025

Bug Report

Description

In a new project repo, where there are no tags or releases, PSR version command incorrectly creates a tag using the default tag_format instead of the configured tag_format.

Expected behavior

PSR should use the configured tag_format when it creates tags whether there are tags in the repo or not.

Actual behavior

PSR creates an initial tag using the default tag_format = v{version} instead of the configured tag_format = X{version}.

command: semantic-release -vv --noop version --patch --no-commit --skip-build --no-changelog --no-vcs-release --no-push

output: semantic-release 'noop' mode is enabled! would have run: GIT_COMMITTER_DATE=2025-01-10T14:22:42.173414-06:00 GIT_AUTHOR_NAME=semantic-release GIT_AUTHOR_EMAIL=semantic-release GIT_COMMITTER_NAME=semantic-release GIT_COMMITTER_EMAIL=semantic-release git tag -a v0.0.1 -m 'v0.0.1

Environment

  • Semantic-release version: 9.15.2
  • Build tool (w/ version): uv 0.5
pip freeze annotated-types==0.7.0 certifi==2024.12.14 charset-normalizer==3.4.1 click==8.1.8 click-option-group==0.5.6 dotty-dict==1.3.1 gitdb==4.0.12 gitpython==3.1.44 idna==3.10 importlib-resources==6.5.2 jinja2==3.1.5 markdown-it-py==3.0.0 markupsafe==3.0.2 mdurl==0.1.2 pydantic==2.10.5 pydantic-core==2.27.2 pygments==2.19.1 python-gitlab==4.13.0 python-semantic-release==9.15.2 requests==2.32.3 requests-toolbelt==1.0.0 rich==13.9.4 shellingham==1.5.4 smmap==5.0.2 tomlkit==0.13.2 typing-extensions==4.12.2 urllib3==2.3.0
semantic-release 'noop' mode is enabled!     would have run:
        GIT_COMMITTER_DATE=2025-01-10T14:22:42.173414-06:00 GIT_AUTHOR_NAME=semantic-release 
GIT_AUTHOR_EMAIL=semantic-release GIT_COMMITTER_NAME=semantic-release GIT_COMMITTER_EMAIL=semantic-release git tag -a 
v0.0.1 -m 'v0.0.1

Configuration

Semantic Release Configuration
[tool.semantic_release]
version_variables = ["version.py:__version__"]
tag_format = "X{version}"

[tool.semantic_release.branches.main]
match = "main"
prerelease = false

Build System Configuration

Execution Log

semantic-release -vv command
[14:25:48] DEBUG    [main.main] logging level set to: DEBUG                                                    main.py:133
🛡 You are running in no-operation mode, because the '--noop' flag was supplied
           DEBUG    [main.main] global cli options: GlobalCommandLineOptions(noop=True, verbosity=2,           main.py:148
                    config_file='pyproject.toml', strict=False)                                                           
           INFO     [util.load_raw_config_file] Loading configuration from pyproject.toml                       util.py:79
           DEBUG    [util.load_raw_config_file] Trying to parse configuration pyproject.toml in TOML format     util.py:82
           INFO     [config.select_branch_options] Using group 'main' options, as 'main' matches 'main'      config.py:549
           DEBUG    [config.from_raw_config] hvcs token is not set                                           config.py:701
           WARNING  [config.from_raw_config] Token value is missing!                                         config.py:704
           DEBUG    [template.environment] {'template_dir':                                                 template.py:57
                    PosixPath('/Users/tjennings/git/psr-test/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': False, 'autoescape_value': False}                                                       
           DEBUG    [translator._invert_tag_format_to_re] inverted tag_format 'X{version}' to             translator.py:40
                    'X(?P<version>.*)'                                                                                    
           DEBUG    [version.is_forced_prerelease] is_forced_prerelease: as_prerelease = False,              version.py:64
                    forced_level_bump = patch, prerelease = False                                                         
           WARNING  [version.version] Forcing a 'patch' release due to '--patch' command-line flag          version.py:487
           INFO     [algorithm.tags_and_versions] found 0 previous tags                                    algorithm.py:59
           DEBUG    [version.parse] attempting to parse string '0.0.0' as Version                           version.py:119
           DEBUG    [version.parse] version string 0.0.0 parsed as a non-prerelease                         version.py:143
           DEBUG    [version.parse] parsed build metadata '' from version string 0.0.0                      version.py:146
           DEBUG    [version.bump] performing a patch level bump                                            version.py:221
0.0.1
           INFO     [algorithm.tags_and_versions] found 0 previous tags                                    algorithm.py:59
           INFO     [algorithm.tags_and_versions] found 0 previous tags                                    algorithm.py:59
           DEBUG    [cmd.execute] Popen(['git', 'rev-list', '--topo-order', 'HEAD', '--'],                     cmd.py:1253
                    cwd=/Users/tjennings/git/psr-test, stdin=None, shell=False, universal_newlines=False)                 
           DEBUG    [release_history.from_git_history] checking if commit 3872174 matches any tags   release_history.py:67
           DEBUG    [release_history.from_git_history] no tags correspond to commit                  release_history.py:71
                    38721744217708d15b1d83a2a2eb86c7237cc505                                                              
           DEBUG    [cmd.execute] Popen(['git', 'cat-file', '--batch'], cwd=/Users/tjennings/git/psr-test,     cmd.py:1253
                    stdin=<valid stream>, shell=False, universal_newlines=False)                                          
           INFO     [release_history.from_git_history] parsing commit [38721744] initial commit     release_history.py:108
           DEBUG    [angular._logged_parse_error] Unable to parse commit message: 'initial commit\n'         angular.py:40
           INFO     [release_history.from_git_history] [Unreleased] adding '38721744'               release_history.py:158
                    commit(unknown) to list                                                                               
The next version is: 0.0.1! 🚀
🛡 semantic-release 'noop' mode is enabled! would have updated versions in the following paths:
    version.py
Skipping build due to --skip-build flag
🛡 semantic-release 'noop' mode is enabled!     would have run:
        git add version.py

🛡 semantic-release 'noop' mode is enabled!         would have run:
                            GIT_AUTHOR_NAME=semantic-release \
    GIT_AUTHOR_EMAIL=semantic-release \
    GIT_COMMITTER_NAME=semantic-release \
    GIT_COMMITTER_EMAIL=semantic-release \
    git commit -m '0.0.1

            Automatically generated by python-semantic-release'

🛡 semantic-release 'noop' mode is enabled!     would have run:
        GIT_COMMITTER_DATE=2025-01-10T14:25:48.858976-06:00 GIT_AUTHOR_NAME=semantic-release 
GIT_AUTHOR_EMAIL=semantic-release GIT_COMMITTER_NAME=semantic-release GIT_COMMITTER_EMAIL=semantic-release git tag -a 
v0.0.1 -m 'v0.0.1'

           INFO     [github_actions_output.write_if_possible] not writing GitHub Actions       github_actions_output.py:74
                    output, as no file specified                                                                          

Additional context

When configured tag_format = X{version}

  1. No git tags in repo - wrong behavior
psr-test ❯ git tag                                                                                           

psr-test ❯ semantic-release version --patch --skip-build --no-changelog --no-vcs-release --no-push       
[14:26:34] WARNING  [config.from_raw_config] Token value is missing!                                         config.py:704
           WARNING  [version.version] Forcing a 'patch' release due to '--patch' command-line flag          version.py:487
0.0.1
The next version is: 0.0.1! 🚀
Skipping build due to --skip-build flag

psr-test main*​ 
psr-test ❯ git tag
v0.0.1
  1. An existing tag in repo -- correct behavior
psr-test ❯ git tag X0.0.0

psr-test main*​ 
psr-test ❯ git tag                
X0.0.0

psr-test main*​ 
psr-test ❯ semantic-release version --patch --skip-build --no-changelog --no-vcs-release --no-push
[14:27:46] WARNING  [config.from_raw_config] Token value is missing!                                         config.py:704
           WARNING  [version.version] Forcing a 'patch' release due to '--patch' command-line flag          version.py:487
0.0.1
The next version is: 0.0.1! 🚀
Skipping build due to --skip-build flag

psr-test main*​ 
psr-test ❯ git tag                                                                                
X0.0.0
X0.0.1
@tcjennings tcjennings added bug Something isn't working properly triage waiting for initial maintainer review labels Jan 10, 2025
@codejedi365 codejedi365 added confirmed Prevent from becoming stale and removed triage waiting for initial maintainer review labels Jan 11, 2025
@codejedi365 codejedi365 self-assigned this Jan 11, 2025
@codejedi365
Copy link
Contributor

@tcjennings, wow what an obscure bug. I was able to replicate it and found the source of the problem. It is specific to using one of the force version bump parameters (ex. --patch, --minor, etc.) when no tags exist on the repository and not the automatic version determination algorithm.

codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Jan 11, 2025
codejedi365 added a commit that referenced this issue Jan 11, 2025
…or initial release (#1138)

Resolves: #1137

* test(fixtures): add new unreleased trunk repo with a different tag format

* test(cmd-version): ensure forced bump version on initial release follows tag format

  ref: #1137
@codejedi365
Copy link
Contributor

🎉 This issue has been resolved in Version 9.16.0 🎉

You can find more information about this release on the GitHub Releases page.

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 confirmed Prevent from becoming stale
Projects
None yet
2 participants