Revert "Merge pull request #812 from GitTools/bug/prerelease"
This reverts commit a6b18fd71f.
This commit is contained in:
@@ -24,7 +24,12 @@ class BuildAgent implements IBuildAgent {
|
||||
return toolLib.findLocalTool(toolName, versionSpec, arch)
|
||||
}
|
||||
|
||||
public cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string> {
|
||||
public cacheDir(
|
||||
sourceDir: string,
|
||||
tool: string,
|
||||
version: string,
|
||||
arch?: string
|
||||
): Promise<string> {
|
||||
return toolLib.cacheDir(sourceDir, tool, version, arch)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,10 @@ import * as toolCache from '@actions/tool-cache'
|
||||
import { injectable } from 'inversify'
|
||||
|
||||
import { IBuildAgent, IExecResult } from '../../core/models'
|
||||
import { IRequestOptions, IProxyConfiguration } from 'typed-rest-client/Interfaces'
|
||||
import {
|
||||
IRequestOptions,
|
||||
IProxyConfiguration
|
||||
} from 'typed-rest-client/Interfaces'
|
||||
|
||||
@injectable()
|
||||
class BuildAgent implements IBuildAgent {
|
||||
@@ -55,7 +58,12 @@ class BuildAgent implements IBuildAgent {
|
||||
return undefined
|
||||
}
|
||||
|
||||
let proxyURL = process.env.HTTP_PROXY || process.env.http_proxy || process.env.HTTPS_PROXY || process.env.https_proxy || null
|
||||
let proxyURL =
|
||||
process.env.HTTP_PROXY ||
|
||||
process.env.http_proxy ||
|
||||
process.env.HTTPS_PROXY ||
|
||||
process.env.https_proxy ||
|
||||
null
|
||||
|
||||
if (proxyURL) {
|
||||
let url = new urlApi.URL(requestedUrl)
|
||||
@@ -70,7 +78,12 @@ class BuildAgent implements IBuildAgent {
|
||||
return undefined
|
||||
}
|
||||
|
||||
public cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string> {
|
||||
public cacheDir(
|
||||
sourceDir: string,
|
||||
tool: string,
|
||||
version: string,
|
||||
arch?: string
|
||||
): Promise<string> {
|
||||
return toolCache.cacheDir(sourceDir, tool, version, arch)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,12 @@ class BuildAgent implements IBuildAgent {
|
||||
return 'find'
|
||||
}
|
||||
|
||||
public cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string> {
|
||||
public cacheDir(
|
||||
sourceDir: string,
|
||||
tool: string,
|
||||
version: string,
|
||||
arch?: string
|
||||
): Promise<string> {
|
||||
console.log('cacheDir')
|
||||
return Promise.resolve('cacheDir')
|
||||
}
|
||||
|
||||
@@ -4,13 +4,16 @@ import * as path from 'path'
|
||||
import * as http from 'typed-rest-client/HttpClient'
|
||||
|
||||
import { inject, injectable } from 'inversify'
|
||||
import { TYPES, IExecResult, IBuildAgent } from './models'
|
||||
import { TYPES, IExecResult, IBuildAgent, ISetupSettings } from './models'
|
||||
import { IVersionManager } from './versionManager'
|
||||
import { ISetupSettings } from '../tools/common/models'
|
||||
|
||||
export interface IDotnetTool {
|
||||
disableTelemetry(): void
|
||||
toolInstall(toolName: string, checkLatest: boolean, setupSettings: ISetupSettings): Promise<string>
|
||||
toolInstall(
|
||||
toolName: string,
|
||||
checkLatest: boolean,
|
||||
setupSettings: ISetupSettings
|
||||
): Promise<string>
|
||||
}
|
||||
|
||||
@injectable()
|
||||
@@ -19,12 +22,20 @@ export class DotnetTool implements IDotnetTool {
|
||||
protected versionManager: IVersionManager
|
||||
private httpClient: http.HttpClient
|
||||
|
||||
private static readonly nugetRoot: string = 'https://azuresearch-usnc.nuget.org/'
|
||||
private static readonly nugetRoot: string =
|
||||
'https://api-v2v3search-0.nuget.org/'
|
||||
|
||||
constructor(@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent, @inject(TYPES.IVersionManager) versionManager: IVersionManager) {
|
||||
constructor(
|
||||
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
||||
@inject(TYPES.IVersionManager) versionManager: IVersionManager
|
||||
) {
|
||||
this.buildAgent = buildAgent
|
||||
this.versionManager = versionManager
|
||||
this.httpClient = new http.HttpClient('dotnet', undefined, this.buildAgent.proxyConfiguration(DotnetTool.nugetRoot))
|
||||
this.httpClient = new http.HttpClient(
|
||||
'dotnet',
|
||||
undefined,
|
||||
this.buildAgent.proxyConfiguration(DotnetTool.nugetRoot)
|
||||
)
|
||||
}
|
||||
|
||||
public disableTelemetry(): void {
|
||||
@@ -37,16 +48,20 @@ export class DotnetTool implements IDotnetTool {
|
||||
return this.buildAgent.exec(cmd, args)
|
||||
}
|
||||
|
||||
public async toolInstall(toolName: string, checkLatest: boolean, setupSettings: ISetupSettings): Promise<string> {
|
||||
public async toolInstall(
|
||||
toolName: string,
|
||||
checkLatest: boolean,
|
||||
setupSettings: ISetupSettings
|
||||
): Promise<string> {
|
||||
console.log('')
|
||||
console.log('--------------------------')
|
||||
console.log(`Acquiring ${toolName} version spec: ${setupSettings.versionSpec}`)
|
||||
console.log(
|
||||
`Installing ${toolName} version ` + setupSettings.versionSpec
|
||||
)
|
||||
console.log('--------------------------')
|
||||
|
||||
let version: string
|
||||
if (this.versionManager.isExplicitVersion(setupSettings.versionSpec)) {
|
||||
checkLatest = false // check latest doesn't make sense when explicit version
|
||||
version = setupSettings.versionSpec
|
||||
}
|
||||
|
||||
let toolPath: string
|
||||
@@ -58,7 +73,10 @@ export class DotnetTool implements IDotnetTool {
|
||||
}
|
||||
|
||||
if (!toolPath) {
|
||||
if (this.versionManager.isExplicitVersion(setupSettings.versionSpec)) {
|
||||
let version: string
|
||||
if (
|
||||
this.versionManager.isExplicitVersion(setupSettings.versionSpec)
|
||||
) {
|
||||
//
|
||||
// Explicit version was specified. No need to query for list of versions.
|
||||
//
|
||||
@@ -70,9 +88,15 @@ export class DotnetTool implements IDotnetTool {
|
||||
// If your tool doesn't offer a mechanism to query,
|
||||
// then it can only support exact version inputs.
|
||||
//
|
||||
version = await this.queryLatestMatch(toolName, setupSettings.versionSpec, setupSettings.includePrerelease)
|
||||
version = await this.queryLatestMatch(
|
||||
toolName,
|
||||
setupSettings.versionSpec,
|
||||
setupSettings.includePrerelease
|
||||
)
|
||||
if (!version) {
|
||||
throw new Error(`Unable to find ${toolName} version '${setupSettings.versionSpec}'.`)
|
||||
throw new Error(
|
||||
`Unable to find ${toolName} version '${setupSettings.versionSpec}'.`
|
||||
)
|
||||
}
|
||||
|
||||
//
|
||||
@@ -84,20 +108,24 @@ export class DotnetTool implements IDotnetTool {
|
||||
//
|
||||
// Download, extract, cache
|
||||
//
|
||||
toolPath = await this.acquireTool(toolName, version, setupSettings.ignoreFailedSources)
|
||||
toolPath = await this.acquireTool(
|
||||
toolName,
|
||||
version,
|
||||
setupSettings.ignoreFailedSources
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('--------------------------')
|
||||
console.log(`${toolName} version: ${version} installed.`)
|
||||
console.log('--------------------------')
|
||||
//
|
||||
// Prepend the tools path. This prepends the PATH for the current process and
|
||||
// instructs the agent to prepend for each task that follows.
|
||||
//
|
||||
this.buildAgent.debug(`toolPath: ${toolPath}`)
|
||||
|
||||
if (os.platform() !== 'win32' && !this.buildAgent.getVariable('DOTNET_ROOT')) {
|
||||
if (
|
||||
os.platform() !== 'win32' &&
|
||||
!this.buildAgent.getVariable('DOTNET_ROOT')
|
||||
) {
|
||||
let dotnetPath = await this.buildAgent.which('dotnet')
|
||||
dotnetPath = fs.readlinkSync(dotnetPath) || dotnetPath
|
||||
const dotnetRoot = path.dirname(dotnetPath)
|
||||
@@ -108,14 +136,22 @@ export class DotnetTool implements IDotnetTool {
|
||||
return toolPath
|
||||
}
|
||||
|
||||
private async queryLatestMatch(toolName: string, versionSpec: string, includePrerelease: boolean): Promise<string> {
|
||||
private async queryLatestMatch(
|
||||
toolName: string,
|
||||
versionSpec: string,
|
||||
includePrerelease: boolean
|
||||
): Promise<string> {
|
||||
this.buildAgent.debug(
|
||||
`querying tool versions for ${toolName}${versionSpec ? `@${versionSpec}` : ''} ${includePrerelease ? 'including pre-releases' : ''}`
|
||||
`querying tool versions for ${toolName}${
|
||||
versionSpec ? `@${versionSpec}` : ''
|
||||
} ${includePrerelease ? 'including pre-releases' : ''}`
|
||||
)
|
||||
|
||||
const toolNameParam = encodeURIComponent(toolName.toLowerCase())
|
||||
const prereleaseParam = includePrerelease ? 'true' : 'false'
|
||||
const downloadPath = `${DotnetTool.nugetRoot}query?q=${toolNameParam}&prerelease=${prereleaseParam}&semVerLevel=2.0.0&take=1`
|
||||
const downloadPath = `${
|
||||
DotnetTool.nugetRoot
|
||||
}query?q=${encodeURIComponent(toolName.toLowerCase())}&prerelease=${
|
||||
includePrerelease ? 'true' : 'false'
|
||||
}&semVerLevel=2.0.0`
|
||||
|
||||
const res = await this.httpClient.get(downloadPath)
|
||||
|
||||
@@ -126,19 +162,23 @@ export class DotnetTool implements IDotnetTool {
|
||||
const body: string = await res.readBody()
|
||||
const data = JSON.parse(body).data
|
||||
|
||||
const versions = (data[0].versions as { version: string }[]).map(x => x.version)
|
||||
const versions = (data[0].versions as { version: string }[]).map(
|
||||
x => x.version
|
||||
)
|
||||
if (!versions || !versions.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
this.buildAgent.debug(`got versions: ${versions.join(', ')}`)
|
||||
|
||||
return this.versionManager.evaluateVersions(versions, versionSpec, {
|
||||
includePrerelease
|
||||
})
|
||||
return this.versionManager.evaluateVersions(versions, versionSpec)
|
||||
}
|
||||
|
||||
private async acquireTool(toolName: string, version: string, ignoreFailedSources: boolean): Promise<string> {
|
||||
private async acquireTool(
|
||||
toolName: string,
|
||||
version: string,
|
||||
ignoreFailedSources: boolean
|
||||
): Promise<string> {
|
||||
const tempDirectory = await this.buildAgent.createTempDir()
|
||||
let args = ['tool', 'install', toolName, '--tool-path', tempDirectory]
|
||||
|
||||
|
||||
@@ -5,9 +5,19 @@ export const TYPES = {
|
||||
IDotnetTool: Symbol.for('DotnetTool'),
|
||||
IGitVersionTool: Symbol.for('GitVersionTool'),
|
||||
IGitReleaseManagerTool: Symbol.for('GitReleaseManagerTool'),
|
||||
IVersionManager: Symbol.for('VersionManager'),
|
||||
IGitVersionSettingsProvider: Symbol.for('GitVersionSettingsProvider'),
|
||||
IGitReleaseManagerSettingsProvider: Symbol.for('GitReleaseManagerSettingsProvider')
|
||||
IVersionManager: Symbol.for('VersionManager')
|
||||
}
|
||||
|
||||
export enum SetupFields {
|
||||
includePrerelease = 'includePrerelease',
|
||||
versionSpec = 'versionSpec',
|
||||
ignoreFailedSources = 'ignoreFailedSources'
|
||||
}
|
||||
|
||||
export interface ISetupSettings {
|
||||
[SetupFields.versionSpec]: string
|
||||
[SetupFields.includePrerelease]: boolean
|
||||
[SetupFields.ignoreFailedSources]: boolean
|
||||
}
|
||||
|
||||
export interface IExecResult {
|
||||
@@ -16,11 +26,17 @@ export interface IExecResult {
|
||||
code: number
|
||||
error: Error
|
||||
}
|
||||
|
||||
export interface IBuildAgent {
|
||||
agentName: string
|
||||
proxyConfiguration(url: string): IRequestOptions
|
||||
find(toolName: string, versionSpec: string, arch?: string): string
|
||||
cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string>
|
||||
cacheDir(
|
||||
sourceDir: string,
|
||||
tool: string,
|
||||
version: string,
|
||||
arch?: string
|
||||
): Promise<string>
|
||||
createTempDir(): Promise<string>
|
||||
debug(message: string): void
|
||||
setFailed(message: string, done?: boolean): void
|
||||
|
||||
19
src/core/settings.ts
Normal file
19
src/core/settings.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { IBuildAgent, SetupFields, ISetupSettings } from './models'
|
||||
|
||||
export class Settings {
|
||||
public static getSetupSettings(buildAgent: IBuildAgent): ISetupSettings {
|
||||
const versionSpec = buildAgent.getInput(SetupFields.versionSpec)
|
||||
const includePrerelease = buildAgent.getBooleanInput(
|
||||
SetupFields.includePrerelease
|
||||
)
|
||||
const ignoreFailedSources = buildAgent.getBooleanInput(
|
||||
SetupFields.ignoreFailedSources
|
||||
)
|
||||
|
||||
return {
|
||||
versionSpec,
|
||||
includePrerelease,
|
||||
ignoreFailedSources
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import cmp from 'semver-compare'
|
||||
import * as semver from 'semver'
|
||||
import { injectable, inject } from 'inversify'
|
||||
|
||||
@@ -5,7 +6,7 @@ import { IBuildAgent, TYPES } from './models'
|
||||
|
||||
export interface IVersionManager {
|
||||
isExplicitVersion(versionSpec: string): boolean
|
||||
evaluateVersions(versions: string[], versionSpec: string, optionsOrLoose?: boolean | semver.RangeOptions): string
|
||||
evaluateVersions(versions: string[], versionSpec: string): string
|
||||
cleanVersion(version: string): string
|
||||
}
|
||||
|
||||
@@ -26,13 +27,13 @@ export class VersionManager implements IVersionManager {
|
||||
return valid
|
||||
}
|
||||
|
||||
public evaluateVersions(versions: string[], versionSpec: string, optionsOrLoose?: boolean | semver.RangeOptions): string {
|
||||
public evaluateVersions(versions: string[], versionSpec: string): string {
|
||||
let version: string
|
||||
this.buildAgent.debug('evaluating ' + versions.length + ' versions')
|
||||
versions = semver.sort(versions)
|
||||
versions = versions.sort(cmp)
|
||||
for (let i = versions.length - 1; i >= 0; i--) {
|
||||
const potential: string = versions[i]
|
||||
const satisfied: boolean = semver.satisfies(potential, versionSpec, optionsOrLoose)
|
||||
const satisfied: boolean = semver.satisfies(potential, versionSpec)
|
||||
if (satisfied) {
|
||||
version = potential
|
||||
break
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { addAsset } from './main'
|
||||
|
||||
await addAsset()
|
||||
addAsset()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { close } from './main'
|
||||
|
||||
await close()
|
||||
close()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { create } from './main'
|
||||
|
||||
await create()
|
||||
create()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { discard } from './main'
|
||||
|
||||
await discard()
|
||||
discard()
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
import { IBuildAgent, TYPES } from '../../core/models'
|
||||
import { IGitReleaseManagerTool, GitReleaseManagerTool } from '../../tools/gitreleasemanager/tool'
|
||||
import { IGitReleaseManagerSettingsProvider } from '../../tools/gitreleasemanager/models'
|
||||
import { GitReleaseManagerSettingsProvider } from '../../tools/gitreleasemanager/settings'
|
||||
import {
|
||||
IGitReleaseManagerTool,
|
||||
GitReleaseManagerTool
|
||||
} from '../../tools/gitreleasemanager/tool'
|
||||
import { Settings as CommonSettings } from '../../core/settings'
|
||||
import { Settings } from '../../tools/gitreleasemanager/settings'
|
||||
|
||||
import container from '../../core/ioc'
|
||||
|
||||
container.bind<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool).to(GitReleaseManagerTool)
|
||||
container.bind<IGitReleaseManagerSettingsProvider>(TYPES.IGitReleaseManagerSettingsProvider).to(GitReleaseManagerSettingsProvider)
|
||||
container
|
||||
.bind<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool)
|
||||
.to(GitReleaseManagerTool)
|
||||
|
||||
const gitReleaseManagerTool = container.get<IGitReleaseManagerTool>(
|
||||
TYPES.IGitReleaseManagerTool
|
||||
)
|
||||
const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent)
|
||||
const gitReleaseManagerTool = container.get<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool)
|
||||
const settingsProvider = container.get<IGitReleaseManagerSettingsProvider>(TYPES.IGitReleaseManagerSettingsProvider)
|
||||
|
||||
export async function setup() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = settingsProvider.getSetupSettings()
|
||||
const settings = CommonSettings.getSetupSettings(buildAgent)
|
||||
|
||||
await gitReleaseManagerTool.install(settings)
|
||||
|
||||
buildAgent.setSucceeded('GitVersionManager installed successfully', true)
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager installed successfully',
|
||||
true
|
||||
)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
@@ -30,11 +38,14 @@ export async function create() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = settingsProvider.getCreateSettings()
|
||||
const settings = Settings.getCreateSettings(buildAgent)
|
||||
|
||||
await gitReleaseManagerTool.create(settings)
|
||||
|
||||
buildAgent.setSucceeded('GitVersionManager created release successfully', true)
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager created release successfully',
|
||||
true
|
||||
)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
@@ -44,11 +55,14 @@ export async function discard() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = settingsProvider.getDiscardSettings()
|
||||
const settings = Settings.getDiscardSettings(buildAgent)
|
||||
|
||||
await gitReleaseManagerTool.discard(settings)
|
||||
|
||||
buildAgent.setSucceeded('GitVersionManager discarded release successfully', true)
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager discarded release successfully',
|
||||
true
|
||||
)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
@@ -58,11 +72,14 @@ export async function close() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = settingsProvider.getCloseSettings()
|
||||
const settings = Settings.getCloseSettings(buildAgent)
|
||||
|
||||
await gitReleaseManagerTool.close(settings)
|
||||
|
||||
buildAgent.setSucceeded('GitVersionManager closed release successfully', true)
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager closed release successfully',
|
||||
true
|
||||
)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
@@ -72,11 +89,14 @@ export async function open() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = settingsProvider.getOpenSettings()
|
||||
const settings = Settings.getOpenSettings(buildAgent)
|
||||
|
||||
await gitReleaseManagerTool.open(settings)
|
||||
|
||||
buildAgent.setSucceeded('GitVersionManager opened release successfully', true)
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager opened release successfully',
|
||||
true
|
||||
)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
@@ -86,11 +106,14 @@ export async function publish() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = settingsProvider.getPublishSettings()
|
||||
const settings = Settings.getPublishSettings(buildAgent)
|
||||
|
||||
await gitReleaseManagerTool.publish(settings)
|
||||
|
||||
buildAgent.setSucceeded('GitVersionManager published release successfully', true)
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager published release successfully',
|
||||
true
|
||||
)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
@@ -100,11 +123,14 @@ export async function addAsset() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = settingsProvider.getAddAssetSettings()
|
||||
const settings = Settings.getAddAssetSettings(buildAgent)
|
||||
|
||||
await gitReleaseManagerTool.addAsset(settings)
|
||||
|
||||
buildAgent.setSucceeded('GitVersionManager added assets to release successfully', true)
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager added assets to release successfully',
|
||||
true
|
||||
)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { open } from './main'
|
||||
|
||||
await open()
|
||||
open()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { publish } from './main'
|
||||
|
||||
await publish()
|
||||
publish()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { setup } from './main'
|
||||
|
||||
await setup()
|
||||
setup()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { run } from './main'
|
||||
|
||||
await run()
|
||||
run()
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
import { IBuildAgent, TYPES } from '../../core/models'
|
||||
import { Settings as CommonSettings } from '../../core/settings'
|
||||
import { Settings } from '../../tools/gitversion/settings'
|
||||
import { IGitVersionTool, GitVersionTool } from '../../tools/gitversion/tool'
|
||||
import { GitVersionSettings, GitVersionOutput, IGitVersionSettingsProvider } from '../../tools/gitversion/models'
|
||||
import { GitVersionSettingsProvider } from '../../tools/gitversion/settings'
|
||||
import {
|
||||
GitVersionSettings,
|
||||
GitVersionOutput
|
||||
} from '../../tools/gitversion/models'
|
||||
|
||||
import container from '../../core/ioc'
|
||||
|
||||
container.bind<IGitVersionTool>(TYPES.IGitVersionTool).to(GitVersionTool)
|
||||
container.bind<IGitVersionSettingsProvider>(TYPES.IGitVersionSettingsProvider).to(GitVersionSettingsProvider)
|
||||
|
||||
const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent)
|
||||
const gitVersionTool = container.get<IGitVersionTool>(TYPES.IGitVersionTool)
|
||||
const settingsProvider = container.get<IGitVersionSettingsProvider>(TYPES.IGitVersionSettingsProvider)
|
||||
const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent)
|
||||
|
||||
export async function setup() {
|
||||
try {
|
||||
gitVersionTool.disableTelemetry()
|
||||
console.log(`Agent: '${buildAgent.agentName}'`)
|
||||
|
||||
const settings = settingsProvider.getSetupSettings()
|
||||
const settings = CommonSettings.getSetupSettings(buildAgent)
|
||||
|
||||
await gitVersionTool.install(settings)
|
||||
|
||||
@@ -30,13 +31,17 @@ export async function setup() {
|
||||
export async function run() {
|
||||
try {
|
||||
gitVersionTool.disableTelemetry()
|
||||
console.log(`Agent: '${buildAgent.agentName}'`)
|
||||
|
||||
const settings: GitVersionSettings = settingsProvider.getGitVersionSettings()
|
||||
const settings: GitVersionSettings = Settings.getGitVersionSettings(
|
||||
buildAgent
|
||||
)
|
||||
|
||||
const result = await gitVersionTool.run(settings)
|
||||
const { stdout } = result
|
||||
const jsonOutput = stdout.substring(stdout.lastIndexOf('{'), stdout.lastIndexOf('}') + 1)
|
||||
const jsonOutput = stdout.substring(
|
||||
stdout.lastIndexOf('{'),
|
||||
stdout.lastIndexOf('}') + 1
|
||||
)
|
||||
|
||||
const gitversion = JSON.parse(jsonOutput) as GitVersionOutput
|
||||
gitVersionTool.writeGitVersionToAgent(gitversion)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { setup } from './main'
|
||||
|
||||
await setup()
|
||||
setup()
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
export enum SetupFields {
|
||||
includePrerelease = 'includePrerelease',
|
||||
versionSpec = 'versionSpec',
|
||||
ignoreFailedSources = 'ignoreFailedSources'
|
||||
}
|
||||
|
||||
export interface ISetupSettings {
|
||||
[SetupFields.versionSpec]: string
|
||||
[SetupFields.includePrerelease]: boolean
|
||||
[SetupFields.ignoreFailedSources]: boolean
|
||||
}
|
||||
|
||||
export interface ISettingsProvider {
|
||||
getSetupSettings(): ISetupSettings
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { injectable } from 'inversify'
|
||||
import { ISettingsProvider, ISetupSettings, SetupFields } from './models'
|
||||
import { IBuildAgent } from '../../core/models'
|
||||
|
||||
@injectable()
|
||||
export class SettingsProvider implements ISettingsProvider {
|
||||
constructor(protected buildAgent: IBuildAgent) {}
|
||||
|
||||
public getSetupSettings(): ISetupSettings {
|
||||
const versionSpec = this.buildAgent.getInput(SetupFields.versionSpec)
|
||||
const includePrerelease = this.buildAgent.getBooleanInput(SetupFields.includePrerelease)
|
||||
const ignoreFailedSources = this.buildAgent.getBooleanInput(SetupFields.ignoreFailedSources)
|
||||
|
||||
return {
|
||||
versionSpec,
|
||||
includePrerelease,
|
||||
ignoreFailedSources
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
import { ISettingsProvider } from '../common/models'
|
||||
|
||||
export enum CommonFields {
|
||||
repository = 'repository',
|
||||
owner = 'owner',
|
||||
@@ -37,22 +35,6 @@ export enum AddAssetFields {
|
||||
assets = 'assets'
|
||||
}
|
||||
|
||||
export interface IGitReleaseManagerSettingsProvider extends ISettingsProvider {
|
||||
getCreateSettings(): GitReleaseManagerCreateSettings
|
||||
|
||||
getDiscardSettings(): GitReleaseManagerDiscardSettings
|
||||
|
||||
getCloseSettings(): GitReleaseManagerCloseSettings
|
||||
|
||||
getOpenSettings(): GitReleaseManagerOpenSettings
|
||||
|
||||
getPublishSettings(): GitReleaseManagerPublishSettings
|
||||
|
||||
getAddAssetSettings(): GitReleaseManagerAddAssetSettings
|
||||
|
||||
getCommonSettings(): GitReleaseManagerSettings
|
||||
}
|
||||
|
||||
export interface GitReleaseManagerSettings {
|
||||
[CommonFields.repository]: string
|
||||
[CommonFields.owner]: string
|
||||
@@ -60,7 +42,8 @@ export interface GitReleaseManagerSettings {
|
||||
[CommonFields.targetDirectory]: string
|
||||
}
|
||||
|
||||
export interface GitReleaseManagerCreateSettings extends GitReleaseManagerSettings {
|
||||
export interface GitReleaseManagerCreateSettings
|
||||
extends GitReleaseManagerSettings {
|
||||
[CreateFields.milestone]: string
|
||||
[CreateFields.name]: string
|
||||
[CreateFields.inputFileName]: string
|
||||
@@ -69,23 +52,28 @@ export interface GitReleaseManagerCreateSettings extends GitReleaseManagerSettin
|
||||
[CreateFields.assets]?: string[]
|
||||
}
|
||||
|
||||
export interface GitReleaseManagerDiscardSettings extends GitReleaseManagerSettings {
|
||||
export interface GitReleaseManagerDiscardSettings
|
||||
extends GitReleaseManagerSettings {
|
||||
[DiscardFields.milestone]: string
|
||||
}
|
||||
|
||||
export interface GitReleaseManagerCloseSettings extends GitReleaseManagerSettings {
|
||||
export interface GitReleaseManagerCloseSettings
|
||||
extends GitReleaseManagerSettings {
|
||||
[CloseFields.milestone]: string
|
||||
}
|
||||
|
||||
export interface GitReleaseManagerOpenSettings extends GitReleaseManagerSettings {
|
||||
export interface GitReleaseManagerOpenSettings
|
||||
extends GitReleaseManagerSettings {
|
||||
[OpenFields.milestone]: string
|
||||
}
|
||||
|
||||
export interface GitReleaseManagerPublishSettings extends GitReleaseManagerSettings {
|
||||
export interface GitReleaseManagerPublishSettings
|
||||
extends GitReleaseManagerSettings {
|
||||
[PublishFields.tagName]: string
|
||||
}
|
||||
|
||||
export interface GitReleaseManagerAddAssetSettings extends GitReleaseManagerSettings {
|
||||
export interface GitReleaseManagerAddAssetSettings
|
||||
extends GitReleaseManagerSettings {
|
||||
[AddAssetFields.tagName]: string
|
||||
[AddAssetFields.assets]: string[]
|
||||
}
|
||||
|
||||
@@ -1,39 +1,35 @@
|
||||
import { IBuildAgent, TYPES } from '../../core/models'
|
||||
import { IBuildAgent } from '../../core/models'
|
||||
import {
|
||||
AddAssetFields,
|
||||
CloseFields,
|
||||
GitReleaseManagerSettings,
|
||||
CommonFields,
|
||||
CreateFields,
|
||||
DiscardFields,
|
||||
GitReleaseManagerAddAssetSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
CloseFields,
|
||||
OpenFields,
|
||||
PublishFields,
|
||||
AddAssetFields,
|
||||
GitReleaseManagerCreateSettings,
|
||||
GitReleaseManagerDiscardSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
GitReleaseManagerOpenSettings,
|
||||
GitReleaseManagerPublishSettings,
|
||||
GitReleaseManagerSettings,
|
||||
IGitReleaseManagerSettingsProvider,
|
||||
OpenFields,
|
||||
PublishFields
|
||||
GitReleaseManagerAddAssetSettings
|
||||
} from './models'
|
||||
import { SettingsProvider } from '../common/settings'
|
||||
import { inject, injectable } from 'inversify'
|
||||
|
||||
@injectable()
|
||||
export class GitReleaseManagerSettingsProvider extends SettingsProvider implements IGitReleaseManagerSettingsProvider {
|
||||
constructor(@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent) {
|
||||
super(buildAgent)
|
||||
}
|
||||
export class Settings {
|
||||
public static getCreateSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerCreateSettings {
|
||||
const milestone = buildAgent.getInput(CreateFields.milestone)
|
||||
const name = buildAgent.getInput(CreateFields.name)
|
||||
const inputFileName = buildAgent.getInput(CreateFields.inputFileName)
|
||||
const isPreRelease = buildAgent.getBooleanInput(
|
||||
CreateFields.isPreRelease
|
||||
)
|
||||
const commit = buildAgent.getInput(CreateFields.commit)
|
||||
const assets = buildAgent.getListInput(CreateFields.assets)
|
||||
|
||||
getCreateSettings(): GitReleaseManagerCreateSettings {
|
||||
const milestone = this.buildAgent.getInput(CreateFields.milestone)
|
||||
const name = this.buildAgent.getInput(CreateFields.name)
|
||||
const inputFileName = this.buildAgent.getInput(CreateFields.inputFileName)
|
||||
const isPreRelease = this.buildAgent.getBooleanInput(CreateFields.isPreRelease)
|
||||
const commit = this.buildAgent.getInput(CreateFields.commit)
|
||||
const assets = this.buildAgent.getListInput(CreateFields.assets)
|
||||
|
||||
const commonSettings = this.getCommonSettings()
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone,
|
||||
@@ -45,51 +41,61 @@ export class GitReleaseManagerSettingsProvider extends SettingsProvider implemen
|
||||
}
|
||||
}
|
||||
|
||||
getDiscardSettings(): GitReleaseManagerDiscardSettings {
|
||||
const milestone = this.buildAgent.getInput(DiscardFields.milestone)
|
||||
public static getDiscardSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerDiscardSettings {
|
||||
const milestone = buildAgent.getInput(DiscardFields.milestone)
|
||||
|
||||
const commonSettings = this.getCommonSettings()
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone
|
||||
}
|
||||
}
|
||||
|
||||
getCloseSettings(): GitReleaseManagerCloseSettings {
|
||||
const milestone = this.buildAgent.getInput(CloseFields.milestone)
|
||||
public static getCloseSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerCloseSettings {
|
||||
const milestone = buildAgent.getInput(CloseFields.milestone)
|
||||
|
||||
const commonSettings = this.getCommonSettings()
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone
|
||||
}
|
||||
}
|
||||
|
||||
getOpenSettings(): GitReleaseManagerOpenSettings {
|
||||
const milestone = this.buildAgent.getInput(OpenFields.milestone)
|
||||
public static getOpenSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerOpenSettings {
|
||||
const milestone = buildAgent.getInput(OpenFields.milestone)
|
||||
|
||||
const commonSettings = this.getCommonSettings()
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone
|
||||
}
|
||||
}
|
||||
|
||||
getPublishSettings(): GitReleaseManagerPublishSettings {
|
||||
const tagName = this.buildAgent.getInput(PublishFields.tagName)
|
||||
public static getPublishSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerPublishSettings {
|
||||
const tagName = buildAgent.getInput(PublishFields.tagName)
|
||||
|
||||
const commonSettings = this.getCommonSettings()
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
return {
|
||||
...commonSettings,
|
||||
tagName
|
||||
}
|
||||
}
|
||||
|
||||
getAddAssetSettings(): GitReleaseManagerAddAssetSettings {
|
||||
const tagName = this.buildAgent.getInput(AddAssetFields.tagName)
|
||||
const assets = this.buildAgent.getListInput(AddAssetFields.assets)
|
||||
public static getAddAssetSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerAddAssetSettings {
|
||||
const tagName = buildAgent.getInput(AddAssetFields.tagName)
|
||||
const assets = buildAgent.getListInput(AddAssetFields.assets)
|
||||
|
||||
const commonSettings = this.getCommonSettings()
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
return {
|
||||
...commonSettings,
|
||||
tagName,
|
||||
@@ -97,11 +103,15 @@ export class GitReleaseManagerSettingsProvider extends SettingsProvider implemen
|
||||
}
|
||||
}
|
||||
|
||||
getCommonSettings(): GitReleaseManagerSettings {
|
||||
const owner = this.buildAgent.getInput(CommonFields.owner, true)
|
||||
const repository = this.buildAgent.getInput(CommonFields.repository, true)
|
||||
const token = this.buildAgent.getInput(CommonFields.token, true)
|
||||
const targetDirectory = this.buildAgent.getInput(CommonFields.targetDirectory)
|
||||
private static getCommonSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerSettings {
|
||||
const owner = buildAgent.getInput(CommonFields.owner, true)
|
||||
const repository = buildAgent.getInput(CommonFields.repository, true)
|
||||
const token = buildAgent.getInput(CommonFields.token, true)
|
||||
const targetDirectory = buildAgent.getInput(
|
||||
CommonFields.targetDirectory
|
||||
)
|
||||
|
||||
return {
|
||||
owner,
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import * as path from 'path'
|
||||
import path = require('path')
|
||||
|
||||
import { IBuildAgent, IExecResult, TYPES } from '../../core/models'
|
||||
import { inject, injectable } from 'inversify'
|
||||
import { TYPES, IBuildAgent, IExecResult, ISetupSettings } from '../../core/models'
|
||||
import { injectable, inject } from 'inversify'
|
||||
import { DotnetTool, IDotnetTool } from '../../core/dotnet-tool'
|
||||
import { IVersionManager } from '../../core/versionManager'
|
||||
|
||||
import {
|
||||
GitReleaseManagerAddAssetSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
GitReleaseManagerSettings,
|
||||
GitReleaseManagerCreateSettings,
|
||||
GitReleaseManagerDiscardSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
GitReleaseManagerOpenSettings,
|
||||
GitReleaseManagerPublishSettings,
|
||||
GitReleaseManagerSettings
|
||||
GitReleaseManagerAddAssetSettings
|
||||
} from './models'
|
||||
import { ISetupSettings } from '../common/models'
|
||||
|
||||
export interface IGitReleaseManagerTool extends IDotnetTool {
|
||||
install(setupSettings: ISetupSettings): Promise<void>
|
||||
@@ -27,28 +26,43 @@ export interface IGitReleaseManagerTool extends IDotnetTool {
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseManagerTool {
|
||||
constructor(@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent, @inject(TYPES.IVersionManager) versionManager: IVersionManager) {
|
||||
export class GitReleaseManagerTool
|
||||
extends DotnetTool
|
||||
implements IGitReleaseManagerTool {
|
||||
constructor(
|
||||
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
||||
@inject(TYPES.IVersionManager) versionManager: IVersionManager
|
||||
) {
|
||||
super(buildAgent, versionManager)
|
||||
}
|
||||
|
||||
public async install(setupSettings: ISetupSettings): Promise<void> {
|
||||
await this.toolInstall('GitReleaseManager.Tool', false, setupSettings)
|
||||
await this.toolInstall(
|
||||
'GitReleaseManager.Tool',
|
||||
false,
|
||||
setupSettings
|
||||
)
|
||||
}
|
||||
|
||||
public create(settings: GitReleaseManagerCreateSettings): Promise<IExecResult> {
|
||||
public create(
|
||||
settings: GitReleaseManagerCreateSettings
|
||||
): Promise<IExecResult> {
|
||||
const args = this.getCreateArguments(settings)
|
||||
|
||||
return this.execute('dotnet-gitreleasemanager', args)
|
||||
}
|
||||
|
||||
public discard(settings: GitReleaseManagerDiscardSettings): Promise<IExecResult> {
|
||||
public discard(
|
||||
settings: GitReleaseManagerDiscardSettings
|
||||
): Promise<IExecResult> {
|
||||
const args = this.getDiscardArguments(settings)
|
||||
|
||||
return this.execute('dotnet-gitreleasemanager', args)
|
||||
}
|
||||
|
||||
public close(settings: GitReleaseManagerCloseSettings): Promise<IExecResult> {
|
||||
public close(
|
||||
settings: GitReleaseManagerCloseSettings
|
||||
): Promise<IExecResult> {
|
||||
const args = this.getCloseArguments(settings)
|
||||
|
||||
return this.execute('dotnet-gitreleasemanager', args)
|
||||
@@ -60,13 +74,17 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
return this.execute('dotnet-gitreleasemanager', args)
|
||||
}
|
||||
|
||||
public publish(settings: GitReleaseManagerPublishSettings): Promise<IExecResult> {
|
||||
public publish(
|
||||
settings: GitReleaseManagerPublishSettings
|
||||
): Promise<IExecResult> {
|
||||
const args = this.getPublishArguments(settings)
|
||||
|
||||
return this.execute('dotnet-gitreleasemanager', args)
|
||||
}
|
||||
|
||||
public addAsset(settings: GitReleaseManagerAddAssetSettings): Promise<IExecResult> {
|
||||
public addAsset(
|
||||
settings: GitReleaseManagerAddAssetSettings
|
||||
): Promise<IExecResult> {
|
||||
const args = this.getAddAssetArguments(settings)
|
||||
|
||||
return this.execute('dotnet-gitreleasemanager', args)
|
||||
@@ -86,7 +104,9 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
return args
|
||||
}
|
||||
|
||||
private getCreateArguments(settings: GitReleaseManagerCreateSettings): string[] {
|
||||
private getCreateArguments(
|
||||
settings: GitReleaseManagerCreateSettings
|
||||
): string[] {
|
||||
const args: string[] = ['create', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -103,7 +123,10 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
if (this.buildAgent.fileExists(settings.inputFileName)) {
|
||||
args.push('--inputFilePath', settings.inputFileName)
|
||||
} else {
|
||||
throw new Error('GitReleaseManager inputFilePath not found at ' + settings.inputFileName)
|
||||
throw new Error(
|
||||
'GitReleaseManager inputFilePath not found at ' +
|
||||
settings.inputFileName
|
||||
)
|
||||
}
|
||||
}
|
||||
if (settings.isPreRelease) {
|
||||
@@ -120,7 +143,9 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
return args
|
||||
}
|
||||
|
||||
private getDiscardArguments(settings: GitReleaseManagerDiscardSettings): string[] {
|
||||
private getDiscardArguments(
|
||||
settings: GitReleaseManagerDiscardSettings
|
||||
): string[] {
|
||||
const args: string[] = ['discard', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -130,7 +155,9 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
return args
|
||||
}
|
||||
|
||||
private getCloseArguments(settings: GitReleaseManagerCloseSettings): string[] {
|
||||
private getCloseArguments(
|
||||
settings: GitReleaseManagerCloseSettings
|
||||
): string[] {
|
||||
const args: string[] = ['close', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -140,7 +167,9 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
return args
|
||||
}
|
||||
|
||||
private getOpenArguments(settings: GitReleaseManagerOpenSettings): string[] {
|
||||
private getOpenArguments(
|
||||
settings: GitReleaseManagerOpenSettings
|
||||
): string[] {
|
||||
const args: string[] = ['open', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -150,7 +179,9 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
return args
|
||||
}
|
||||
|
||||
private getPublishArguments(settings: GitReleaseManagerPublishSettings): string[] {
|
||||
private getPublishArguments(
|
||||
settings: GitReleaseManagerPublishSettings
|
||||
): string[] {
|
||||
const args: string[] = ['publish', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.tagName) {
|
||||
@@ -160,8 +191,13 @@ export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseMana
|
||||
return args
|
||||
}
|
||||
|
||||
private getAddAssetArguments(settings: GitReleaseManagerAddAssetSettings): string[] {
|
||||
const args: string[] = ['addasset', ...this.getCommonArguments(settings)]
|
||||
private getAddAssetArguments(
|
||||
settings: GitReleaseManagerAddAssetSettings
|
||||
): string[] {
|
||||
const args: string[] = [
|
||||
'addasset',
|
||||
...this.getCommonArguments(settings)
|
||||
]
|
||||
|
||||
if (settings.tagName) {
|
||||
args.push('--tagName', settings.tagName)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { ISettingsProvider } from '../common/models'
|
||||
|
||||
export enum ExecuteFields {
|
||||
targetPath = 'targetPath',
|
||||
useConfigFile = 'useConfigFile',
|
||||
@@ -20,10 +18,6 @@ export interface GitVersionSettings {
|
||||
[ExecuteFields.srcDir]: string
|
||||
}
|
||||
|
||||
export interface IGitVersionSettingsProvider extends ISettingsProvider {
|
||||
getGitVersionSettings(): GitVersionSettings
|
||||
}
|
||||
|
||||
export interface GitVersionOutput {
|
||||
Major: number
|
||||
Minor: number
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
import { IBuildAgent, TYPES } from '../../core/models'
|
||||
import { IBuildAgent } from '../../core/models'
|
||||
|
||||
import { ExecuteFields, GitVersionSettings, IGitVersionSettingsProvider } from './models'
|
||||
import { SettingsProvider } from '../common/settings'
|
||||
import { inject, injectable } from 'inversify'
|
||||
import { GitVersionSettings, ExecuteFields } from './models'
|
||||
|
||||
@injectable()
|
||||
export class GitVersionSettingsProvider extends SettingsProvider implements IGitVersionSettingsProvider {
|
||||
constructor(@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent) {
|
||||
super(buildAgent)
|
||||
}
|
||||
export class Settings {
|
||||
public static getGitVersionSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitVersionSettings {
|
||||
const targetPath = buildAgent.getInput(ExecuteFields.targetPath)
|
||||
|
||||
public getGitVersionSettings(): GitVersionSettings {
|
||||
const targetPath = this.buildAgent.getInput(ExecuteFields.targetPath)
|
||||
const useConfigFile = buildAgent.getBooleanInput(
|
||||
ExecuteFields.useConfigFile
|
||||
)
|
||||
const configFilePath = buildAgent.getInput(ExecuteFields.configFilePath)
|
||||
|
||||
const useConfigFile = this.buildAgent.getBooleanInput(ExecuteFields.useConfigFile)
|
||||
const configFilePath = this.buildAgent.getInput(ExecuteFields.configFilePath)
|
||||
const updateAssemblyInfo = buildAgent.getBooleanInput(
|
||||
ExecuteFields.updateAssemblyInfo
|
||||
)
|
||||
const updateAssemblyInfoFilename = buildAgent.getInput(
|
||||
ExecuteFields.updateAssemblyInfoFilename
|
||||
)
|
||||
|
||||
const updateAssemblyInfo = this.buildAgent.getBooleanInput(ExecuteFields.updateAssemblyInfo)
|
||||
const updateAssemblyInfoFilename = this.buildAgent.getInput(ExecuteFields.updateAssemblyInfoFilename)
|
||||
const additionalArguments = buildAgent.getInput(
|
||||
ExecuteFields.additionalArguments
|
||||
)
|
||||
|
||||
const additionalArguments = this.buildAgent.getInput(ExecuteFields.additionalArguments)
|
||||
|
||||
const srcDir = this.buildAgent.getSourceDir()?.replace(/\\/g, '/')
|
||||
const srcDir = buildAgent.getSourceDir()?.replace(/\\/g, '/')
|
||||
|
||||
return {
|
||||
targetPath,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { inject, injectable } from 'inversify'
|
||||
import { IBuildAgent, IExecResult, TYPES } from '../../core/models'
|
||||
import path = require('path')
|
||||
|
||||
import { injectable, inject } from 'inversify'
|
||||
import { IExecResult, IBuildAgent, TYPES, ISetupSettings } from '../../core/models'
|
||||
import { DotnetTool, IDotnetTool } from '../../core/dotnet-tool'
|
||||
import { GitVersionOutput, GitVersionSettings } from './models'
|
||||
import { GitVersionSettings, GitVersionOutput } from './models'
|
||||
import { IVersionManager } from '../../core/versionManager'
|
||||
import { ISetupSettings } from '../common/models'
|
||||
|
||||
export interface IGitVersionTool extends IDotnetTool {
|
||||
install(setupSettings: ISetupSettings): Promise<void>
|
||||
@@ -13,12 +14,19 @@ export interface IGitVersionTool extends IDotnetTool {
|
||||
|
||||
@injectable()
|
||||
export class GitVersionTool extends DotnetTool implements IGitVersionTool {
|
||||
constructor(@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent, @inject(TYPES.IVersionManager) versionManager: IVersionManager) {
|
||||
constructor(
|
||||
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
||||
@inject(TYPES.IVersionManager) versionManager: IVersionManager
|
||||
) {
|
||||
super(buildAgent, versionManager)
|
||||
}
|
||||
|
||||
public async install(setupSettings: ISetupSettings): Promise<void> {
|
||||
await this.toolInstall('GitVersion.Tool', false, setupSettings)
|
||||
await this.toolInstall(
|
||||
'GitVersion.Tool',
|
||||
false,
|
||||
setupSettings
|
||||
)
|
||||
}
|
||||
|
||||
public run(options: GitVersionSettings): Promise<IExecResult> {
|
||||
@@ -44,16 +52,33 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
|
||||
return workDir.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
private getArguments(workDir: string, options: GitVersionSettings): string[] {
|
||||
private getArguments(
|
||||
workDir: string,
|
||||
options: GitVersionSettings
|
||||
): string[] {
|
||||
let args = [workDir, '/output', 'json', '/output', 'buildserver']
|
||||
|
||||
const { useConfigFile, configFilePath, updateAssemblyInfo, updateAssemblyInfoFilename, additionalArguments } = options
|
||||
const {
|
||||
useConfigFile,
|
||||
configFilePath,
|
||||
updateAssemblyInfo,
|
||||
updateAssemblyInfoFilename,
|
||||
additionalArguments
|
||||
} = options
|
||||
|
||||
if (useConfigFile) {
|
||||
if (this.buildAgent.isValidInputFile('configFilePath', configFilePath)) {
|
||||
if (
|
||||
this.buildAgent.isValidInputFile(
|
||||
'configFilePath',
|
||||
configFilePath
|
||||
)
|
||||
) {
|
||||
args.push('/config', configFilePath)
|
||||
} else {
|
||||
throw new Error('GitVersion configuration file not found at ' + configFilePath)
|
||||
throw new Error(
|
||||
'GitVersion configuration file not found at ' +
|
||||
configFilePath
|
||||
)
|
||||
}
|
||||
}
|
||||
if (updateAssemblyInfo) {
|
||||
@@ -61,10 +86,18 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
|
||||
|
||||
// You can specify 'updateAssemblyInfo' without 'updateAssemblyInfoFilename'.
|
||||
if (updateAssemblyInfoFilename?.length > 0) {
|
||||
if (this.buildAgent.isValidInputFile('updateAssemblyInfoFilename', updateAssemblyInfoFilename)) {
|
||||
if (
|
||||
this.buildAgent.isValidInputFile(
|
||||
'updateAssemblyInfoFilename',
|
||||
updateAssemblyInfoFilename
|
||||
)
|
||||
) {
|
||||
args.push(updateAssemblyInfoFilename)
|
||||
} else {
|
||||
throw new Error('AssemblyInfoFilename file not found at ' + updateAssemblyInfoFilename)
|
||||
throw new Error(
|
||||
'AssemblyInfoFilename file not found at ' +
|
||||
updateAssemblyInfoFilename
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,9 +182,12 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
|
||||
}
|
||||
|
||||
private toCamelCase(input: string): string {
|
||||
return input.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) {
|
||||
if (+match === 0) return '' // or if (/\s+/.test(match)) for white spaces
|
||||
return index == 0 ? match.toLowerCase() : match.toUpperCase()
|
||||
})
|
||||
return input.replace(
|
||||
/(?:^\w|[A-Z]|\b\w|\s+)/g,
|
||||
function (match, index) {
|
||||
if (+match === 0) return '' // or if (/\s+/.test(match)) for white spaces
|
||||
return index == 0 ? match.toLowerCase() : match.toUpperCase()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user