Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

v5.3.0 always looks for tags created from the branch #126

Closed
impks27 opened this issue Oct 25, 2023 · 7 comments
Closed

v5.3.0 always looks for tags created from the branch #126

impks27 opened this issue Oct 25, 2023 · 7 comments

Comments

@impks27
Copy link

impks27 commented Oct 25, 2023

v5.3.0 always looks for tags created from the branch.
By default it should consider last matching tag on the repo. Right now it's always making an increment to tag from the particular branch.

Is this expected behaviour?

@PaulHatch
Copy link
Owner

Yes, or more specifically it always looks at the current HEAD unless you set the branch explicitly (not recommended 99% of the time).

So "current" is found using git' rev-parse HEAD, then this command is used to find the tag:

git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}

If it looked at the entire repository you'd get some very strange behavior, especially when re-running older builds.

@impks27
Copy link
Author

impks27 commented Oct 25, 2023

Thanks for the reply. It's an awesome action.
Does this support releasing from multiple branches?
For e.g.
If I use release branches for each release
REL2023.10.0
REL2023.11.0

Will each branch start with 0.0.1? I assume no, as it could cause scmtag exists issue.

How to support this case using this action?

@PaulHatch
Copy link
Owner

Thanks, yes, there is a new branch support feature just added a few weeks ago (#76). The term branches in this context can be a bit overloaded so let me define these first:

  • There is a branch parameter, referenced above, this allows you to explicitly get a version for a particular branch (or commit). This has been present from the start, but I don't think this is useful at all to be honest, I'm considering removing it. Aside from the name it doesn't really have anything to do with "branch support"
  • There is a use_branches option which is deprecated now and will be removed in version 6. This literally just uses the branch name instead of the tag. This works in certain limited cases but is problematic once you start merging branches, since branch commits aren't fixed.
  • Finally there is the latest option version_from_branch, if you want to version from branches, this is the option you want to use.

What the version_from_branch option does when enabled is look at the name of the currently checked out branch and if it ends with either a {major} or {major}.{minor} pattern (e.g. v1 or v1.2) it will always use those values are the major/minor version, considering only tags which match that version. It will also downgrade commit message increments so that the predicted version does not exceed the branch version, so a MAJOR type commit on a v1 branch will be treated as a minor increment.

In this way you would be able to do things like merge a bug fix into multiple version branches without worrying about the tags present in the commit log for other versions or commit messages causing a conflict with another already published version.

You should tag the commit where that branch is first created in order to get reliable increment numbers, otherwise the action won't know how far back a particular version branch forked from the main trunk, and continue to tag commits when you release them the same as you would without branch support enabled since the action will still look for tags matching the branch version.

Note that in your example it seems that you are specifying the patch as part of the branch name, is the major version supposed to be 2023? If you enable version_from_branch only the the last two numbers at most will be used, so REL2023.10.0 would be interpreted as v10.0.*, so only tags in this range would be considered.

@impks27
Copy link
Author

impks27 commented Oct 30, 2023

The problem I am facing is when I create tags from feature branches. Same tags are getting created from both feature branches and my pipeline is failing with error SCM tag already exists.

How do I get past this?

Use case is to be able to create tags from different feature branches but follow semantic versioning for the repository

@PaulHatch
Copy link
Owner

Well the tags need to be unique, I'm not sure what you're using exactly though.

What I mean is imagine you are on master and you are releasing a new version, say 7.0.0. You would create a branch name like release/v7 or release/v7.1 depending on whether you planned to provide ongoing updates for v7.x or v7.0.x. At that point you need to also tag that commit like v7.0.0.

Some time goes by and you want to release an update. You're still on branch release/v7 or release/v7.0, so you build as normal and the action gives you the version 7.0.1, when you decide to release you add that tag. So far nothing has really changed from a normal setup that isn't using branches aside from the creation of the branch.

After you've released 8.0.0 suppose you find a bug in 7.0.1 and want to fix it. This is where the version_from_branch has an effect, depending on how that commit was created. If you simple push a new commit to the branch, that's pretty simple and you won't have any issues regardless. On the other hand if you are doing some more complicated stuff with merges, merging a fix into multiple branches you could run into trouble if the branch ends up including a commit tagged for a later version. Here using version_from_branch ensures that only 7.x commits are considered, and that no commits will cause your version to exceed the one specified by the branch name.

Using branches for versioning is quite an advance use case, most people will not need. I am in the process of writing up a guide which includes a section on choosing a versioning strategy. It is still a work in progress, but might be helpful.

@jerryderry
Copy link

jerryderry commented Nov 1, 2023

Hi, I actually have the same question, but I'm not quite understand your explanation above.

git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=${current} ${refPrefixPattern}${releasePattern}

This command will only list the tags reachable from current. However, not all tags can be reached from there. Wouldn't it mean conflicting tags will be generated?

Could you also elaborate on this, please?

If it looked at the entire repository you'd get some very strange behavior, especially when re-running older builds.

Why would we have strange behaviour?

My use case is: feature branches will be created, and once a feature is done, the feature branch will be merged back to the main branch, producing a release. There is only one series of version numbers.

@PaulHatch
Copy link
Owner

This command will only list the tags reachable from current. However, not all tags can be reached from there. Wouldn't it mean conflicting tags will be generated?

Well yes. Maybe I can add some detection for this and print a friendly warning or something.

Why would we have strange behaviour?

You'd randomly pick up versions jumping ahead depending on how other branches had been tagged, the latest version would always be selected. This commit is quite likely not even an ancestor of the current HEAD, so how do we get the commits between them? If you went back and reran a previous build, you'd be trying to use a different tag as the previous tag, etc.

Based on the use case you described you do not need to use the version from branch feature at all, this is an advanced feature intended only for maintaining ongoing updates to previous versions. One thing you may wish to do is to use the branch name or commit hash as part of the version (e.g. v2.0.7-branch-name+1, but this would be done at a higher scope than this action.

e.g.

env:
  VERSION: ${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch }}-${{ github.head_ref }}+${{steps.version.outputs.increment}}

This will prevent version conflicts if you have two branches running at the same time which have the same number of commits since the last version tag, which may or may not be a problem for you depending on what else you are doing.

I am going to change this to a conversation, if there's a bug or feature request please open a new issue for it.

Repository owner locked and limited conversation to collaborators Nov 1, 2023
@PaulHatch PaulHatch converted this issue into discussion #127 Nov 1, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants