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

Setup python semantic release with master/beta/development/feature branches #789

Open
ZionStage opened this issue Jan 2, 2024 · 7 comments
Assignees
Labels
bug Something isn't working properly confirmed Prevent from becoming stale

Comments

@ZionStage
Copy link

Hello everyone (and a happy new year to all),

I have been using python-semantic-release for 2 months now, and I still encounter problems setting it up for my current work flow.

I have a python package with 3 main branches (main, beta and development) and some feature branches (feat-*). I need to have a dependable versioning system on all these branches in order to generate a front end client in the CI. My workflow is as is :

  • For a new feature, create a feature branch from development
  • Iterate on this feature branch until everything works
  • Merge on development
  • [Optional] repeat with as many features as needed
  • Merging development into beta
  • When ready for production, merging beta into main
  • Merging main into beta and beta into development

I have the following conf file :

[tool.semantic_release]
version_toml = [
    "pyproject.toml:project.version",
]
commit_message = "Bump to {version} [skip ci]\n\nAutomatically generated by python-semantic-release"

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

[tool.semantic_release.branches.beta]
match = "beta"
prerelease = true
prerelease_token = "beta"

[tool.semantic_release.branches.development]
match = "development"
prerelease = true
prerelease_token = "alpha"

[tool.semantic_release.branches.features]
match = "^feat-.*$"
prerelease = true
prerelease_token = "dev"

When creating a feature branch the versioning works well, however as soon as I merge into development and merge development into beta I run into some versioning problems.
Sometimes even if I'm on beta the output version is tagged alpha, sometimes the output version does not have a pre-release token.
Obviously, there's something wrong with my configuration for my workflow, but I can't seem to pinpoint what it is even after reading the whole docs. So here are my questions :

  • Can python-semantic-release work with the workflow I described ?
  • If so, what am I missing ?

Thank you !

@codejedi365
Copy link
Contributor

codejedi365 commented Jan 2, 2024

@ZionStage, Thank you for submitting your issue. I believe your branching strategy is almost exactly the Git Flow strategy with a slight variation to include a separate beta branch. Python Semantic Release is built to support Git Flow so the answer to your first question is yes, your workflow is supported. At first glance, I do believe your configuration file is also correct and complete.

The downside, Git Flow is a fairly complex workflow and we may not be covering all scenarios. In fact, as I was just yesterday refactoring the testing code for angular style repository scenarios, and the current testing does not cover merges of Git Flow branches. This gap in test coverage could have some bugs in it that you are experiencing.

To help isolate the problem further, can you provide the output log of one such circumstance where it creates the version with the wrong token but with debug level verbosity enabled. The option is -vv. You should be able to go to the commit directly and execute semantic-release -vv version --print. The output should be descriptive of how it interprets the tags of the repository.

Secondly, if you can confirm that you are using the included angular parser? If not, please specify which included parser or provide the code for your custom parser.

Lastly, what is your merging strategy? I suspect it is just merge --no-ff but if it is squash or rebase and merge, that could cause different outcomes. If you don't know, it would be helpful if you could take a snapshot of your git repo in graph form, which you can do with VSCode's Git Graph Extension, or in the terminal with git log --graph --decorate --oneline --all --topo-order. With the snapshot, please make sure to isolate the area where an incorrect tag was created.

@ZionStage
Copy link
Author

Hi @codejedi365, thanks for your quick answer

Here is an example of something I don't quite understand with the implemented logic. I just merged development into beta. The last tag of development is 1.2.0-alpha.5 and the last tag of 1.2.0-beta.2. What I would expect after the merge on beta is the creation of the tag 1.2.0-beta.3 yet the algorithm outputs 1.2.0-alpha.5. I provided the logs in this version_output.log file.

The parser I use is the included angular parser indeed, I did not change anything concerning the parser, and it is the default parser from what I understand.

As for my merging strategy, it is just merge. At first, I thought that squashing was a good idea, but it leads to more unexpected behavior, so we decided to start over again with a simple merge.

