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

BuildingRef is incorrectly populated on Bitbucket pipelines #935

Closed
henriq opened this issue May 10, 2023 · 5 comments · Fixed by #936
Closed

BuildingRef is incorrectly populated on Bitbucket pipelines #935

henriq opened this issue May 10, 2023 · 5 comments · Fixed by #936
Labels
Milestone

Comments

@henriq
Copy link

henriq commented May 10, 2023

Hi,

Since updating nbgv from v3.5.119 to v3.6.128 we are experiencing an issue with the BuildingRef when running on Bitbucket pipelines. Previously the BuildingRef was set to refs/heads/<branch name>, while in the new version it's set to only <branch name>. This only happens when running in a Bitbucket pipeline, when running locally both versions prefix the branch name with refs/heads/.

This issue is causing the PublicReleaseRefSpec matching to fail in Bitbucket which means no releases are flagged as public unless we modify the regex.

Here's a minimal example of how to reproduce this issue.

version.json
{
  "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "version": "4.0",
  "publicReleaseRefSpec": [
    "^refs/heads/release/test/v\\d+(?:\\.\\d+)?$"
  ],
  "release": {
    "branchName": "release/test/v{version}",
    "firstUnstableTag": "prerelease"
  }
}
bitbucket-pipeline.yml
definitions:
  steps:
    - step: &versionStep
        name: Version
        image: mcr.microsoft.com/dotnet/sdk:7.0
        script:
          - dotnet tool install --tool-path ./nbgv-3.6.128 nbgv --version=3.6.128
          - dotnet tool install --tool-path ./nbgv-3.5.119 nbgv --version=3.5.119
          - ./nbgv-3.6.128/nbgv get-version -f json
          - ./nbgv-3.5.119/nbgv get-version -f json

pipelines:
  branches:
    release/**:
      - step: *versionStep

The following is output from each version of nbgv.

./nbgv-3.6.128/nbgv get-version -f json
{
  "CloudBuildNumber": "4.0.8+f47f9261d4",
  "CloudBuildNumberEnabled": false,
  "BuildMetadataWithCommitId": [
    "f47f9261d4"
  ],
  "VersionFileFound": true,
  "VersionOptions": {
    "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
    "Version": {
      "Version": "4.0",
      "Prerelease": "",
      "BuildMetadata": "",
      "VersionHeightPosition": 2
    },
    "PublicReleaseRefSpec": [
      "^refs/heads/release/test/v\\d+(?:\\.\\d+)?$"
    ],
    "Release": {
      "BranchName": "release/test/v{version}",
      "FirstUnstableTag": "prerelease"
    }
  },
  "AssemblyVersion": "4.0.0.0",
  "AssemblyFileVersion": "4.0.8.62591",
  "AssemblyInformationalVersion": "4.0.8+f47f9261d4",
  "PublicRelease": false,
  "PrereleaseVersion": "",
  "PrereleaseVersionNoLeadingHyphen": "",
  "SimpleVersion": "4.0.8",
  "BuildNumber": 8,
  "VersionRevision": 62591,
  "MajorMinorVersion": "4.0",
  "VersionMajor": 4,
  "VersionMinor": 0,
  "GitCommitId": "f47f9261d4868294391510800211c79cd607ffe8",
  "GitCommitIdShort": "f47f9261d4",
  "GitCommitDate": "2023-05-10T07:15:46+00:00",
  "VersionHeight": 8,
  "VersionHeightOffset": 0,
  "BuildingRef": "release/test/v1.0",
  "Version": "4.0.8.62591",
  "CloudBuildAllVarsEnabled": false,
  "CloudBuildAllVars": {
    "NBGV_CloudBuildNumber": "4.0.8+f47f9261d4",
    "NBGV_VersionFileFound": "True",
    "NBGV_AssemblyVersion": "4.0.0.0",
    "NBGV_AssemblyFileVersion": "4.0.8.62591",
    "NBGV_AssemblyInformationalVersion": "4.0.8+f47f9261d4",
    "NBGV_PublicRelease": "False",
    "NBGV_PrereleaseVersion": "",
    "NBGV_PrereleaseVersionNoLeadingHyphen": "",
    "NBGV_SimpleVersion": "4.0.8",
    "NBGV_BuildNumber": "8",
    "NBGV_VersionRevision": "62591",
    "NBGV_MajorMinorVersion": "4.0",
    "NBGV_VersionMajor": "4",
    "NBGV_VersionMinor": "0",
    "NBGV_GitCommitId": "f47f9261d4868294391510800211c79cd607ffe8",
    "NBGV_GitCommitIdShort": "f47f9261d4",
    "NBGV_GitCommitDate": "2023-05-10T07:15:46.0000000+00:00",
    "NBGV_VersionHeight": "8",
    "NBGV_VersionHeightOffset": "0",
    "NBGV_BuildingRef": "release/test/v1.0",
    "NBGV_Version": "4.0.8.62591",
    "NBGV_BuildMetadataFragment": "+f47f9261d4",
    "NBGV_NuGetPackageVersion": "4.0.8-gf47f9261d4",
    "NBGV_ChocolateyPackageVersion": "4.0.8-gf47f9261d4",
    "NBGV_NpmPackageVersion": "4.0.8",
    "NBGV_SemVer1": "4.0.8-f47f9261d4",
    "NBGV_SemVer2": "4.0.8-gf47f9261d4",
    "NBGV_SemVer1NumericIdentifierPadding": "4"
  },
  "CloudBuildVersionVarsEnabled": true,
  "CloudBuildVersionVars": {
    "GitAssemblyInformationalVersion": "4.0.8+f47f9261d4",
    "GitBuildVersion": "4.0.8.62591",
    "GitBuildVersionSimple": "4.0.8"
  },
  "BuildMetadata": [],
  "BuildMetadataFragment": "+f47f9261d4",
  "NuGetPackageVersion": "4.0.8-gf47f9261d4",
  "ChocolateyPackageVersion": "4.0.8-gf47f9261d4",
  "NpmPackageVersion": "4.0.8",
  "SemVer1": "4.0.8-f47f9261d4",
  "SemVer2": "4.0.8-gf47f9261d4",
  "SemVer1NumericIdentifierPadding": 4
}
./nbgv-3.5.119/nbgv get-version -f json
{
  "CloudBuildNumber": "4.0.8",
  "CloudBuildNumberEnabled": false,
  "BuildMetadataWithCommitId": [
    "f47f9261d4"
  ],
  "VersionFileFound": true,
  "VersionOptions": {
    "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
    "Version": {
      "Version": "4.0",
      "Prerelease": "",
      "BuildMetadata": "",
      "VersionHeightPosition": 2
    },
    "PublicReleaseRefSpec": [
      "^refs/heads/release/test/v\\d+(?:\\.\\d+)?$"
    ],
    "Release": {
      "BranchName": "release/test/v{version}",
      "FirstUnstableTag": "prerelease"
    }
  },
  "AssemblyVersion": "4.0.0.0",
  "AssemblyFileVersion": "4.0.8.62591",
  "AssemblyInformationalVersion": "4.0.8+f47f9261d4",
  "PublicRelease": true,
  "PrereleaseVersion": "",
  "PrereleaseVersionNoLeadingHyphen": "",
  "SimpleVersion": "4.0.8",
  "BuildNumber": 8,
  "VersionRevision": 62591,
  "MajorMinorVersion": "4.0",
  "VersionMajor": 4,
  "VersionMinor": 0,
  "GitCommitId": "f47f9261d4868294391510800211c79cd607ffe8",
  "GitCommitIdShort": "f47f9261d4",
  "GitCommitDate": "2023-05-10T07:15:46+00:00",
  "VersionHeight": 8,
  "VersionHeightOffset": 0,
  "BuildingRef": "refs/heads/release/test/v1.0",
  "Version": "4.0.8.62591",
  "CloudBuildAllVarsEnabled": false,
  "CloudBuildAllVars": {
    "NBGV_CloudBuildNumber": "4.0.8",
    "NBGV_VersionFileFound": "True",
    "NBGV_VersionOptions": "Nerdbank.GitVersioning.VersionOptions",
    "NBGV_AssemblyVersion": "4.0.0.0",
    "NBGV_AssemblyFileVersion": "4.0.8.62591",
    "NBGV_AssemblyInformationalVersion": "4.0.8+f47f9261d4",
    "NBGV_PublicRelease": "True",
    "NBGV_PrereleaseVersion": "",
    "NBGV_PrereleaseVersionNoLeadingHyphen": "",
    "NBGV_SimpleVersion": "4.0.8",
    "NBGV_BuildNumber": "8",
    "NBGV_VersionRevision": "62591",
    "NBGV_MajorMinorVersion": "4.0",
    "NBGV_VersionMajor": "4",
    "NBGV_VersionMinor": "0",
    "NBGV_GitCommitId": "f47f9261d4868294391510800211c79cd607ffe8",
    "NBGV_GitCommitIdShort": "f47f9261d4",
    "NBGV_GitCommitDate": "05/10/2023 07:15:46 +00:00",
    "NBGV_VersionHeight": "8",
    "NBGV_VersionHeightOffset": "0",
    "NBGV_BuildingRef": "refs/heads/release/test/v1.0",
    "NBGV_Version": "4.0.8.62591",
    "NBGV_BuildMetadataFragment": "+f47f9261d4",
    "NBGV_NuGetPackageVersion": "4.0.8",
    "NBGV_ChocolateyPackageVersion": "4.0.8",
    "NBGV_NpmPackageVersion": "4.0.8",
    "NBGV_SemVer1": "4.0.8",
    "NBGV_SemVer2": "4.0.8",
    "NBGV_SemVer1NumericIdentifierPadding": "4"
  },
  "CloudBuildVersionVarsEnabled": true,
  "CloudBuildVersionVars": {
    "GitAssemblyInformationalVersion": "4.0.8+f47f9261d4",
    "GitBuildVersion": "4.0.8.62591",
    "GitBuildVersionSimple": "4.0.8"
  },
  "BuildMetadata": [],
  "BuildMetadataFragment": "+f47f9261d4",
  "NuGetPackageVersion": "4.0.8",
  "ChocolateyPackageVersion": "4.0.8",
  "NpmPackageVersion": "4.0.8",
  "SemVer1": "4.0.8",
  "SemVer2": "4.0.8",
  "SemVer1NumericIdentifierPadding": 4
}

As can be seen in the output above, PublicRelease and BuildingRef differ between the two versions.

@AArnott AArnott added the bug label May 10, 2023
@AArnott AArnott added this to the v3.6 milestone May 10, 2023
@AArnott
Copy link
Collaborator

AArnott commented May 10, 2023

Thank you for the excellent bug report.

It looks like our bitbucket code hasn't changed since it was first introduced, so the problem must be elsewhere. Maybe this isn't a BitBucket-specific problem.

While I investigate this, can you please dump the environment block from within a bitbucket pipeline so I can imagine how that data will flow through NB.GV?

@AArnott
Copy link
Collaborator

AArnott commented May 10, 2023

Oh gosh. 3.6 added BitBucket support, so ya, this is BitBucket specific and apparently it's just buggy. It should be returning strings that start with refs/heads/ for branches and refs/tags/ for tags. Apparently at least for branches, BitBucket doesn't include that in the environment variable so we'll need to explicitly add it.

AArnott added a commit that referenced this issue May 10, 2023
BitBucket environment variables do not include the `refs/` prefix, so we need to add them ourselves (as we do for some other cloud build services already).

Fixes #935
AArnott added a commit that referenced this issue May 10, 2023
BitBucket environment variables do not include the `refs/` prefix, so we need to add them ourselves (as we do for some other cloud build services already).

Fixes #935
AArnott added a commit that referenced this issue May 10, 2023
BitBucket environment variables do not include the `refs/` prefix, so we need to add them ourselves (as we do for some other cloud build services already).

Fixes #935
@henriq
Copy link
Author

henriq commented May 10, 2023

@AArnott Ok! Do you still need the environment of the pipeline or should we start by testing the PR?

@AArnott
Copy link
Collaborator

AArnott commented May 10, 2023

I think we can test the PR at this point, as I'm pretty sure of what the environment must be.

@henriq
Copy link
Author

henriq commented May 10, 2023

Ok! Here are the env variables relevant to the commit, so your guess seems good to me.

Branch build
BITBUCKET_BRANCH=release/test/v1.0

Tag build
BITBUCKET_TAG=1.0

@AArnott AArnott closed this as completed May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants