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

Nuget Package Version and nbgv cloud NBGV_NuGetPackageVersion differ #451

Closed
epvanhouten opened this issue Mar 13, 2020 · 18 comments · Fixed by #465
Closed

Nuget Package Version and nbgv cloud NBGV_NuGetPackageVersion differ #451

epvanhouten opened this issue Mar 13, 2020 · 18 comments · Fixed by #465

Comments

@epvanhouten
Copy link

Nerdbank.GitVersioning Version 3.1.68

version.json

{
    "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
    "version": "0.2",
    "pathFilters": ["."],
    "publicReleaseRefSpec": [
        "^refs/heads/master$"
      ]
  }

Results in package like <Package Name>.0.2.0-g49454ca976.nupkg and NBGV_NuGetPackageVersion like 0.2.1-g49454ca976.

@AArnott
Copy link
Collaborator

AArnott commented Mar 13, 2020

Can you include a diagnostic build log? (/bl switch and the .binlog file would be great)

@epvanhouten
Copy link
Author

nerdbankDebug.zip

Produced by running

dotnet pack /bl
nbgv cloud -s VisualStudioTeamServices --all-vars > AzDoAllvars.txt

in this repo.

@AArnott
Copy link
Collaborator

AArnott commented Mar 14, 2020

Thanks for the great repro. I can repro it as well and am investigating. It appears to be specific to @saul's new pathFilters feature that you're using.
Any ideas, @saul?

@AArnott
Copy link
Collaborator

AArnott commented Mar 14, 2020

BTW, the difference isn't in the package vs. the CLI. The difference is whether the version calculation is from the repo root or the project directory.
So @epvanhouten, a workaround for you would be to pass the -p sub-dir argument when calling nbgv so that the relative path is the same as the path that contains the project being packed.

@epvanhouten
Copy link
Author

epvanhouten commented Mar 14, 2020 via email

@AArnott
Copy link
Collaborator

AArnott commented Mar 14, 2020

Well, since version.json was defined only once in the root, and the pathfilter indicated ., that I would expect to mean all files and directories at the repo root and below. So I expect the same version throughout.

@epvanhouten
Copy link
Author

epvanhouten commented Mar 14, 2020 via email

@jmezach
Copy link

jmezach commented Mar 17, 2020

I'm seeing a similar issue, but even after removing the path filters it doesn't seem to work. I'm using GitHub Actions and I see that my NuGet package I'm producing gets a different version number then when I try to restore that same NuGet package later on in a different job.

For some reason the NuGet package version being calculated is two Git commits higher than what's being set by nbgv cloud. Interestingly running nbgv cloud locally on my development machine produces the correct version number. This is kinda driving me crazy.

Feel free to have a look at my repo. For example, in this CI Workflow I'm seeing that nbgv cloud --all-vars sets NBGV_NuGetPackageVersion to 1.0.0-beta.23, but later on in that same job when I do a dotnet pack I'm getting 1.0.0-beta.25 as the version number.

@jmezach
Copy link

jmezach commented Mar 18, 2020

Applying @AArnott's workaround of specifying the sub path explicitly when running nbgv cloud seems to resolve my issue. Still don't understand why that's necessary though because I only have one single version.json file in my entire repository.

@AArnott
Copy link
Collaborator

AArnott commented Mar 18, 2020

I'm glad the workaround worked, @jmezach.
There's no good reason for it -- it's just a bug in the pathFilter feature. This is exactly why I was hesitant to accept that PR: I figured there was a high chance it would be buggy. So far I haven't heard from @saul who contributed it and if I don't have time to investigate fixing it myself and no one else contributes I may remove the feature.

@AArnott
Copy link
Collaborator

AArnott commented Mar 18, 2020

even after removing the path filters it doesn't seem to work

Probably because you didn't rewrite your past commits. NB.GV is a git history based algorithm so if your pathFilter is in any of your git commit history, it will still impact the version height calculation even if your more recent commits no longer use it.

@saul
Copy link
Contributor

saul commented Mar 18, 2020

For what it's worth, we've been using path filters on dozens of packages at our company with no issues. Although from the comments in this ticket, it appears this issue is only happening with NBGV cloud? I could certainly set aside some time to dig into this.

@AArnott
Copy link
Collaborator

AArnott commented Mar 18, 2020

Thanks, @saul!

A bit more info to help you:
The problem is not with nbgv cloud it has to do with the directory the version is calculated for. As people typically run nbgv cloud, the context is usually the repo root directory. Since the version calculated for any project is the project directory, these two directories are different and the version is different due to the bug. The workaround I prescribe above demonstrates how nbgv cloud -p some-project-dir demonstrates this.

Here are the pathFilters used in the two folks who have reported version mismatches:

rr-wfm/MSBuild.Sdk.SqlProj@9cbba15
https://github.com/epvanhouten/nerdbankReproduction/blob/1bc6de56915bd868503e91274d471bd249f08dd0/version.json#L4

@AArnott
Copy link
Collaborator

AArnott commented Apr 7, 2020

Any progress, @saul?

@saul
Copy link
Contributor

saul commented Apr 7, 2020

Hi - I did spend a couple of hours on Friday afternoon looking into this but it wasn't immediately obvious how I could fix it. I'm setting aside more time tomorrow in the working day to dig deeper.

Is there an easier way to communicate with you both instead of GitHub comments? I may have some more questions re the cloud functionality.

Thanks

@AArnott
Copy link
Collaborator

AArnott commented Apr 7, 2020

Yes: you can find me on gitter.im. this repo has a room there.

But again, this has nothing to do with the cloud feature, and everything to do with the "projectDirectory" used to start the version calculation.

@saul
Copy link
Contributor

saul commented Apr 11, 2020

OK so my understanding of the problem is that when building a project, repoRelativeProjectDirectory is the path to the directory that the csproj/fsproj lives in. When running nbgv cloud, repoRelativeProjectDirectory points to the root of the repo. This is causing version differences when relative paths are used.

I believe the bug here is that relative paths should always be relative to the version.json file, not the project directory. I'll see if I can whip up a unit test to exercise this.

saul added a commit to saul/Nerdbank.GitVersioning that referenced this issue Apr 12, 2020
Fixes dotnet#451

Path were incorrectly relative to the project directory.
@saul
Copy link
Contributor

saul commented Apr 12, 2020

Opened #465 which fixes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants