|
| 1 | +import tl = require('vsts-task-lib/task'); |
| 2 | +import { IExecOptions, ToolRunner } from 'vsts-task-lib/toolrunner'; |
| 3 | +import path = require('path'); |
| 4 | +import q = require('q'); |
| 5 | +import os = require('os'); |
| 6 | + |
| 7 | +var updateAssemblyInfo = tl.getBoolInput('updateAssemblyInfo'); |
| 8 | +var updateAssemblyInfoFilename = tl.getInput('updateAssemblyInfoFilename'); |
| 9 | +var additionalArguments = tl.getInput('additionalArguments'); |
| 10 | +var gitVersionPath = tl.getInput('gitVersionPath'); |
| 11 | +var preferBundledVersion = tl.getBoolInput('preferBundledVersion'); |
| 12 | + |
| 13 | +var currentDirectory = __dirname; |
| 14 | + |
| 15 | +var sourcesDirectory = tl.getVariable("Build.SourcesDirectory") |
| 16 | + |
| 17 | +if (!gitVersionPath) { |
| 18 | + gitVersionPath = tl.which("GitVersion.exe"); |
| 19 | + if (preferBundledVersion || !gitVersionPath) { |
| 20 | + gitVersionPath = path.join(currentDirectory, "GitVersion.exe"); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +(async function execute() { |
| 25 | + try { |
| 26 | + |
| 27 | + var execOptions: IExecOptions = { |
| 28 | + cwd: undefined, |
| 29 | + env: undefined, |
| 30 | + silent: undefined, |
| 31 | + failOnStdErr: undefined, |
| 32 | + ignoreReturnCode: undefined, |
| 33 | + errStream: undefined, |
| 34 | + outStream: undefined, |
| 35 | + windowsVerbatimArguments: undefined |
| 36 | + }; |
| 37 | + |
| 38 | + var toolRunner: ToolRunner; |
| 39 | + |
| 40 | + var isWin32 = os.platform() == "win32"; |
| 41 | + |
| 42 | + if (isWin32) { |
| 43 | + toolRunner = tl.tool(gitVersionPath); |
| 44 | + } else { |
| 45 | + toolRunner = tl.tool("mono"); |
| 46 | + toolRunner.arg(gitVersionPath); |
| 47 | + } |
| 48 | + |
| 49 | + toolRunner.arg([ |
| 50 | + sourcesDirectory, |
| 51 | + "/output", |
| 52 | + "buildserver", |
| 53 | + "/nofetch" |
| 54 | + ]); |
| 55 | + |
| 56 | + if (updateAssemblyInfo) { |
| 57 | + toolRunner.arg("/updateassemblyinfo") |
| 58 | + if (updateAssemblyInfoFilename) { |
| 59 | + toolRunner.arg(updateAssemblyInfoFilename); |
| 60 | + } else { |
| 61 | + toolRunner.arg("true"); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + if (additionalArguments) { |
| 66 | + toolRunner.line(additionalArguments); |
| 67 | + } |
| 68 | + |
| 69 | + var result = await toolRunner.exec(execOptions); |
| 70 | + if (result) { |
| 71 | + tl.setResult(tl.TaskResult.Failed, "An error occured during GitVersion execution") |
| 72 | + } else { |
| 73 | + tl.setResult(tl.TaskResult.Succeeded, "GitVersion executed successfully") |
| 74 | + } |
| 75 | + } |
| 76 | + catch (err) { |
| 77 | + tl.debug(err.stack) |
| 78 | + tl.setResult(tl.TaskResult.Failed, err); |
| 79 | + } |
| 80 | +})(); |
0 commit comments