From c6c07deac41aecd0364d45791d21949e30ab1a8e Mon Sep 17 00:00:00 2001 From: matteopey <28830727+matteopey@users.noreply.github.com> Date: Wed, 16 Mar 2022 23:47:41 +0100 Subject: [PATCH] Add '--ignore-failed-sources' to options --- dist/azure/gitreleasemanager/setup/task.json | 8 ++++ dist/azure/gitversion/setup/task.json | 8 ++++ src/core/dotnet-tool.ts | 41 +++++++++++++------- src/core/models.ts | 4 +- src/core/settings.ts | 6 ++- src/tasks/gitreleasemanager/main.ts | 5 +-- src/tasks/gitversion/main.ts | 5 +-- src/tools/gitreleasemanager/tool.ts | 12 ++---- src/tools/gitversion/tool.ts | 12 ++---- 9 files changed, 60 insertions(+), 41 deletions(-) diff --git a/dist/azure/gitreleasemanager/setup/task.json b/dist/azure/gitreleasemanager/setup/task.json index e48b5db7f..2130ae7e3 100644 --- a/dist/azure/gitreleasemanager/setup/task.json +++ b/dist/azure/gitreleasemanager/setup/task.json @@ -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" } ] } diff --git a/dist/azure/gitversion/setup/task.json b/dist/azure/gitversion/setup/task.json index 31378d61a..8fadb9440 100644 --- a/dist/azure/gitversion/setup/task.json +++ b/dist/azure/gitversion/setup/task.json @@ -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" } ] } diff --git a/src/core/dotnet-tool.ts b/src/core/dotnet-tool.ts index b8b186257..7d0dcb99c 100644 --- a/src/core/dotnet-tool.ts +++ b/src/core/dotnet-tool.ts @@ -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 } @@ -51,16 +50,17 @@ export class DotnetTool implements IDotnetTool { public async toolInstall( toolName: string, - versionSpec: string, checkLatest: boolean, - includePre: boolean + setupSettings: ISetupSettings ): Promise { 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 } @@ -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. @@ -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}'.` ) } @@ -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 + ) } } @@ -170,11 +176,16 @@ export class DotnetTool implements IDotnetTool { private async acquireTool( toolName: string, - version: string + version: string, + ignoreFailedSources: boolean ): Promise { 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]) diff --git a/src/core/models.ts b/src/core/models.ts index 58971821e..5a156c5e4 100644 --- a/src/core/models.ts +++ b/src/core/models.ts @@ -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 { diff --git a/src/core/settings.ts b/src/core/settings.ts index 769e48dd7..e72d66d97 100644 --- a/src/core/settings.ts +++ b/src/core/settings.ts @@ -6,10 +6,14 @@ export class Settings { const includePrerelease = buildAgent.getBooleanInput( SetupFields.includePrerelease ) + const ignoreFailedSources = buildAgent.getBooleanInput( + SetupFields.ignoreFailedSources + ) return { versionSpec, - includePrerelease + includePrerelease, + ignoreFailedSources } } } diff --git a/src/tasks/gitreleasemanager/main.ts b/src/tasks/gitreleasemanager/main.ts index 68c86efb1..5e3936aea 100644 --- a/src/tasks/gitreleasemanager/main.ts +++ b/src/tasks/gitreleasemanager/main.ts @@ -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', diff --git a/src/tasks/gitversion/main.ts b/src/tasks/gitversion/main.ts index 70cf89b22..5d36280fa 100644 --- a/src/tasks/gitversion/main.ts +++ b/src/tasks/gitversion/main.ts @@ -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) { diff --git a/src/tools/gitreleasemanager/tool.ts b/src/tools/gitreleasemanager/tool.ts index 3950a4920..797f80781 100644 --- a/src/tools/gitreleasemanager/tool.ts +++ b/src/tools/gitreleasemanager/tool.ts @@ -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' @@ -16,7 +16,7 @@ import { } from './models' export interface IGitReleaseManagerTool extends IDotnetTool { - install(versionSpec: string, includePrerelease: boolean): Promise + install(setupSettings: ISetupSettings): Promise create(settings: GitReleaseManagerCreateSettings): Promise discard(settings: GitReleaseManagerDiscardSettings): Promise close(settings: GitReleaseManagerCloseSettings): Promise @@ -36,15 +36,11 @@ export class GitReleaseManagerTool super(buildAgent, versionManager) } - public async install( - versionSpec: string, - includePrerelease: boolean - ): Promise { + public async install(setupSettings: ISetupSettings): Promise { await this.toolInstall( 'GitReleaseManager.Tool', - versionSpec, false, - includePrerelease + setupSettings ) } diff --git a/src/tools/gitversion/tool.ts b/src/tools/gitversion/tool.ts index d5a90cb47..9053bc43b 100644 --- a/src/tools/gitversion/tool.ts +++ b/src/tools/gitversion/tool.ts @@ -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 + install(setupSettings: ISetupSettings): Promise run(options: GitVersionSettings): Promise writeGitVersionToAgent(gitversion: GitVersionOutput): void } @@ -21,15 +21,11 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool { super(buildAgent, versionManager) } - public async install( - versionSpec: string, - includePrerelease: boolean - ): Promise { + public async install(setupSettings: ISetupSettings): Promise { await this.toolInstall( 'GitVersion.Tool', - versionSpec, false, - includePrerelease + setupSettings ) }