made gitversion & gitreleasemanager extend dotnet-tool

This commit is contained in:
Artur Stolear
2020-02-08 15:40:50 +02:00
parent 1be05ba386
commit aba63c943d
16 changed files with 201 additions and 230 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -8,15 +8,14 @@ import { TYPES, IExecResult, IBuildAgent } from "./common";
import { IVersionManager } from "./versionManager"; import { IVersionManager } from "./versionManager";
export interface IDotnetTool { export interface IDotnetTool {
run(args: string[]): Promise<IExecResult>;
toolInstall(toolName: string, versionSpec: string, checkLatest: boolean, includePre: boolean): Promise<string>; toolInstall(toolName: string, versionSpec: string, checkLatest: boolean, includePre: boolean): Promise<string>;
} }
@injectable() @injectable()
export class DotnetTool implements IDotnetTool { export class DotnetTool implements IDotnetTool {
private buildAgent: IBuildAgent; protected buildAgent: IBuildAgent;
private versionManager: IVersionManager; protected versionManager: IVersionManager;
private httpClient: http.HttpClient; private httpClient: http.HttpClient;
constructor( constructor(
@@ -28,8 +27,9 @@ export class DotnetTool implements IDotnetTool {
this.httpClient = new http.HttpClient("dotnet"); this.httpClient = new http.HttpClient("dotnet");
} }
public run(args: string[]): Promise<IExecResult> { public execute(cmd: string, args: string[]): Promise<IExecResult> {
return this.buildAgent.exec("dotnet", args); console.log(`Command: ${cmd} ${args.join(' ')}`);
return this.buildAgent.exec(cmd, args);
} }
public async toolInstall(toolName: string, versionSpec: string, checkLatest: boolean, includePre: boolean) public async toolInstall(toolName: string, versionSpec: string, checkLatest: boolean, includePre: boolean)
@@ -131,7 +131,7 @@ export class DotnetTool implements IDotnetTool {
args = args.concat(["--version", version]); args = args.concat(["--version", version]);
} }
const result = await this.run(args); const result = await this.execute("dotnet", args);
const status = result.code === 0 ? "success" : "failure"; const status = result.code === 0 ? "success" : "failure";
const message = result.code === 0 ? result.stdout : result.stderr; const message = result.code === 0 ? result.stdout : result.stderr;

View File

@@ -2,12 +2,10 @@ import { Container } from "inversify";
import { IVersionManager, VersionManager } from "./versionManager"; import { IVersionManager, VersionManager } from "./versionManager";
import { TYPES, IBuildAgent } from "./common"; import { TYPES, IBuildAgent } from "./common";
import { BuildAgent } from "../agent/mock/build-agent"; import { BuildAgent } from "../agent/mock/build-agent";
import { IDotnetTool, DotnetTool } from "./dotnet-tool";
const container = new Container(); const container = new Container();
container.bind<IVersionManager>(TYPES.IVersionManager).to(VersionManager); container.bind<IVersionManager>(TYPES.IVersionManager).to(VersionManager);
container.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent); container.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent);
container.bind<IDotnetTool>(TYPES.IDotnetTool).to(DotnetTool);
export default container; export default container;

View File

