mtkennerly / dunamai

Dynamic versioning library and CLI
https://dunamai.readthedocs.io/en/latest
MIT License
320 stars 23 forks source link

Tags not found in monorepo setup #55

Closed cmarqu closed 1 year ago

cmarqu commented 1 year ago

I have a monorepo with a few packages, and I am using a git tag naming scheme like packagename/v0.1.2. Thus, I am setting pattern accordingly (adapted from the default, looking like ^packagename/v((?P<epoch>\\d+)!)?(?P<base>\\d+(\\.\\d+)*) in the middle part).

So far so good, but I found I am not getting all the tags offered with dunamai while e.g. git tag -l shows them all. My tags are like packagename1/v0.1.2, packagename2/v0.1.2, packagename3/v0.1.2, potentially all pointing to the same git hash.

mtkennerly commented 1 year ago

Hi! Could you give me a sample of how to reproduce this? On my end, it works as expected when the same commit has two tags and you use different patterns to select them. Are you seeing this locally, on CI, or both?

Setup:

git init
echo foo > foo.txt
git add .
git commit -m Initial --no-gpg-sign
git tag bar/v0.1.0 -m t1
git tag baz/v0.1.1 -m t2

Output:

$ dunamai from git --pattern '^bar/v(?P<base>\d+\.\d+\.\d+)$'
0.1.0

$ dunamai from git --pattern '^baz/v(?P<base>\d+\.\d+\.\d+)$'
0.1.1
cmarqu commented 1 year ago

I appear to have a pretty strange state in my repo in that the git hash which the tag points to does not show up in a plain git log, and also not with --full-history. It does show up with e.g. git show-ref --tags -d though.

I'm also using lightweight tags but that probably doesn't make a difference.

I will experiment more next week and try to find a recipe to make this reproducible.

EDIT: I'm seeing this both in CI (Jenkins) and locally.

mtkennerly commented 1 year ago

Do you have a workflow like this?

That would explain why it's not in the history of master and why removing --merged would help. I still think --merged should be the default (so that the dynamic versions are tailored to the active branch), but we could add an option to bypass it.

If you use a process like Gitflow, where all of the tags end up in the same branch (master) but just not the active branch (develop), then you can use the --tag-branch option.

cmarqu commented 1 year ago

(Sorry for the radio silence, I'm still trying to replicate how I ended up with the current tags in my repo.)

cmarqu commented 1 year ago

My problem is apparently a mixture of the fact that in my CI setup, the Jenkins git plugin leaves a detached head by checking out a hash instead of a branch (fixed by doing another git checkout <branchname> in the Jenkinsfile), and not properly fetching the tags when I tried to replicate locally. It all works fine now, thanks!