Skip to content

Commit

Permalink
Merge pull request #1070 from arturcic/main
Browse files Browse the repository at this point in the history
Check for shallow clone for GitVersion execute action/task
  • Loading branch information
arturcic authored Mar 11, 2024
2 parents 6e5f96b + 6b1df7a commit a5ea5ba
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 48 deletions.
1 change: 1 addition & 0 deletions .azure/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:

steps:
- checkout: self
displayName: Checkout
fetchDepth: '0'
- pwsh: |
npm install
Expand Down
4 changes: 2 additions & 2 deletions dist/azure/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/azure/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/azure/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/azure/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/azure/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/azure/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/azure/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/azure/gitversion/execute/bundle.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/azure/gitversion/setup/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/github/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/github/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/github/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/github/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/github/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/github/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/github/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/github/gitversion/execute/bundle.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/github/gitversion/setup/bundle.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions docs/cloning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
In order for the gitversion to properly work you need to clone the repository with the entire history:

```yaml
# GitHub Actions syntax
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
```
```yaml
# Azure DevOps syntax
steps:
- checkout: self
displayName: Checkout
fetchDepth: '0'
```
2 changes: 1 addition & 1 deletion docs/examples/github/gitversion/setup/usage-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ In order for the gitversion to properly work you need to clone the repository wi
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
```
Expand Down
3 changes: 2 additions & 1 deletion src/core/dotnet-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ISetupSettings } from '../tools/common/models'

export interface IDotnetTool {
disableTelemetry(): void

toolInstall(toolName: string, versionRange: string, setupSettings: ISetupSettings): Promise<string>
}

Expand Down Expand Up @@ -54,7 +55,7 @@ export class DotnetTool implements IDotnetTool {
if (!this.versionManager.satisfies(version, versionRange, { includePrerelease: setupSettings.includePrerelease })) {
throw new Error(
`Version spec '${setupSettings.versionSpec}' resolved as '${version}' does not satisfy the range '${versionRange}'.` +
'Check https://raw.githubusercontent.com/GitTools/actions/main/docs/versions.md for more information'
'See https://github.com/GitTools/actions/blob/main/docs/versions.md for more information.'
)
}

Expand Down
10 changes: 8 additions & 2 deletions src/tools/gitversion/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
await this.toolInstall('GitVersion.Tool', '>=5.2.0 <6.1.0', setupSettings)
}

public run(options: GitVersionSettings): Promise<IExecResult> {
public async run(options: GitVersionSettings): Promise<IExecResult> {
const isShallowResult = await this.execute('git', ['rev-parse', '--is-shallow-repository'])
if (isShallowResult.code === 0 && isShallowResult.stdout.trim() === 'true') {
throw new Error(
'The repository is shallow. Consider disabling shallow clones. See https://github.com/GitTools/actions/blob/main/docs/cloning.md for more information.'
)
}
const workDir = this.getRepoDir(options)

const args = this.getArguments(workDir, options)

return this.execute('dotnet-gitversion', args)
return await this.execute('dotnet-gitversion', args)
}

private getRepoDir(options: GitVersionSettings): string {
Expand Down

0 comments on commit a5ea5ba

Please sign in to comment.