@@ -2,8 +2,9 @@ import path = require("path");
import { TYPES, IBuildAgent, IExecResult } from "../../core/common"; import { TYPES, IBuildAgent, IExecResult } from "../../core/common";
import { injectable, inject } from "inversify"; import { injectable, inject } from "inversify";
import { IDotnetTool } from "../../core/dotnet-tool"; import { DotnetTool } from "../../core/dotnet-tool";
import { GitReleaseManagerCreateSettings, GitReleaseManagerSettings, CreateFields, CommonFields } from "./models"; import { GitReleaseManagerCreateSettings, GitReleaseManagerSettings, CreateFields, CommonFields } from "./models";
import { IVersionManager } from "../../core/versionManager";
export interface IGitReleaseManagerTool { export interface IGitReleaseManagerTool {
install(versionSpec: string, includePrerelease: boolean): Promise<void>; install(versionSpec: string, includePrerelease: boolean): Promise<void>;
@@ -11,30 +12,23 @@ export interface IGitReleaseManagerTool {
} }
@injectable() @injectable()
export class GitReleaseManagerTool implements IGitReleaseManagerTool { export class GitReleaseManagerTool extends DotnetTool implements IGitReleaseManagerTool {
private buildAgent: IBuildAgent;
private dotnetTool: IDotnetTool;
constructor( constructor(
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent, @inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool, @inject(TYPES.IVersionManager) versionManager: IVersionManager
) { ) {
this.dotnetTool = dotnetTool; super(buildAgent, versionManager);
} }
public async install(versionSpec: string, includePrerelease: boolean): Promise<void> { public async install(versionSpec: string, includePrerelease: boolean): Promise<void> {
await this.dotnetTool.toolInstall("GitReleaseManager.Tool", versionSpec, false, includePrerelease); await this.toolInstall("GitReleaseManager.Tool", versionSpec, false, includePrerelease);
} }
public create(settings: GitReleaseManagerCreateSettings): Promise<IExecResult> { public create(settings: GitReleaseManagerCreateSettings): Promise<IExecResult> {
const args = this.getCreateArguments(settings); const args = this.getCreateArguments(settings);
console.log(args); return this.execute("dotnet-gitreleasemanager", args);
return Promise.resolve(null);
// return this.buildAgent.exec("dotnet-gitreleasemanager", args);
} }
getCommonArguments(settings: GitReleaseManagerSettings): string[] { getCommonArguments(settings: GitReleaseManagerSettings): string[] {
@@ -48,7 +42,7 @@ export class GitReleaseManagerTool implements IGitReleaseManagerTool {
} }
getCreateArguments(settings: GitReleaseManagerCreateSettings): string[] { getCreateArguments(settings: GitReleaseManagerCreateSettings): string[] {
const args: string[] = [...this.getCommonArguments(settings)]; const args: string[] = ['create', ...this.getCommonArguments(settings)];
if (settings.milestone) { if (settings.milestone) {
args.push("--milestone", settings.milestone); args.push("--milestone", settings.milestone);

View File

@@ -1,8 +1,9 @@
import path = require("path"); import path = require("path");
import { injectable, inject } from "inversify"; import { injectable, inject } from "inversify";
import { IExecResult, IBuildAgent, TYPES } from "../../core/common"; import { IExecResult, IBuildAgent, TYPES } from "../../core/common";
import { IDotnetTool } from "../../core/dotnet-tool"; import { DotnetTool } from "../../core/dotnet-tool";
import { GitVersionInput, GitVersionOutput, GitVersionRunOptions } from "./models"; import { GitVersionInput, GitVersionOutput, GitVersionRunOptions } from "./models";
import { IVersionManager } from "../../core/versionManager";
export interface IGitVersionTool { export interface IGitVersionTool {
install(versionSpec: string, includePrerelease: boolean): Promise<void>; install(versionSpec: string, includePrerelease: boolean): Promise<void>;
@@ -12,21 +13,17 @@ export interface IGitVersionTool {
} }
@injectable() @injectable()
export class GitVersionTool implements IGitVersionTool { export class GitVersionTool extends DotnetTool implements IGitVersionTool {
private buildAgent: IBuildAgent;
private dotnetTool: IDotnetTool;
constructor( constructor(
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent, @inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool, @inject(TYPES.IVersionManager) versionManager: IVersionManager
) { ) {
this.buildAgent = buildAgent; super(buildAgent, versionManager);
this.dotnetTool = dotnetTool;
} }
public async install(versionSpec: string, includePrerelease: boolean): Promise<void> { public async install(versionSpec: string, includePrerelease: boolean): Promise<void> {
await this.dotnetTool.toolInstall("GitVersion.Tool", versionSpec, false, includePrerelease); await this.toolInstall("GitVersion.Tool", versionSpec, false, includePrerelease);
} }
public run(options: GitVersionInput): Promise<IExecResult> { public run(options: GitVersionInput): Promise<IExecResult> {
@@ -34,7 +31,7 @@ export class GitVersionTool implements IGitVersionTool {
const args = this.getArguments(workDir, options); const args = this.getArguments(workDir, options);
return this.buildAgent.exec("dotnet-gitversion", args); return this.execute("dotnet-gitversion", args);
} }
private getRepoDir(targetPath: string): string { private getRepoDir(targetPath: string): string {
@@ -65,7 +62,7 @@ export class GitVersionTool implements IGitVersionTool {
updateAssemblyInfo, updateAssemblyInfo,
updateAssemblyInfoFilename, updateAssemblyInfoFilename,
additionalArguments, additionalArguments,
} = options; } = options;
if (useConfigFile) { if (useConfigFile) {
if (this.buildAgent.isValidInputFile("configFilePath", configFilePath)) { if (this.buildAgent.isValidInputFile("configFilePath", configFilePath)) {
@@ -114,35 +111,35 @@ export class GitVersionTool implements IGitVersionTool {
public writeGitVersionToAgent(gitversion: GitVersionOutput): void { public writeGitVersionToAgent(gitversion: GitVersionOutput): void {
this.buildAgent.setOutput("major", gitversion.Major.toString()); this.buildAgent.setOutput("major", gitversion.Major.toString());
this.buildAgent.setOutput("minor", gitversion.Minor.toString()); this.buildAgent.setOutput("minor", gitversion.Minor.toString());
this.buildAgent.setOutput("patch", gitversion.Patch.toString()); this.buildAgent.setOutput("patch", gitversion.Patch.toString());
this.buildAgent.setOutput("preReleaseTag", gitversion.PreReleaseTag); this.buildAgent.setOutput("preReleaseTag", gitversion.PreReleaseTag);
this.buildAgent.setOutput("preReleaseTagWithDash", gitversion.PreReleaseTagWithDash); this.buildAgent.setOutput("preReleaseTagWithDash", gitversion.PreReleaseTagWithDash);
this.buildAgent.setOutput("preReleaseLabel", gitversion.PreReleaseLabel); this.buildAgent.setOutput("preReleaseLabel", gitversion.PreReleaseLabel);
this.buildAgent.setOutput("preReleaseNumber", gitversion.PreReleaseNumber.toString()); this.buildAgent.setOutput("preReleaseNumber", gitversion.PreReleaseNumber.toString());
this.buildAgent.setOutput("weightedPreReleaseNumber", gitversion.WeightedPreReleaseNumber.toString()); this.buildAgent.setOutput("weightedPreReleaseNumber", gitversion.WeightedPreReleaseNumber.toString());
this.buildAgent.setOutput("buildMetaData", gitversion.BuildMetaData.toString()); this.buildAgent.setOutput("buildMetaData", gitversion.BuildMetaData.toString());
this.buildAgent.setOutput("buildMetaDataPadded", gitversion.BuildMetaDataPadded); this.buildAgent.setOutput("buildMetaDataPadded", gitversion.BuildMetaDataPadded);
this.buildAgent.setOutput("fullBuildMetaData", gitversion.FullBuildMetaData); this.buildAgent.setOutput("fullBuildMetaData", gitversion.FullBuildMetaData);
this.buildAgent.setOutput("majorMinorPatch", gitversion.MajorMinorPatch); this.buildAgent.setOutput("majorMinorPatch", gitversion.MajorMinorPatch);
this.buildAgent.setOutput("semVer", gitversion.SemVer); this.buildAgent.setOutput("semVer", gitversion.SemVer);
this.buildAgent.setOutput("legacySemVer", gitversion.LegacySemVer); this.buildAgent.setOutput("legacySemVer", gitversion.LegacySemVer);
this.buildAgent.setOutput("legacySemVerPadded", gitversion.LegacySemVerPadded); this.buildAgent.setOutput("legacySemVerPadded", gitversion.LegacySemVerPadded);
this.buildAgent.setOutput("assemblySemVer", gitversion.AssemblySemVer); this.buildAgent.setOutput("assemblySemVer", gitversion.AssemblySemVer);
this.buildAgent.setOutput("assemblySemFileVer", gitversion.AssemblySemFileVer); this.buildAgent.setOutput("assemblySemFileVer", gitversion.AssemblySemFileVer);
this.buildAgent.setOutput("fullSemVer", gitversion.FullSemVer); this.buildAgent.setOutput("fullSemVer", gitversion.FullSemVer);
this.buildAgent.setOutput("informationalVersion", gitversion.InformationalVersion); this.buildAgent.setOutput("informationalVersion", gitversion.InformationalVersion);
this.buildAgent.setOutput("branchName", gitversion.BranchName); this.buildAgent.setOutput("branchName", gitversion.BranchName);
this.buildAgent.setOutput("sha", gitversion.Sha); this.buildAgent.setOutput("sha", gitversion.Sha);
this.buildAgent.setOutput("shortSha", gitversion.ShortSha); this.buildAgent.setOutput("shortSha", gitversion.ShortSha);
this.buildAgent.setOutput("nuGetVersionV2", gitversion.NuGetVersionV2); this.buildAgent.setOutput("nuGetVersionV2", gitversion.NuGetVersionV2);
this.buildAgent.setOutput("nuGetVersion", gitversion.NuGetVersion); this.buildAgent.setOutput("nuGetVersion", gitversion.NuGetVersion);
this.buildAgent.setOutput("nuGetPreReleaseTagV2", gitversion.NuGetPreReleaseTagV2); this.buildAgent.setOutput("nuGetPreReleaseTagV2", gitversion.NuGetPreReleaseTagV2);
this.buildAgent.setOutput("nuGetPreReleaseTag", gitversion.NuGetPreReleaseTag); this.buildAgent.setOutput("nuGetPreReleaseTag", gitversion.NuGetPreReleaseTag);
this.buildAgent.setOutput("versionSourceSha", gitversion.VersionSourceSha); this.buildAgent.setOutput("versionSourceSha", gitversion.VersionSourceSha);
this.buildAgent.setOutput("commitsSinceVersionSource", gitversion.CommitsSinceVersionSource.toString()); this.buildAgent.setOutput("commitsSinceVersionSource", gitversion.CommitsSinceVersionSource.toString());
this.buildAgent.setOutput("commitsSinceVersionSourcePadded", gitversion.CommitsSinceVersionSourcePadded); this.buildAgent.setOutput("commitsSinceVersionSourcePadded", gitversion.CommitsSinceVersionSourcePadded);
this.buildAgent.setOutput("commitDate", gitversion.CommitDate); this.buildAgent.setOutput("commitDate", gitversion.CommitDate);
} }
} }