Here's the tip of the git graph I have.
Screenshot 2024-01-03 at 11 42 13

Let me know if there are still some gray zones or if you need me to provide more info

@codejedi365
Copy link
Contributor

That definitely sounds like the incorrect version determination. Thank you for the info, I didn't find anything yet but should have some time tomorrow. Would you be able to run the version determination again without the latest incorrect version? Right now it is hard to tell since it thinks it evaluated correctly and no new version is required

Steps:

  • clone repo into /tmp
  • Checkout beta branch at merge: git checkout -B beta v1.2.0-alpha.5
  • Delete tag: git tag -d v1.2.0-alpha.5
  • Execute version determination in debug mode semantic-release -vv version --print > next_beta_version.log

@ZionStage
Copy link
Author

Of course, no problem. I followed your steps and here are the resulting logs : next_beta_version_stderr.log

Just so you know, I created a feature branch from development for a new feature. I just finished it today and the last version is v1.2.0-dev.1+feat-shelves.
I just happened to merge it into development and I get the same issue: next_dev_version_stderr.log

Here's the git tree.
Screenshot 2024-01-04 at 15 46 23

@codejedi365
Copy link
Contributor

@ZionStage, The logs along with the picture were really helpful. I pieced apart logs to identify the flawed decision. Will start reviewing the code for optimizations and improvements. It seems to not to fully evaluate merges but only walks down the latest parent chain of commits until it reaches a tag and stops. It forgets to look down the beta branch for tags, and it also forgets to use the prerelease token configuration that it previously identified for the beta branch.

Lots of unintended behavior, thank you for bringing this to our attention!

@ZionStage
Copy link
Author

Glad to know this was helpful to you.
Let me know if you want me to test some WIP when you have some time to tackle this.

Have a nice one !

@codejedi365
Copy link
Contributor

Just for an update on this, I believe I have found a fix, I'm working on building a test case to prevent regression however it is taking a bit longer fitting into the newer test structure.

codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Mar 23, 2024
In the case where there are alpha and beta releases, we must only
consider the previous beta release even if alpha releases exist
due to merging into beta release only branches which have no changes
considerable changes from alphas but must be marked otherwise.

Resolves: python-semantic-release#789
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Mar 23, 2024
In the case where there are alpha and beta releases, we must only
consider the previous beta release even if alpha releases exist
due to merging into beta release only branches which have no changes
considerable changes from alphas but must be marked otherwise.

Resolves: python-semantic-release#789
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Mar 24, 2024
In the case where there are alpha and beta releases, we must only
consider the previous beta release even if alpha releases exist
due to merging into beta release only branches which have no changes
considerable changes from alphas but must be marked otherwise.

Resolves: python-semantic-release#789
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Mar 24, 2024
In the case where there are alpha and beta releases, we must only
consider the previous beta release even if alpha releases exist
due to merging into beta release only branches which have no changes
considerable changes from alphas but must be marked otherwise.

Resolves: python-semantic-release#789
@codejedi365 codejedi365 added the confirmed Prevent from becoming stale label Mar 26, 2024
@codejedi365 codejedi365 self-assigned this Apr 11, 2024
@codejedi365 codejedi365 added bug Something isn't working properly and removed confirmed Prevent from becoming stale question labels Apr 11, 2024
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue Apr 20, 2024
In the case where there are alpha and beta releases, we must only
consider the previous beta release even if alpha releases exist
due to merging into beta release only branches which have no changes
considerable changes from alphas but must be marked otherwise.

Resolves: python-semantic-release#789
@codejedi365 codejedi365 added the confirmed Prevent from becoming stale label May 6, 2024
codejedi365 added a commit to codejedi365/python-semantic-release that referenced this issue May 18, 2024
In the case where there are alpha and beta releases, we must only
consider the previous beta release even if alpha releases exist
due to merging into beta release only branches which have no changes
considerable changes from alphas but must be marked otherwise.

Resolves: python-semantic-release#789
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
Development

No branches or pull requests

2 participants