Skip to content

Commit

Permalink
Add '--ignore-failed-sources' to options
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopey authored and arturcic committed Mar 17, 2022
1 parent a7350ec commit c6c07de
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 41 deletions.
8 changes: 8 additions & 0 deletions dist/azure/gitreleasemanager/setup/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
"defaultValue": "false",
"required": false,
"helpMarkDown": "Include pre-release versions when matching a version"
},
{
"name": "ignoreFailedSources",
"type": "boolean",
"label": "Treat package source failures as warnings",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Treat package source failures as warnings"
}
]
}
8 changes: 8 additions & 0 deletions dist/azure/gitversion/setup/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
"defaultValue": "false",
"required": false,
"helpMarkDown": "Include pre-release versions when matching a version"
},
{
"name": "ignoreFailedSources",
"type": "boolean",
"label": "Treat package source failures as warnings",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Treat package source failures as warnings"
}
]
}
41 changes: 26 additions & 15 deletions src/core/dotnet-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ 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'

export interface IDotnetTool {
disableTelemetry(): void
toolInstall(
toolName: string,
versionSpec: string,
checkLatest: boolean,
includePre: boolean
setupSettings: ISetupSettings
): Promise<string>
}

Expand Down Expand Up @@ -51,16 +50,17 @@ export class DotnetTool implements IDotnetTool {

public async toolInstall(
toolName: string,
versionSpec: string,
checkLatest: boolean,
includePre: boolean
setupSettings: ISetupSettings
): Promise<string> {
console.log('')
console.log('--------------------------')
console.log(`Installing ${toolName} version ` + versionSpec)
console.log(
`Installing ${toolName} version ` + setupSettings.versionSpec
)
console.log('--------------------------')

if (this.versionManager.isExplicitVersion(versionSpec)) {
if (this.versionManager.isExplicitVersion(setupSettings.versionSpec)) {
checkLatest = false // check latest doesn't make sense when explicit version
}

Expand All @@ -69,16 +69,18 @@ export class DotnetTool implements IDotnetTool {
//
// Let's try and resolve the version spec locally first
//
toolPath = this.buildAgent.find(toolName, versionSpec)
toolPath = this.buildAgent.find(toolName, setupSettings.versionSpec)
}

if (!toolPath) {
let version: string
if (this.versionManager.isExplicitVersion(versionSpec)) {
if (
this.versionManager.isExplicitVersion(setupSettings.versionSpec)
) {
//
// Explicit version was specified. No need to query for list of versions.
//
version = versionSpec
version = setupSettings.versionSpec
} else {
//
// Let's query and resolve the latest version for the versionSpec.
Expand All @@ -88,12 +90,12 @@ export class DotnetTool implements IDotnetTool {
//
version = await this.queryLatestMatch(
toolName,
versionSpec,
includePre
setupSettings.versionSpec,
setupSettings.includePrerelease
)
if (!version) {
throw new Error(
`Unable to find ${toolName} version '${versionSpec}'.`
`Unable to find ${toolName} version '${setupSettings.versionSpec}'.`
)
}

Expand All @@ -106,7 +108,11 @@ export class DotnetTool implements IDotnetTool {
//
// Download, extract, cache
//
toolPath = await this.acquireTool(toolName, version)
toolPath = await this.acquireTool(
toolName,
version,
setupSettings.ignoreFailedSources
)
}
}

Expand Down Expand Up @@ -170,11 +176,16 @@ export class DotnetTool implements IDotnetTool {

private async acquireTool(
toolName: string,
version: string
version: string,
ignoreFailedSources: boolean
): Promise<string> {
const tempDirectory = await this.buildAgent.createTempDir()
let args = ['tool', 'install', toolName, '--tool-path', tempDirectory]

if (ignoreFailedSources) {
args.push('--ignore-failed-sources')
}

if (version) {
version = this.versionManager.cleanVersion(version)
args = args.concat(['--version', version])
Expand Down
4 changes: 3 additions & 1 deletion src/core/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export const TYPES = {

export enum SetupFields {
includePrerelease = 'includePrerelease',
versionSpec = 'versionSpec'
versionSpec = 'versionSpec',
ignoreFailedSources = 'ignoreFailedSources'
}

export interface ISetupSettings {
[SetupFields.versionSpec]: string
[SetupFields.includePrerelease]: boolean
[SetupFields.ignoreFailedSources]: boolean
}

export interface IExecResult {
Expand Down
6 changes: 5 additions & 1 deletion src/core/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ export class Settings {
const includePrerelease = buildAgent.getBooleanInput(
SetupFields.includePrerelease
)
const ignoreFailedSources = buildAgent.getBooleanInput(
SetupFields.ignoreFailedSources
)

return {
versionSpec,
includePrerelease
includePrerelease,
ignoreFailedSources
}
}
}
5 changes: 1 addition & 4 deletions src/tasks/gitreleasemanager/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export async function setup() {

const settings = CommonSettings.getSetupSettings(buildAgent)

await gitReleaseManagerTool.install(
settings.versionSpec,
settings.includePrerelease
)
await gitReleaseManagerTool.install(settings)

buildAgent.setSucceeded(
'GitVersionManager installed successfully',
Expand Down
5 changes: 1 addition & 4 deletions src/tasks/gitversion/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ export async function setup() {

const settings = CommonSettings.getSetupSettings(buildAgent)

await gitVersionTool.install(
settings.versionSpec,
settings.includePrerelease
)
await gitVersionTool.install(settings)

buildAgent.setSucceeded('GitVersion installed successfully', true)
} catch (error) {
Expand Down
12 changes: 4 additions & 8 deletions src/tools/gitreleasemanager/tool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path = require('path')

import { TYPES, IBuildAgent, IExecResult } from '../../core/models'
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'
Expand All @@ -16,7 +16,7 @@ import {
} from './models'

export interface IGitReleaseManagerTool extends IDotnetTool {
install(versionSpec: string, includePrerelease: boolean): Promise<void>
install(setupSettings: ISetupSettings): Promise<void>
create(settings: GitReleaseManagerCreateSettings): Promise<IExecResult>
discard(settings: GitReleaseManagerDiscardSettings): Promise<IExecResult>
close(settings: GitReleaseManagerCloseSettings): Promise<IExecResult>
Expand All @@ -36,15 +36,11 @@ export class GitReleaseManagerTool
super(buildAgent, versionManager)
}

public async install(
versionSpec: string,
includePrerelease: boolean
): Promise<void> {
public async install(setupSettings: ISetupSettings): Promise<void> {
await this.toolInstall(
'GitReleaseManager.Tool',
versionSpec,
false,
includePrerelease
setupSettings
)
}

Expand Down
12 changes: 4 additions & 8 deletions src/tools/gitversion/tool.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import path = require('path')

import { injectable, inject } from 'inversify'
import { IExecResult, IBuildAgent, TYPES } from '../../core/models'
import { IExecResult, IBuildAgent, TYPES, ISetupSettings } from '../../core/models'
import { DotnetTool, IDotnetTool } from '../../core/dotnet-tool'
import { GitVersionSettings, GitVersionOutput } from './models'
import { IVersionManager } from '../../core/versionManager'

export interface IGitVersionTool extends IDotnetTool {
install(versionSpec: string, includePrerelease: boolean): Promise<void>
install(setupSettings: ISetupSettings): Promise<void>
run(options: GitVersionSettings): Promise<IExecResult>
writeGitVersionToAgent(gitversion: GitVersionOutput): void
}
Expand All @@ -21,15 +21,11 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
super(buildAgent, versionManager)
}

public async install(
versionSpec: string,
includePrerelease: boolean
): Promise<void> {
public async install(setupSettings: ISetupSettings): Promise<void> {
await this.toolInstall(
'GitVersion.Tool',
versionSpec,
false,
includePrerelease
setupSettings
)
}

Expand Down

0 comments on commit c6c07de

Please sign in to comment.