introduce SettingsProviders
This commit is contained in:
@@ -8,6 +8,7 @@ end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = off
|
||||
|
||||
[*.yml]
|
||||
indent_size = 2
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@ node_modules/
|
||||
*.js
|
||||
!dist/**/*.js
|
||||
*.vsix
|
||||
|
||||
.idea/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"printWidth": 160,
|
||||
"tabWidth": 4,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
|
||||
@@ -24,12 +24,7 @@ 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,10 +12,7 @@ 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 {
|
||||
@@ -58,12 +55,7 @@ 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)
|
||||
@@ -78,12 +70,7 @@ 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,12 +19,7 @@ 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,16 +4,13 @@ import * as path from 'path'
|
||||
import * as http from 'typed-rest-client/HttpClient'
|
||||
|
||||
import { inject, injectable } from 'inversify'
|
||||
import { TYPES, IExecResult, IBuildAgent, ISetupSettings } from './models'
|
||||
import { TYPES, IExecResult, IBuildAgent } 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()
|
||||
@@ -22,20 +19,12 @@ 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://azuresearch-usnc.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 {
|
||||
@@ -48,16 +37,10 @@ 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(
|
||||
`Installing ${toolName} version ` + setupSettings.versionSpec
|
||||
)
|
||||
console.log(`Installing ${toolName} version ` + setupSettings.versionSpec)
|
||||
console.log('--------------------------')
|
||||
|
||||
if (this.versionManager.isExplicitVersion(setupSettings.versionSpec)) {
|
||||
@@ -74,9 +57,7 @@ export class DotnetTool implements IDotnetTool {
|
||||
|
||||
if (!toolPath) {
|
||||
let version: string
|
||||
if (
|
||||
this.versionManager.isExplicitVersion(setupSettings.versionSpec)
|
||||
) {
|
||||
if (this.versionManager.isExplicitVersion(setupSettings.versionSpec)) {
|
||||
//
|
||||
// Explicit version was specified. No need to query for list of versions.
|
||||
//
|
||||
@@ -88,15 +69,9 @@ 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}'.`)
|
||||
}
|
||||
|
||||
//
|
||||
@@ -108,11 +83,7 @@ export class DotnetTool implements IDotnetTool {
|
||||
//
|
||||
// Download, extract, cache
|
||||
//
|
||||
toolPath = await this.acquireTool(
|
||||
toolName,
|
||||
version,
|
||||
setupSettings.ignoreFailedSources
|
||||
)
|
||||
toolPath = await this.acquireTool(toolName, version, setupSettings.ignoreFailedSources)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +93,7 @@ export class DotnetTool implements IDotnetTool {
|
||||
//
|
||||
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)
|
||||
@@ -136,19 +104,13 @@ 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 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 res = await this.httpClient.get(downloadPath)
|
||||
@@ -160,23 +122,19 @@ 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, {
|
||||
includePrerelease
|
||||
})
|
||||
}
|
||||
|
||||
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,19 +5,9 @@ export const TYPES = {
|
||||
IDotnetTool: Symbol.for('DotnetTool'),
|
||||
IGitVersionTool: Symbol.for('GitVersionTool'),
|
||||
IGitReleaseManagerTool: Symbol.for('GitReleaseManagerTool'),
|
||||
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
|
||||
IVersionManager: Symbol.for('VersionManager'),
|
||||
IGitVersionSettingsProvider: Symbol.for('GitVersionSettingsProvider'),
|
||||
IGitReleaseManagerSettingsProvider: Symbol.for('GitReleaseManagerSettingsProvider')
|
||||
}
|
||||
|
||||
export interface IExecResult {
|
||||
@@ -26,17 +16,11 @@ 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
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
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,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { addAsset } from './main'
|
||||
|
||||
addAsset()
|
||||
await addAsset()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { close } from './main'
|
||||
|
||||
close()
|
||||
await close()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { create } from './main'
|
||||
|
||||
create()
|
||||
await create()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { discard } from './main'
|
||||
|
||||
discard()
|
||||
await discard()
|
||||
|
||||
@@ -1,34 +1,26 @@
|
||||
import { IBuildAgent, TYPES } from '../../core/models'
|
||||
import {
|
||||
IGitReleaseManagerTool,
|
||||
GitReleaseManagerTool
|
||||
} from '../../tools/gitreleasemanager/tool'
|
||||
import { Settings as CommonSettings } from '../../core/settings'
|
||||
import { Settings } from '../../tools/gitreleasemanager/settings'
|
||||
import { IGitReleaseManagerTool, GitReleaseManagerTool } from '../../tools/gitreleasemanager/tool'
|
||||
import { IGitReleaseManagerSettingsProvider } from '../../tools/gitreleasemanager/models'
|
||||
import { GitReleaseManagerSettingsProvider } from '../../tools/gitreleasemanager/settings'
|
||||
|
||||
import container from '../../core/ioc'
|
||||
|
||||
container
|
||||
.bind<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool)
|
||||
.to(GitReleaseManagerTool)
|
||||
container.bind<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool).to(GitReleaseManagerTool)
|
||||
container.bind<IGitReleaseManagerSettingsProvider>(TYPES.IGitReleaseManagerSettingsProvider).to(GitReleaseManagerSettingsProvider)
|
||||
|
||||
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 = CommonSettings.getSetupSettings(buildAgent)
|
||||
const settings = settingsProvider.getSetupSettings()
|
||||
|
||||
await gitReleaseManagerTool.install(settings)
|
||||
|
||||
buildAgent.setSucceeded(
|
||||
'GitVersionManager installed successfully',
|
||||
true
|
||||
)
|
||||
buildAgent.setSucceeded('GitVersionManager installed successfully', true)
|
||||
} catch (error) {
|
||||
buildAgent.setFailed(error.message, true)
|
||||
}
|
||||
@@ -38,14 +30,11 @@ export async function create() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = Settings.getCreateSettings(buildAgent)
|
||||
const settings = settingsProvider.getCreateSettings()
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -55,14 +44,11 @@ export async function discard() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = Settings.getDiscardSettings(buildAgent)
|
||||
const settings = settingsProvider.getDiscardSettings()
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -72,14 +58,11 @@ export async function close() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = Settings.getCloseSettings(buildAgent)
|
||||
const settings = settingsProvider.getCloseSettings()
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -89,14 +72,11 @@ export async function open() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = Settings.getOpenSettings(buildAgent)
|
||||
const settings = settingsProvider.getOpenSettings()
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -106,14 +86,11 @@ export async function publish() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = Settings.getPublishSettings(buildAgent)
|
||||
const settings = settingsProvider.getPublishSettings()
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -123,14 +100,11 @@ export async function addAsset() {
|
||||
try {
|
||||
gitReleaseManagerTool.disableTelemetry()
|
||||
|
||||
const settings = Settings.getAddAssetSettings(buildAgent)
|
||||
const settings = settingsProvider.getAddAssetSettings()
|
||||
|
||||
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'
|
||||
|
||||
open()
|
||||
await open()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { publish } from './main'
|
||||
|
||||
publish()
|
||||
await publish()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { setup } from './main'
|
||||
|
||||
setup()
|
||||
await setup()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'reflect-metadata'
|
||||
import { run } from './main'
|
||||
|
||||
run()
|
||||
await run()
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
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
|
||||
} from '../../tools/gitversion/models'
|
||||
import { GitVersionSettings, GitVersionOutput, IGitVersionSettingsProvider } from '../../tools/gitversion/models'
|
||||
import { GitVersionSettingsProvider } from '../../tools/gitversion/settings'
|
||||
|
||||
import container from '../../core/ioc'
|
||||
|
||||
container.bind<IGitVersionTool>(TYPES.IGitVersionTool).to(GitVersionTool)
|
||||
container.bind<IGitVersionSettingsProvider>(TYPES.IGitVersionSettingsProvider).to(GitVersionSettingsProvider)
|
||||
|
||||
const gitVersionTool = container.get<IGitVersionTool>(TYPES.IGitVersionTool)
|
||||
const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent)
|
||||
const gitVersionTool = container.get<IGitVersionTool>(TYPES.IGitVersionTool)
|
||||
const settingsProvider = container.get<IGitVersionSettingsProvider>(TYPES.IGitVersionSettingsProvider)
|
||||
|
||||
export async function setup() {
|
||||
try {
|
||||
gitVersionTool.disableTelemetry()
|
||||
console.log(`Agent: '${buildAgent.agentName}'`)
|
||||
|
||||
const settings = CommonSettings.getSetupSettings(buildAgent)
|
||||
const settings = settingsProvider.getSetupSettings()
|
||||
|
||||
await gitVersionTool.install(settings)
|
||||
|
||||
@@ -31,17 +30,13 @@ export async function setup() {
|
||||
export async function run() {
|
||||
try {
|
||||
gitVersionTool.disableTelemetry()
|
||||
console.log(`Agent: '${buildAgent.agentName}'`)
|
||||
|
||||
const settings: GitVersionSettings = Settings.getGitVersionSettings(
|
||||
buildAgent
|
||||
)
|
||||
const settings: GitVersionSettings = settingsProvider.getGitVersionSettings()
|
||||
|
||||
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'
|
||||
|
||||
setup()
|
||||
await setup()
|
||||
|
||||
15
src/tools/common/models.ts
Normal file
15
src/tools/common/models.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
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
|
||||
}
|
||||
20
src/tools/common/settings.ts
Normal file
20
src/tools/common/settings.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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,3 +1,5 @@
|
||||
import { ISettingsProvider } from '../common/models'
|
||||
|
||||
export enum CommonFields {
|
||||
repository = 'repository',
|
||||
owner = 'owner',
|
||||
@@ -35,6 +37,22 @@ 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
|
||||
@@ -42,8 +60,7 @@ 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
|
||||
@@ -52,28 +69,23 @@ export interface GitReleaseManagerCreateSettings
|
||||
[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,35 +1,39 @@
|
||||
import { IBuildAgent } from '../../core/models'
|
||||
import { IBuildAgent, TYPES } from '../../core/models'
|
||||
import {
|
||||
GitReleaseManagerSettings,
|
||||
AddAssetFields,
|
||||
CloseFields,
|
||||
CommonFields,
|
||||
CreateFields,
|
||||
DiscardFields,
|
||||
CloseFields,
|
||||
OpenFields,
|
||||
PublishFields,
|
||||
AddAssetFields,
|
||||
GitReleaseManagerAddAssetSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
GitReleaseManagerCreateSettings,
|
||||
GitReleaseManagerDiscardSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
GitReleaseManagerOpenSettings,
|
||||
GitReleaseManagerPublishSettings,
|
||||
GitReleaseManagerAddAssetSettings
|
||||
GitReleaseManagerSettings,
|
||||
IGitReleaseManagerSettingsProvider,
|
||||
OpenFields,
|
||||
PublishFields
|
||||
} from './models'
|
||||
import { SettingsProvider } from '../common/settings'
|
||||
import { inject, injectable } from 'inversify'
|
||||
|
||||
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)
|
||||
@injectable()
|
||||
export class GitReleaseManagerSettingsProvider extends SettingsProvider implements IGitReleaseManagerSettingsProvider {
|
||||
constructor(@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent) {
|
||||
super(buildAgent)
|
||||
}
|
||||
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
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()
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone,
|
||||
@@ -41,61 +45,51 @@ export class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
public static getDiscardSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerDiscardSettings {
|
||||
const milestone = buildAgent.getInput(DiscardFields.milestone)
|
||||
getDiscardSettings(): GitReleaseManagerDiscardSettings {
|
||||
const milestone = this.buildAgent.getInput(DiscardFields.milestone)
|
||||
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
const commonSettings = this.getCommonSettings()
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone
|
||||
}
|
||||
}
|
||||
|
||||
public static getCloseSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerCloseSettings {
|
||||
const milestone = buildAgent.getInput(CloseFields.milestone)
|
||||
getCloseSettings(): GitReleaseManagerCloseSettings {
|
||||
const milestone = this.buildAgent.getInput(CloseFields.milestone)
|
||||
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
const commonSettings = this.getCommonSettings()
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone
|
||||
}
|
||||
}
|
||||
|
||||
public static getOpenSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerOpenSettings {
|
||||
const milestone = buildAgent.getInput(OpenFields.milestone)
|
||||
getOpenSettings(): GitReleaseManagerOpenSettings {
|
||||
const milestone = this.buildAgent.getInput(OpenFields.milestone)
|
||||
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
const commonSettings = this.getCommonSettings()
|
||||
return {
|
||||
...commonSettings,
|
||||
milestone
|
||||
}
|
||||
}
|
||||
|
||||
public static getPublishSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerPublishSettings {
|
||||
const tagName = buildAgent.getInput(PublishFields.tagName)
|
||||
getPublishSettings(): GitReleaseManagerPublishSettings {
|
||||
const tagName = this.buildAgent.getInput(PublishFields.tagName)
|
||||
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
const commonSettings = this.getCommonSettings()
|
||||
return {
|
||||
...commonSettings,
|
||||
tagName
|
||||
}
|
||||
}
|
||||
|
||||
public static getAddAssetSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitReleaseManagerAddAssetSettings {
|
||||
const tagName = buildAgent.getInput(AddAssetFields.tagName)
|
||||
const assets = buildAgent.getListInput(AddAssetFields.assets)
|
||||
getAddAssetSettings(): GitReleaseManagerAddAssetSettings {
|
||||
const tagName = this.buildAgent.getInput(AddAssetFields.tagName)
|
||||
const assets = this.buildAgent.getListInput(AddAssetFields.assets)
|
||||
|
||||
const commonSettings = Settings.getCommonSettings(buildAgent)
|
||||
const commonSettings = this.getCommonSettings()
|
||||
return {
|
||||
...commonSettings,
|
||||
tagName,
|
||||
@@ -103,15 +97,11 @@ export class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
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)
|
||||
|
||||
return {
|
||||
owner,
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import path = require('path')
|
||||
import * as path from 'path'
|
||||
|
||||
import { TYPES, IBuildAgent, IExecResult, ISetupSettings } from '../../core/models'
|
||||
import { injectable, inject } from 'inversify'
|
||||
import { IBuildAgent, IExecResult, TYPES } from '../../core/models'
|
||||
import { inject, injectable } from 'inversify'
|
||||
import { DotnetTool, IDotnetTool } from '../../core/dotnet-tool'
|
||||
import { IVersionManager } from '../../core/versionManager'
|
||||
|
||||
import {
|
||||
GitReleaseManagerSettings,
|
||||
GitReleaseManagerAddAssetSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
GitReleaseManagerCreateSettings,
|
||||
GitReleaseManagerDiscardSettings,
|
||||
GitReleaseManagerCloseSettings,
|
||||
GitReleaseManagerOpenSettings,
|
||||
GitReleaseManagerPublishSettings,
|
||||
GitReleaseManagerAddAssetSettings
|
||||
GitReleaseManagerSettings
|
||||
} from './models'
|
||||
import { ISetupSettings } from '../common/models'
|
||||
|
||||
export interface IGitReleaseManagerTool extends IDotnetTool {
|
||||
install(setupSettings: ISetupSettings): Promise<void>
|
||||
@@ -26,43 +27,28 @@ 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)
|
||||
@@ -74,17 +60,13 @@ export class GitReleaseManagerTool
|
||||
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)
|
||||
@@ -104,9 +86,7 @@ export class GitReleaseManagerTool
|
||||
return args
|
||||
}
|
||||
|
||||
private getCreateArguments(
|
||||
settings: GitReleaseManagerCreateSettings
|
||||
): string[] {
|
||||
private getCreateArguments(settings: GitReleaseManagerCreateSettings): string[] {
|
||||
const args: string[] = ['create', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -123,10 +103,7 @@ export class GitReleaseManagerTool
|
||||
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) {
|
||||
@@ -143,9 +120,7 @@ export class GitReleaseManagerTool
|
||||
return args
|
||||
}
|
||||
|
||||
private getDiscardArguments(
|
||||
settings: GitReleaseManagerDiscardSettings
|
||||
): string[] {
|
||||
private getDiscardArguments(settings: GitReleaseManagerDiscardSettings): string[] {
|
||||
const args: string[] = ['discard', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -155,9 +130,7 @@ export class GitReleaseManagerTool
|
||||
return args
|
||||
}
|
||||
|
||||
private getCloseArguments(
|
||||
settings: GitReleaseManagerCloseSettings
|
||||
): string[] {
|
||||
private getCloseArguments(settings: GitReleaseManagerCloseSettings): string[] {
|
||||
const args: string[] = ['close', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -167,9 +140,7 @@ export class GitReleaseManagerTool
|
||||
return args
|
||||
}
|
||||
|
||||
private getOpenArguments(
|
||||
settings: GitReleaseManagerOpenSettings
|
||||
): string[] {
|
||||
private getOpenArguments(settings: GitReleaseManagerOpenSettings): string[] {
|
||||
const args: string[] = ['open', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.milestone) {
|
||||
@@ -179,9 +150,7 @@ export class GitReleaseManagerTool
|
||||
return args
|
||||
}
|
||||
|
||||
private getPublishArguments(
|
||||
settings: GitReleaseManagerPublishSettings
|
||||
): string[] {
|
||||
private getPublishArguments(settings: GitReleaseManagerPublishSettings): string[] {
|
||||
const args: string[] = ['publish', ...this.getCommonArguments(settings)]
|
||||
|
||||
if (settings.tagName) {
|
||||
@@ -191,13 +160,8 @@ export class GitReleaseManagerTool
|
||||
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,3 +1,5 @@
|
||||
import { ISettingsProvider } from '../common/models'
|
||||
|
||||
export enum ExecuteFields {
|
||||
targetPath = 'targetPath',
|
||||
useConfigFile = 'useConfigFile',
|
||||
@@ -18,6 +20,10 @@ export interface GitVersionSettings {
|
||||
[ExecuteFields.srcDir]: string
|
||||
}
|
||||
|
||||
export interface IGitVersionSettingsProvider extends ISettingsProvider {
|
||||
getGitVersionSettings(): GitVersionSettings
|
||||
}
|
||||
|
||||
export interface GitVersionOutput {
|
||||
Major: number
|
||||
Minor: number
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
import { IBuildAgent } from '../../core/models'
|
||||
import { IBuildAgent, TYPES } from '../../core/models'
|
||||
|
||||
import { GitVersionSettings, ExecuteFields } from './models'
|
||||
import { ExecuteFields, GitVersionSettings, IGitVersionSettingsProvider } from './models'
|
||||
import { SettingsProvider } from '../common/settings'
|
||||
import { inject, injectable } from 'inversify'
|
||||
|
||||
export class Settings {
|
||||
public static getGitVersionSettings(
|
||||
buildAgent: IBuildAgent
|
||||
): GitVersionSettings {
|
||||
const targetPath = buildAgent.getInput(ExecuteFields.targetPath)
|
||||
@injectable()
|
||||
export class GitVersionSettingsProvider extends SettingsProvider implements IGitVersionSettingsProvider {
|
||||
constructor(@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent) {
|
||||
super(buildAgent)
|
||||
}
|
||||
|
||||
const useConfigFile = buildAgent.getBooleanInput(
|
||||
ExecuteFields.useConfigFile
|
||||
)
|
||||
const configFilePath = buildAgent.getInput(ExecuteFields.configFilePath)
|
||||
public getGitVersionSettings(): GitVersionSettings {
|
||||
const targetPath = this.buildAgent.getInput(ExecuteFields.targetPath)
|
||||
|
||||
const updateAssemblyInfo = buildAgent.getBooleanInput(
|
||||
ExecuteFields.updateAssemblyInfo
|
||||
)
|
||||
const updateAssemblyInfoFilename = buildAgent.getInput(
|
||||
ExecuteFields.updateAssemblyInfoFilename
|
||||
)
|
||||
const useConfigFile = this.buildAgent.getBooleanInput(ExecuteFields.useConfigFile)
|
||||
const configFilePath = this.buildAgent.getInput(ExecuteFields.configFilePath)
|
||||
|
||||
const additionalArguments = buildAgent.getInput(
|
||||
ExecuteFields.additionalArguments
|
||||
)
|
||||
const updateAssemblyInfo = this.buildAgent.getBooleanInput(ExecuteFields.updateAssemblyInfo)
|
||||
const updateAssemblyInfoFilename = this.buildAgent.getInput(ExecuteFields.updateAssemblyInfoFilename)
|
||||
|
||||
const srcDir = buildAgent.getSourceDir()?.replace(/\\/g, '/')
|
||||
const additionalArguments = this.buildAgent.getInput(ExecuteFields.additionalArguments)
|
||||
|
||||
const srcDir = this.buildAgent.getSourceDir()?.replace(/\\/g, '/')
|
||||
|
||||
return {
|
||||
targetPath,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import path = require('path')
|
||||
|
||||
import { injectable, inject } from 'inversify'
|
||||
import { IExecResult, IBuildAgent, TYPES, ISetupSettings } from '../../core/models'
|
||||
import { inject, injectable } from 'inversify'
|
||||
import { IBuildAgent, IExecResult, TYPES } from '../../core/models'
|
||||
import { DotnetTool, IDotnetTool } from '../../core/dotnet-tool'
|
||||
import { GitVersionSettings, GitVersionOutput } from './models'
|
||||
import { GitVersionOutput, GitVersionSettings } from './models'
|
||||
import { IVersionManager } from '../../core/versionManager'
|
||||
import { ISetupSettings } from '../common/models'
|
||||
|
||||
export interface IGitVersionTool extends IDotnetTool {
|
||||
install(setupSettings: ISetupSettings): Promise<void>
|
||||
@@ -14,19 +13,12 @@ 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> {
|
||||
@@ -52,33 +44,16 @@ 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) {
|
||||
@@ -86,18 +61,10 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,12 +149,9 @@ 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()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "node",
|
||||
"target": "ES2016",
|
||||
"target": "es2017",
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": true,
|
||||
"lib": ["ES2016"],
|
||||
"types": ["reflect-metadata"],
|
||||
"esModuleInterop":true,
|
||||
"lib": [ "ES2016" ],
|
||||
"types": [ "reflect-metadata" ],
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ function getConfig(mode, agent, entry) {
|
||||
entry: entry,
|
||||
target: 'node',
|
||||
mode: mode,
|
||||
devtool: mode == 'development' ? 'inline-source-map' : false,
|
||||
devtool: mode === 'development' ? 'inline-source-map' : false,
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.tsx?$/,
|
||||
@@ -43,7 +43,10 @@ function getConfig(mode, agent, entry) {
|
||||
replace: 'let pkg = { version: "1.2.3" };'
|
||||
}]
|
||||
}])
|
||||
]
|
||||
],
|
||||
experiments: {
|
||||
topLevelAwait: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +65,12 @@ const entryPoints = [
|
||||
module.exports = (env) => {
|
||||
const task = env.task || 'compile';
|
||||
const agent = env.agent || 'mock';
|
||||
const mode = task == 'compile' ? 'development' : 'production';
|
||||
const mode = task === 'compile' ? 'development' : 'production';
|
||||
const entry = {};
|
||||
entryPoints.forEach(key => {
|
||||
const resource = task == 'compile' ? `src/tasks/${key}.ts` : `dist/${agent}/${key}/bundle.js`;
|
||||
const resource = task === 'compile' ? `src/tasks/${key}.ts` : `dist/${agent}/${key}/bundle.js`;
|
||||
entry[key] = path.resolve(__dirname, resource);
|
||||
});
|
||||
|
||||
return getConfig(mode, agent, entry);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user