diff --git a/.azure/ci.yml b/.azure/ci.yml
index edfc7d796..ef020df90 100644
--- a/.azure/ci.yml
+++ b/.azure/ci.yml
@@ -71,6 +71,24 @@ jobs:
node gitversion/setup/main.mjs
displayName: gitversion/setup
workingDirectory: dist/vsix
+ - pwsh: |
+ # set the inputs for the 'gitversion/command' action
+ $env:INPUT_TARGETPATH = './'
+ $env:INPUT_ARGUMENTS = '/showvariable FullSemVer'
+
+ # run the 'gitversion/command' action
+ node gitversion/command/main.mjs
+ displayName: gitversion/command (showvariable)
+ workingDirectory: dist/vsix
+ - pwsh: |
+ # set the inputs for the 'gitversion/command' action
+ $env:INPUT_TARGETPATH = './'
+ $env:INPUT_ARGUMENTS = '/format {Major}.{Minor}'
+
+ # run the 'gitversion/command' action
+ node gitversion/command/main.mjs
+ displayName: gitversion/command (format)
+ workingDirectory: dist/vsix
- pwsh: |
# set the inputs for the 'gitversion/execute' action
$env:INPUT_TARGETPATH = './'
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 287c89dbf..d87ebe1a0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -54,6 +54,14 @@ jobs:
uses: ./gitversion/setup
with:
versionSpec: '6.x'
+ - name: gitversion/command (showvariable)
+ uses: ./gitversion/command
+ with:
+ arguments: '/showvariable FullSemVer'
+ - name: gitversion/command (format)
+ uses: ./gitversion/command
+ with:
+ arguments: '/format {Major}.{Minor}'
- name: gitversion/execute
id: gitversion # step id used as reference for output values
uses: ./gitversion/execute
diff --git a/dist/azure/gitversion/command/icon.png b/dist/azure/gitversion/command/icon.png
new file mode 100644
index 000000000..22b958c98
Binary files /dev/null and b/dist/azure/gitversion/command/icon.png differ
diff --git a/dist/azure/gitversion/command/main.mjs b/dist/azure/gitversion/command/main.mjs
new file mode 100644
index 000000000..7116bee93
--- /dev/null
+++ b/dist/azure/gitversion/command/main.mjs
@@ -0,0 +1,2 @@
+import { run } from './tools/lib.mjs'
+await run('azure', 'gitversion', 'command')
diff --git a/dist/azure/gitversion/command/task.json b/dist/azure/gitversion/command/task.json
new file mode 100644
index 000000000..bdd931097
--- /dev/null
+++ b/dist/azure/gitversion/command/task.json
@@ -0,0 +1,51 @@
+{
+ "id": "41dc3dd2-6a51-4ba5-a889-824274acca8b",
+ "name": "gitversion/command",
+ "friendlyName": "Command GitVersion Task",
+ "description": "Easy Semantic Versioning (https://semver.org) for projects using Git",
+ "author": "GitTools Contributors",
+ "helpMarkDown": "See the [documentation](https://gitversion.net/docs/) for help",
+ "category": "Build",
+ "demands": [],
+ "version": {
+ "Major": 0,
+ "Minor": 0,
+ "Patch": 1
+ },
+ "minimumAgentVersion": "3.224.0",
+ "execution": {
+ "Node20_1": {
+ "target": "main.mjs",
+ "argumentFormat": "",
+ "workingDirectory": "."
+ }
+ },
+ "instanceNameFormat": "gitversion/command",
+ "inputs": [
+ {
+ "name": "targetPath",
+ "type": "string",
+ "label": "Working directory path",
+ "defaultValue": "",
+ "required": false,
+ "helpMarkDown": "Optionally supply the path to the working directory",
+ "groupName": "gitversionDetails"
+ },
+ {
+ "name": "disableShallowCloneCheck",
+ "type": "boolean",
+ "label": "Disable Shallow Clone Check",
+ "defaultValue": "false",
+ "required": false,
+ "helpMarkDown": "Whether to disable GitVersion shallow clone check"
+ },
+ {
+ "name": "arguments",
+ "type": "string",
+ "label": "GitVersion arguments",
+ "defaultValue": "",
+ "required": true,
+ "helpMarkDown": "Arguments to send to GitVersion"
+ }
+ ]
+}
diff --git a/dist/azure/manifest.config.cjs b/dist/azure/manifest.config.cjs
index f1510fe27..5489962a8 100644
--- a/dist/azure/manifest.config.cjs
+++ b/dist/azure/manifest.config.cjs
@@ -5,7 +5,8 @@ module.exports = (env) => {
const gitversion = [
{ id: 'setup', path: 'gitversion/setup' },
- { id: 'execute', path: 'gitversion/execute' }
+ { id: 'execute', path: 'gitversion/execute' },
+ { id: 'command', path: 'gitversion/command' }
]
const gitreleasemanager = [
diff --git a/dist/azure/tasks.json b/dist/azure/tasks.json
index 898d764b0..878f70f4d 100644
--- a/dist/azure/tasks.json
+++ b/dist/azure/tasks.json
@@ -7,6 +7,10 @@
"execute": {
"test": "9b58ed30-0deb-4083-b007-5f6ce7787544",
"prod": "9013cf7f-ee8d-49f4-a39b-db244928d391"
+ },
+ "command": {
+ "test": "b5559270-0af3-49c8-bde3-c44847a8503b",
+ "prod": "41dc3dd2-6a51-4ba5-a889-824274acca8b"
}
},
"gitreleasemanager": {
diff --git a/docs/examples/azure/gitversion/command.md b/docs/examples/azure/gitversion/command.md
new file mode 100644
index 000000000..b3615660d
--- /dev/null
+++ b/docs/examples/azure/gitversion/command.md
@@ -0,0 +1,95 @@
+# Command GitVersion Task (gitversion/command) usage Examples
+
+Find out how to use the **gitversion/command** task using the examples below.
+
+Note that if the pipeline is set up to use a shallow git fetch mode the GitVersion Command task will fail. It is required to use `fetchDepth: 0`.
+You must also run the GitVersion Setup step before the Command step:
+
+```yaml
+steps:
+ - checkout: self
+ fetchDepth: 0
+
+ - task: gitversion/setup@2.0.1
+ displayName: Install GitVersion
+ inputs:
+ versionSpec: '6.x'
+```
+
+These steps are omitted from the examples for brevity.
+
+> The examples use version _2.0.1_ of the GitVersion Command task. It is recommended to use the latest released version in your own workflows.
+
+## Inputs
+
+The Command GitVersion task accepts the following inputs:
+
+```yaml
+targetPath:
+ description: Optionally supply the path to the working directory
+ required: false
+ default: ''
+disableShallowCloneCheck:
+ description: Whether to disable the check for shallow clone
+ required: false
+ default: 'false'
+arguments:
+ description: Arguments to send to GitVersion
+ required: true
+ default: ''
+```
+
+---
+
+## Execution Examples
+
+### Example 1
+
+
+ Show the effective configuration for GitVersion by running the /showConfig command.
+
+```yaml
+steps:
+ # gitversion/setup@2.0.1 task omitted for brevity.
+
+ - task: gitversion/command@2.0.1
+ displayName: Display GitVersion config
+ inputs:
+ arguments: '/showConfig'
+```
+
+
+
+### Example 2
+
+
+ Outputs the FullSemVer variable by running the /showvariable FullSemVer command.
+
+```yaml
+steps:
+ # gitversion/setup@2.0.1 task omitted for brevity.
+
+ - task: gitversion/command@2.0.1
+ displayName: Output the FullSemVer variable
+ inputs:
+ arguments: '/showvariable FullSemVer'
+```
+
+
+
+### Example 3
+
+
+ Outputs the formatted version by running the /format {Major}.{Minor} command.
+
+```yaml
+steps:
+ # gitversion/setup@2.0.1 task omitted for brevity.
+
+ - task: gitversion/command@2.0.1
+ displayName: Output the formatted version
+ inputs:
+ arguments: '/format {Major}.{Minor}' # any Output Variable can be used here
+```
+
+
diff --git a/docs/examples/azure/gitversion/index.md b/docs/examples/azure/gitversion/index.md
index a800b31d6..2dd324663 100644
--- a/docs/examples/azure/gitversion/index.md
+++ b/docs/examples/azure/gitversion/index.md
@@ -11,3 +11,7 @@ Note: You need to run the Setup step before the Execute step, otherwise the Exec
## Execute GitVersion (gitversion/execute)
- [Execute](execute.md)
+
+## Execute GitVersion (gitversion/command)
+
+- [Command](command.md)
diff --git a/docs/examples/github/gitversion/command.md b/docs/examples/github/gitversion/command.md
new file mode 100644
index 000000000..6120dd7ea
--- /dev/null
+++ b/docs/examples/github/gitversion/command.md
@@ -0,0 +1,98 @@
+# Command GitVersion Action (gitversion/command) usage Examples
+
+Find out how to use the **gitversion/command** action using the examples below.
+
+Note that if the pipeline is set up to use a shallow git fetch mode the GitVersion Command action will fail. It is required to use `fetch-depth: 0`.
+You must also run the GitVersion Setup step before the Command step:
+
+```yaml
+steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Install GitVersion
+ uses: gittools/actions/gitversion/setup@v2.0.1
+ with:
+ versionSpec: '6.x'
+```
+
+These steps are omitted from the examples for brevity.
+
+> The examples use version _2.0.1_ of the GitVersion Command action. It is recommended to use the latest released version in your own workflows.
+
+## Inputs
+
+The Command GitVersion action accepts the following inputs:
+
+```yaml
+targetPath:
+ description: Optionally supply the path to the working directory
+ required: false
+ default: ''
+disableShallowCloneCheck:
+ description: Whether to disable the check for shallow clone
+ required: false
+ default: 'false'
+arguments:
+ description: Arguments to send to GitVersion
+ required: true
+ default: ''
+```
+
+---
+
+## Execution Examples
+
+### Example 1
+
+
+ Show the effective configuration for GitVersion by running the /showConfig command.
+
+```yaml
+steps:
+ # gittools/actions/gitversion/setup@v2.0.1 action omitted for brevity.
+
+ - name: Display GitVersion config
+ uses: gittools/actions/gitversion/command@v2.0.1
+ with:
+ useConfigFile: true
+ arguments: '/showConfig'
+```
+
+
+
+### Example 2
+
+
+ Outputs the FullSemVer variable by running the /showvariable FullSemVer command.
+
+```yaml
+steps:
+ # gittools/actions/gitversion/setup@v2.0.1 action omitted for brevity.
+
+ - name: Output the FullSemVer variable
+ uses: gittools/actions/gitversion/command@v2.0.1
+ with:
+ arguments: '/showvariable FullSemVer'
+```
+
+
+
+### Example 3
+
+
+ Outputs the formatted version by running the /format {Major}.{Minor} command.
+
+```yaml
+steps:
+ # gittools/actions/gitversion/setup@v2.0.1 action omitted for brevity.
+
+ - name: Output the formatted version
+ uses: gittools/actions/gitversion/command@v2.0.1
+ with:
+ arguments: '/format {Major}.{Minor}' # any Output Variable can be used here
+```
+
+
diff --git a/docs/examples/github/gitversion/index.md b/docs/examples/github/gitversion/index.md
index 00140a6f6..dd6dbc977 100644
--- a/docs/examples/github/gitversion/index.md
+++ b/docs/examples/github/gitversion/index.md
@@ -11,3 +11,7 @@ Note: You need to run the Setup step before the Execute step, otherwise the Exec
## Execute GitVersion (gitversion/execute)
- [Execute](execute.md)
+
+## Execute GitVersion (gitversion/command)
+
+- [Command](command.md)
diff --git a/envs/gitversion/command/azure.env b/envs/gitversion/command/azure.env
new file mode 100644
index 000000000..e71d298c1
--- /dev/null
+++ b/envs/gitversion/command/azure.env
@@ -0,0 +1,4 @@
+BUILD_SOURCESDIRECTORY=.
+AGENT_TEMPDIRECTORY=./.test/temp
+AGENT_TOOLSDIRECTORY=./.test/tools
+GITVERSION_PATH=./.test/tools/GitVersion.Tool/6.0.0
diff --git a/envs/gitversion/command/github.env b/envs/gitversion/command/github.env
new file mode 100644
index 000000000..5ed0e7ad0
--- /dev/null
+++ b/envs/gitversion/command/github.env
@@ -0,0 +1,4 @@
+GITHUB_WORKSPACE=.
+RUNNER_TEMP=./.test/temp
+RUNNER_TOOL_CACHE=./.test/tools
+GITVERSION_PATH=./.test/tools/GitVersion.Tool/6.0.0
diff --git a/envs/gitversion/command/local.env b/envs/gitversion/command/local.env
new file mode 100644
index 000000000..04df64eac
--- /dev/null
+++ b/envs/gitversion/command/local.env
@@ -0,0 +1,4 @@
+AGENT_SOURCE_DIR=.
+AGENT_TEMP_DIR=./.test/temp
+AGENT_TOOLS_DIR=./.test/tools
+GITVERSION_PATH=./.test/tools/GitVersion.Tool/6.0.0
diff --git a/gitversion/command/action.yml b/gitversion/command/action.yml
new file mode 100644
index 000000000..c0f5d3a84
--- /dev/null
+++ b/gitversion/command/action.yml
@@ -0,0 +1,22 @@
+name: gitversion-command
+description: GitHub Action for Easy Semantic Versioning with GitVersion. Run GitVersion with arguments.
+author: GitTools
+branding:
+ color: gray-dark
+ icon: git-pull-request
+runs:
+ using: node20
+ main: main.mjs
+inputs:
+ targetPath:
+ description: Optionally supply the path to the working directory
+ required: false
+ default: ''
+ disableShallowCloneCheck:
+ description: Whether to disable the check for shallow clone
+ required: false
+ default: 'false'
+ arguments:
+ description: Arguments to send to GitVersion
+ required: true
+ default: ''
diff --git a/gitversion/command/main.mjs b/gitversion/command/main.mjs
new file mode 100644
index 000000000..1b6f0e16f
--- /dev/null
+++ b/gitversion/command/main.mjs
@@ -0,0 +1,2 @@
+import { run } from '../../dist/tools/lib.mjs'
+await run('github', 'gitversion', 'command')
diff --git a/src/__tests__/tools/gitversion/runner.spec.ts b/src/__tests__/tools/gitversion/runner.spec.ts
index 8beb1e83a..2e86f1306 100644
--- a/src/__tests__/tools/gitversion/runner.spec.ts
+++ b/src/__tests__/tools/gitversion/runner.spec.ts
@@ -73,6 +73,32 @@ describe('GitVersion Runner', () => {
expect(result.stdout).toContain('Executing GenerateSetVersionMessage')
expect(result.stdout).toContain('Executing GenerateBuildLogOutput')
})
+
+ it.sequential('should output Major variable', async () => {
+ setEnv(toolPathVariable, toolPath)
+
+ setInputs({
+ arguments: '/showvariable major'
+ })
+
+ const result = await runner.run('command')
+
+ expect(result.code).toBe(0)
+ expect(result.stdout).toContain('2')
+ })
+
+ it.sequential('should output formatted version', async () => {
+ setEnv(toolPathVariable, toolPath)
+
+ setInputs({
+ arguments: '/format {Major}.{Minor}'
+ })
+
+ const result = await runner.run('command')
+
+ expect(result.code).toBe(0)
+ expect(result.stdout).toContain('2.0')
+ })
}
describe('Local Agent', () => {
diff --git a/src/__tests__/tools/gitversion/settings.spec.ts b/src/__tests__/tools/gitversion/settings.spec.ts
index 2d7693f4e..0fd25ef4a 100644
--- a/src/__tests__/tools/gitversion/settings.spec.ts
+++ b/src/__tests__/tools/gitversion/settings.spec.ts
@@ -1,6 +1,6 @@
import { describe, it } from 'vitest'
import { IBuildAgent } from '@agents/common'
-import { type GitVersionExecuteSettings, GitVersionSettingsProvider } from '@tools/gitversion'
+import { type GitVersionCommandSettings, type GitVersionExecuteSettings, GitVersionSettingsProvider } from '@tools/gitversion'
import { expectValidSettings } from '../common/utils'
describe('GitVersion settings', () => {
@@ -29,4 +29,23 @@ describe('GitVersion settings', () => {
expectValidSettings(settings, gitVersionExecuteSettings)
})
+
+ it('should return GitVersionCommandSettings', () => {
+ const settings: GitVersionCommandSettings = {
+ targetPath: 'path',
+ disableShallowCloneCheck: true,
+ arguments: 'args'
+ }
+
+ const buildAgent = {
+ getInput: (input: keyof GitVersionCommandSettings) => settings[input] as string,
+ getBooleanInput: (input: keyof GitVersionCommandSettings) => settings[input] as boolean
+ } as IBuildAgent
+
+ const settingsProvider = new GitVersionSettingsProvider(buildAgent)
+
+ const gitVersionCommandSettings = settingsProvider.getGitVersionCommandSettings()
+
+ expectValidSettings(settings, gitVersionCommandSettings)
+ })
})
diff --git a/src/__tests__/tools/gitversion/tool.spec.ts b/src/__tests__/tools/gitversion/tool.spec.ts
index 1f7fa071c..ca12146b7 100644
--- a/src/__tests__/tools/gitversion/tool.spec.ts
+++ b/src/__tests__/tools/gitversion/tool.spec.ts
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { IBuildAgent } from '@agents/common'
-import { type GitVersionOutput, type GitVersionExecuteSettings, GitVersionTool } from '@tools/gitversion'
+import { type GitVersionOutput, type GitVersionCommandSettings, type GitVersionExecuteSettings, GitVersionTool } from '@tools/gitversion'
class TestGitVersionTool extends GitVersionTool {
private _isValidInputFile = false
@@ -13,13 +13,17 @@ class TestGitVersionTool extends GitVersionTool {
return Promise.resolve(this._isValidInputFile)
}
- async getRepoDir(settings: GitVersionExecuteSettings): Promise {
+ async getRepoDir(settings: GitVersionExecuteSettings | GitVersionCommandSettings): Promise {
return super.getRepoDir(settings)
}
async getExecuteArguments(workDir: string, options: GitVersionExecuteSettings): Promise {
return super.getExecuteArguments(workDir, options)
}
+
+ async getCommandArguments(workDir: string, options: GitVersionCommandSettings): Promise {
+ return super.getCommandArguments(workDir, options)
+ }
}
describe('GitVersionTool', () => {
@@ -101,7 +105,7 @@ describe('GitVersionTool', () => {
tool = new TestGitVersionTool(buildAgent)
const repoDir = await tool.getRepoDir({
targetPath: ''
- } as GitVersionExecuteSettings)
+ } as GitVersionExecuteSettings | GitVersionCommandSettings)
expect(repoDir).toBe('workdir')
})
@@ -112,7 +116,7 @@ describe('GitVersionTool', () => {
tool = new TestGitVersionTool(buildAgent)
const repoDir = await tool.getRepoDir({
targetPath: ''
- } as GitVersionExecuteSettings)
+ } as GitVersionExecuteSettings | GitVersionCommandSettings)
expect(repoDir).toBe('.')
})
@@ -125,7 +129,7 @@ describe('GitVersionTool', () => {
tool = new TestGitVersionTool(buildAgent)
const repoDir = await tool.getRepoDir({
targetPath: 'targetDir'
- } as GitVersionExecuteSettings)
+ } as GitVersionExecuteSettings | GitVersionCommandSettings)
expect(repoDir).toBe('targetDir')
})
@@ -140,7 +144,7 @@ describe('GitVersionTool', () => {
await expect(
tool.getRepoDir({
targetPath: wrongDir
- } as GitVersionExecuteSettings)
+ } as GitVersionExecuteSettings | GitVersionCommandSettings)
).rejects.toThrowError(`Directory not found at ${wrongDir}`)
})
})
@@ -243,4 +247,18 @@ describe('GitVersionTool', () => {
])
})
})
+
+ describe('getCommandArguments', () => {
+ it('should return correct arguments for empty settings', async () => {
+ const args = await tool.getCommandArguments('workdir', {} as GitVersionCommandSettings)
+ expect(args).toEqual(['workdir'])
+ })
+
+ it('should return correct arguments for settings with additional arguments', async () => {
+ const args = await tool.getCommandArguments('workdir', {
+ arguments: '--some-arg --another-arg'
+ } as GitVersionCommandSettings)
+ expect(args).toEqual(['workdir', '--some-arg', '--another-arg'])
+ })
+ })
})
diff --git a/src/tools/gitversion/models.ts b/src/tools/gitversion/models.ts
index 844f3a133..dc22969f7 100644
--- a/src/tools/gitversion/models.ts
+++ b/src/tools/gitversion/models.ts
@@ -1,4 +1,4 @@
-export type Commands = 'setup' | 'execute'
+export type Commands = 'setup' | 'execute' | 'command'
export enum ExecuteFields {
targetPath = 'targetPath',
@@ -12,6 +12,12 @@ export enum ExecuteFields {
updateAssemblyInfoFilename = 'updateAssemblyInfoFilename'
}
+export enum CommandFields {
+ targetPath = 'targetPath',
+ disableShallowCloneCheck = 'disableShallowCloneCheck',
+ arguments = 'arguments'
+}
+
export type GitVersionExecuteSettings = {
[ExecuteFields.targetPath]: string
[ExecuteFields.disableCache]: boolean
@@ -24,6 +30,12 @@ export type GitVersionExecuteSettings = {
[ExecuteFields.updateAssemblyInfoFilename]: string
}
+export type GitVersionCommandSettings = {
+ [CommandFields.targetPath]: string
+ [ExecuteFields.disableShallowCloneCheck]: boolean
+ [CommandFields.arguments]: string
+}
+
export type GitVersionOutput = {
Major: number
Minor: number
diff --git a/src/tools/gitversion/runner.ts b/src/tools/gitversion/runner.ts
index 689fa0ab0..410e2feb6 100644
--- a/src/tools/gitversion/runner.ts
+++ b/src/tools/gitversion/runner.ts
@@ -16,6 +16,8 @@ export class Runner implements IRunner {
return await this.setup()
case 'execute':
return await this.execute()
+ case 'command':
+ return await this.command()
}
}
@@ -97,6 +99,44 @@ export class Runner implements IRunner {
}
}
+ private async command(): Promise {
+ try {
+ this.disableTelemetry()
+
+ this.buildAgent.info('Executing GitVersion')
+
+ const result = await this.gitVersionTool.executeCommand()
+
+ if (result.code === 0) {
+ this.buildAgent.info('GitVersion executed successfully')
+ const stdout = result.stdout as string
+
+ this.buildAgent.info('GitVersion output:')
+ this.buildAgent.info('-------------------')
+ this.buildAgent.info(stdout)
+ this.buildAgent.info('-------------------')
+
+ this.buildAgent.setSucceeded('GitVersion executed successfully', true)
+ return result
+ } else {
+ this.buildAgent.debug('GitVersion failed')
+ const error = result.error
+ if (error instanceof Error) {
+ this.buildAgent.setFailed(error.message, true)
+ }
+ return result
+ }
+ } catch (error) {
+ if (error instanceof Error) {
+ this.buildAgent.setFailed(error.message, true)
+ }
+ return {
+ code: -1,
+ error
+ }
+ }
+ }
+
private disableTelemetry(): void {
this.buildAgent.info(`Running on: '${this.buildAgent.agentName}'`)
this.buildAgent.debug('Disabling telemetry')
diff --git a/src/tools/gitversion/settings.ts b/src/tools/gitversion/settings.ts
index 251cab408..93bec300d 100644
--- a/src/tools/gitversion/settings.ts
+++ b/src/tools/gitversion/settings.ts
@@ -1,8 +1,10 @@
import { type ISettingsProvider, SettingsProvider } from '@tools/common'
-import { ExecuteFields, type GitVersionExecuteSettings } from './models'
+import { CommandFields, ExecuteFields, type GitVersionCommandSettings, type GitVersionExecuteSettings } from './models'
export interface IGitVersionSettingsProvider extends ISettingsProvider {
getGitVersionExecuteSettings(): GitVersionExecuteSettings
+
+ getGitVersionCommandSettings(): GitVersionCommandSettings
}
export class GitVersionSettingsProvider extends SettingsProvider implements IGitVersionSettingsProvider {
@@ -32,4 +34,16 @@ export class GitVersionSettingsProvider extends SettingsProvider implements IGit
updateAssemblyInfoFilename
}
}
+
+ getGitVersionCommandSettings(): GitVersionCommandSettings {
+ const targetPath = this.buildAgent.getInput(CommandFields.targetPath)
+ const disableShallowCloneCheck = this.buildAgent.getBooleanInput(CommandFields.disableShallowCloneCheck)
+ const args = this.buildAgent.getInput(CommandFields.arguments)
+
+ return {
+ targetPath,
+ disableShallowCloneCheck,
+ arguments: args
+ }
+ }
}
diff --git a/src/tools/gitversion/tool.ts b/src/tools/gitversion/tool.ts
index 5ba1fbc9f..b48b155e9 100644
--- a/src/tools/gitversion/tool.ts
+++ b/src/tools/gitversion/tool.ts
@@ -1,6 +1,6 @@
import { type ExecResult } from '@agents/common'
import { DotnetTool, keysOf } from '@tools/common'
-import { type GitVersionExecuteSettings, type GitVersionOutput } from './models'
+import { type GitVersionCommandSettings, type GitVersionExecuteSettings, type GitVersionOutput } from './models'
import { GitVersionSettingsProvider, type IGitVersionSettingsProvider } from './settings'
export class GitVersionTool extends DotnetTool {
@@ -36,6 +36,18 @@ export class GitVersionTool extends DotnetTool {
return await this.executeTool(args)
}
+ async executeCommand(): Promise {
+ const settings = this.settingsProvider.getGitVersionCommandSettings()
+ const workDir = await this.getRepoDir(settings)
+
+ await this.checkShallowClone(settings, workDir)
+
+ const args = await this.getCommandArguments(workDir, settings)
+
+ await this.setDotnetRoot()
+ return await this.executeTool(args)
+ }
+
writeGitVersionToAgent(output: GitVersionOutput): void {
for (const property of keysOf(output)) {
const name = this.toCamelCase(property)
@@ -54,7 +66,7 @@ export class GitVersionTool extends DotnetTool {
}
}
- protected async getRepoDir(settings: GitVersionExecuteSettings): Promise {
+ protected async getRepoDir(settings: GitVersionExecuteSettings | GitVersionCommandSettings): Promise {
return await super.getRepoPath(settings.targetPath)
}
@@ -113,6 +125,15 @@ export class GitVersionTool extends DotnetTool {
return args
}
+ protected async getCommandArguments(workDir: string, options: GitVersionCommandSettings): Promise {
+ let args = [workDir]
+
+ if (options.arguments) {
+ args = args.concat(this.argStringToArray(options.arguments))
+ }
+ return args
+ }
+
private argStringToArray(argString: string): string[] {
const args: string[] = []
@@ -175,7 +196,7 @@ export class GitVersionTool extends DotnetTool {
return args
}
- private async checkShallowClone(settings: GitVersionExecuteSettings, workDir: string): Promise {
+ private async checkShallowClone(settings: GitVersionExecuteSettings | GitVersionCommandSettings, workDir: string): Promise {
if (!settings.disableShallowCloneCheck) {
const isShallowResult = await this.execute('git', ['-C', workDir, 'rev-parse', '--is-shallow-repository'])
if (isShallowResult.code === 0 && isShallowResult.stdout.trim() === 'true') {