GitTools / GitVersion

From git log to SemVer in no time
https://gitversion.net/docs/
MIT License
2.87k stars 653 forks source link

[ISSUE]: Falsely detecting shallow clone - azure devops build with unshallow checkout failing #4330

Open dazinator opened 2 days ago

dazinator commented 2 days ago

Prerequisites

GitVersion package

GitVersion.Tool, AzureDevops task

GitVersion version

6.0.5

Operating system

Linux

What are you seeing?

In my azure-pipleines.yml

steps:
- checkout: self
  persistCredentials: true
  clean: true
  fetchDepth: 0 # fetch full history for versioning

- task: gitversion/setup@3.0.3
  displayName: Install GitVersion
  inputs:
    versionSpec: '6.x'    

- task: gitversion/execute@3.0.3
  displayName: Determine Version
  name: Version
  inputs:
    useConfigFile: true
    configFilePath: GitVersion.yml

The see the -unshallow option being used in checkout happening in the azure devops pipeline logs

Starting: Checkout HubCore@refs/pull/991/merge to s
==============================================================================
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Syncing repository: HubCore (Git)
git version
git version 2.34.1
git config --get remote.origin.url
git clean -ffdx
git reset --hard HEAD
HEAD is now at 8603488f28 Merge pull request 991 from hotfix/0.88.7 into master
git config gc.auto 0
git config core.longpaths true
git config --get-all http.https://***@dev.azure.com/***/***/_git/HubCore.extraheader
git config --get-all http.extraheader
git config --get-regexp .*extraheader
git config --get-all http.proxy
git config http.version HTTP/1.1
git --config-env=http.extraheader=env_var_http.extraheader fetch --force --tags --prune --prune-tags --progress --no-recurse-submodules origin --unshallow  +refs/heads/*:refs/remotes/origin/* +refs/pull/991/merge:refs/remotes/pull/991/merge
remote: Azure Repos        
remote: 
remote: Found 63848 objects to send. (1560 ms)        
Receiving objects:   0% (1/63848)
Receiving objects:   1% (639/63848)
Receiving objects:   2% (1277/63848)
Receiving objects:   3% (1916/63848)
// shortened for brevity

The install step succeeds

Starting: Install GitVersion
==============================================================================
Task         : Setup GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org/) for projects using Git
Version      : 3.0.3
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
--------------------------
Acquiring GitVersion.Tool for version spec: 6.x
--------------------------
Querying tool versions for GitVersion.Tool@6.x 
Found matching version: 6.0.5
Looking for local tool GitVersion.Tool@6.0.5
Found tool GitVersion.Tool@6.0.5 at /azp/_work/_tool/GitVersion.Tool/6.0.5
--------------------------
GitVersion.Tool version: 6.0.5 found in local cache at /azp/_work/_tool/GitVersion.Tool/6.0.5.
--------------------------
Prepending /azp/_work/_tool/GitVersion.Tool/6.0.5 to PATH
Updated PATH: /azp/_work/_tool/GitVersion.Tool/6.0.5:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Set GITVERSION_PATH to /azp/_work/_tool/GitVersion.Tool/6.0.5
GitVersion installed successfully
Finishing: Install GitVersion

However then the execute step fails

Starting: Determine Version
==============================================================================
Task         : Execute GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org/) for projects using Git
Version      : 3.0.3
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
Executing GitVersion
Command: git -C /azp/_work/1/s rev-parse --is-shallow-repository
##[error]The repository is shallow. Consider disabling shallow clones. See https://github.com/GitTools/actions/blob/main/docs/cloning.md for more information.
Finishing: Determine Version

I am very confused.. looking for inspiration or ideas?

What is expected?

I didn't expect it to report a shallow clone with the checkout step fetch depth set to 0.

Steps to Reproduce

as per above is my current setup. Not sure how reproducable.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

as per above.
dazinator commented 2 days ago

Hm this is working now, here are my conclusions.

  1. The checkout step someone had accidentally moved so it wasn't the first step under steps - i think this is what initially caused the problem.
  2. Even when the above was fixed, the issue remained when using @3.0.3 for the task versions.

The fix seemed to be changing the task versions back to @0 e.g gitversion/setup@0 and gitversion/execute@0

  - task: gitversion/setup@0
    displayName: Install GitVersion
    inputs:
      versionSpec: '5.12.0'

  - task: gitversion/execute@0
    displayName: Determine Version
    name: Version
    inputs:
      useConfigFile: true
      configFilePath: GitVersion.yml

You'll notice I am specifying 5.12.0 because this was the version of gitversion that has been working previously. When I specified this version using @3.0.3 it still failed with same error and even with the correct checkout step for unshallow and clean. When I then moved back to @0 it started working.

I am not sure if there is some caching between the tools or anything like that, but its very odd.