dotnet / Nerdbank.GitVersioning

Stamp your assemblies, packages and more with a unique version generated from a single, simple version.json file and include git commit IDs for non-official builds.
https://www.nuget.org/packages/Nerdbank.GitVersioning
MIT License
1.36k stars 167 forks source link

Wrong version produced when changing version.json #389

Closed shana closed 5 years ago

shana commented 5 years ago

Hey hey! First off, love the project, it's solving almost all my versioning issues! I hit a thing that might or might not be a bug (or maybe I'm missing something, dunno)...

I have about 10 projects in a repo, and I'm following the instructions at https://github.com/AArnott/Nerdbank.GitVersioning/blob/master/doc/cloudbuild.md#set-them-from-just-one-project to set the cloud build variables from only one project. I have a version.json in the root like this:

version.json at root:

{
  "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "version":  "1.0",
  "publicReleaseRefSpec": [
    "^refs/heads/master$",
    "^refs/heads/v\\d+(?:.\\d+)?$"
  ],
  "cloudBuild": {
    "setVersionVariables": false,
    "buildNumber": {
      "enabled": false
    }
  },  
  "inherit": false
}

version.json in all project subdirectories except MasterProject:

{
    "$schema":  "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
    "inherit":  true
}

version.json in MasterProject:

{
  "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "cloudBuild": {
    "setVersionVariables": true,
    "buildNumber": {
      "enabled": true
    }
  },
  "inherit": true
}

It all works great except that I moved the projects down one subdirectory. The root version.json file has not been changed. After this move, all theprojects have their versions bumped correctly in a local build (from 1.0.9 to 1.0.10) EXCEPT for the MasterProject, which misteriously got stamped with 1.0.0. If I take out the the cloudBuild section in the MasterProject, it gets versioned correctly. Looks like it thinks that the version.json file in the MasterProject has changes that affect the version?

AArnott commented 5 years ago

You can simplify your root version.json to just the following, since you're just explicitly setting defaults.

 {
   "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
   "version":  "1.0",
   "publicReleaseRefSpec": [
     "^refs/heads/master$",
     "^refs/heads/v\\d+(?:.\\d+)?$"
   ],
-  "cloudBuild": {
-    "setVersionVariables": false,
-    "buildNumber": {
-      "enabled": false
-    }
-  },  
-  "inherit": false
 }

You can remove all your version.json files that are just:

{
    "$schema":  "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
    "inherit":  true
}

These are completely unnecessary.

For your master project and your main point, I'll think about it more and get back to you.

shana commented 5 years ago

Ah, cool, I'll try that, thanks!

AArnott commented 5 years ago

So your root version.json is and always has been in the repo root, right?

Can you share the repo or whip up a repro repo that you can share?

shana commented 5 years ago

@AArnott Yeah, the version.json in the root was never touched. The repo is https://github.com/spoiledcat/UnityTools, but I've moved some other things around and suddenly it's versioning things correctly, I can't reproduce it anymore. I have no idea what was happening or why it stopped happening :-/

AArnott commented 5 years ago

Well, that's good---ish. ;-p

One thing that frequently trips up people is that changes to version.json must be committed for everything to apply properly. Maybe when you were seeing the unexpected behavior, you only had local changes that hadn't been committed yet.

shana commented 5 years ago

Maybe, could have been that. If it happens again, I'll try to isolate it. Thanks!