Skip to content

Commit

Permalink
moved the gitversion settings to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Feb 8, 2020
1 parent b98ee9d commit dab6b01
Show file tree
Hide file tree
Showing 20 changed files with 442 additions and 259 deletions.
9 changes: 6 additions & 3 deletions dist/azure/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/azure/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

87 changes: 56 additions & 31 deletions dist/azure/gitversion/execute/bundle.js

Large diffs are not rendered by default.

87 changes: 56 additions & 31 deletions dist/azure/gitversion/setup/bundle.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/github/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/github/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

87 changes: 56 additions & 31 deletions dist/github/gitversion/execute/bundle.js

Large diffs are not rendered by default.

87 changes: 56 additions & 31 deletions dist/github/gitversion/setup/bundle.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/mock/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/mock/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

87 changes: 56 additions & 31 deletions dist/mock/gitversion/execute/bundle.js

Large diffs are not rendered by default.

87 changes: 56 additions & 31 deletions dist/mock/gitversion/setup/bundle.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/core/dotnet-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TYPES, IExecResult, IBuildAgent } from "./common";
import { IVersionManager } from "./versionManager";

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

Expand All @@ -27,6 +28,10 @@ export class DotnetTool implements IDotnetTool {
this.httpClient = new http.HttpClient("dotnet");
}

public disableTelemetry(): void {
this.buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
}

public execute(cmd: string, args: string[]): Promise<IExecResult> {
console.log(`Command: ${cmd} ${args.join(' ')}`);
return this.buildAgent.exec(cmd, args);
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/gitreleasemanager/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent);
export async function setup() {
try {

buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
gitReleaseManagerTool.disableTelemetry();

const versionSpec = buildAgent.getInput(SetupOptions.versionSpec);
const includePrerelease = buildAgent.getBooleanInput(SetupOptions.includePrerelease);
Expand All @@ -28,7 +28,7 @@ export async function setup() {
export async function create() {
try {

buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
gitReleaseManagerTool.disableTelemetry();

const settings = Settings.getCreateSettings(buildAgent);

Expand Down
12 changes: 8 additions & 4 deletions src/tasks/gitversion/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IBuildAgent, TYPES, SetupOptions } from "../../core/common";
import { IGitVersionTool, GitVersionTool } from "../../tools/gitversion/gitversion-tool";
import { GitVersionInput, GitVersionOutput } from "../../tools/gitversion/models";
import { GitVersionSettings, GitVersionOutput } from "../../tools/gitversion/models";

import container from "../../core/ioc";
import { Settings } from "../../tools/gitversion/settings";

container.bind<IGitVersionTool>(TYPES.IGitVersionTool).to(GitVersionTool);

Expand All @@ -12,7 +13,7 @@ const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent);
export async function setup() {
try {

buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
gitVersionTool.disableTelemetry();

const versionSpec = buildAgent.getInput(SetupOptions.versionSpec);
const includePrerelease = buildAgent.getBooleanInput(SetupOptions.includePrerelease);
Expand All @@ -27,9 +28,12 @@ export async function setup() {

export async function run() {
try {
const inputOptions: GitVersionInput = gitVersionTool.getGitVersionInput();

const result = await gitVersionTool.run(inputOptions);
gitVersionTool.disableTelemetry();

const settings: GitVersionSettings = Settings.getGitVersionSettings(buildAgent);

const result = await gitVersionTool.run(settings);

const gitversion = JSON.parse(result.stdout) as GitVersionOutput;
gitVersionTool.writeGitVersionToAgent(gitversion);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/gitreleasemanager/gitreleasemanager-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import path = require("path");

import { TYPES, IBuildAgent, IExecResult } from "../../core/common";
import { injectable, inject } from "inversify";
import { DotnetTool } from "../../core/dotnet-tool";
import { DotnetTool, IDotnetTool } from "../../core/dotnet-tool";
import { GitReleaseManagerCreateSettings, GitReleaseManagerSettings, CreateFields, CommonFields } from "./models";
import { IVersionManager } from "../../core/versionManager";

export interface IGitReleaseManagerTool {
export interface IGitReleaseManagerTool extends IDotnetTool {
install(versionSpec: string, includePrerelease: boolean): Promise<void>;
create(settings: GitReleaseManagerCreateSettings): Promise<IExecResult>;
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/gitreleasemanager/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IBuildAgent } from "../../core/common";
import { GitReleaseManagerSettings, CommonFields, CreateFields } from "./models";

export class Settings {

public static getCreateSettings(buildAgent: IBuildAgent) {
const milestone = buildAgent.getInput(CreateFields.milestone);
const releaseName = buildAgent.getInput(CreateFields.releaseName);
Expand Down
38 changes: 6 additions & 32 deletions src/tools/gitversion/gitversion-tool.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import path = require("path");
import { injectable, inject } from "inversify";
import { IExecResult, IBuildAgent, TYPES } from "../../core/common";
import { DotnetTool } from "../../core/dotnet-tool";
import { GitVersionInput, GitVersionOutput, GitVersionRunOptions } from "./models";
import { DotnetTool, IDotnetTool } from "../../core/dotnet-tool";
import { GitVersionSettings, GitVersionOutput, ExecuteFields } from "./models";
import { IVersionManager } from "../../core/versionManager";

export interface IGitVersionTool {
export interface IGitVersionTool extends IDotnetTool {
install(versionSpec: string, includePrerelease: boolean): Promise<void>;
run(options: GitVersionInput): Promise<IExecResult>;
run(options: GitVersionSettings): Promise<IExecResult>;
writeGitVersionToAgent(gitversion: GitVersionOutput): void;
getGitVersionInput(): GitVersionInput;
}

@injectable()
Expand All @@ -26,7 +25,7 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
await this.toolInstall("GitVersion.Tool", versionSpec, false, includePrerelease);
}

public run(options: GitVersionInput): Promise<IExecResult> {
public run(options: GitVersionSettings): Promise<IExecResult> {
const workDir = this.getRepoDir(options.targetPath);

const args = this.getArguments(workDir, options);
Expand All @@ -49,7 +48,7 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
return workDir.replace(/\\/g, "/");
}

private getArguments(workDir: string, options: GitVersionInput): string[] {
private getArguments(workDir: string, options: GitVersionSettings): string[] {
const args = [
workDir,
"/output",
Expand Down Expand Up @@ -84,31 +83,6 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
return args;
}

public getGitVersionInput(): GitVersionInput {

const targetPath = this.buildAgent.getInput(GitVersionRunOptions.targetPath);

const useConfigFile = this.buildAgent.getBooleanInput(GitVersionRunOptions.useConfigFile);
const configFilePath = this.buildAgent.getInput(GitVersionRunOptions.configFilePath);

const updateAssemblyInfo = this.buildAgent.getBooleanInput(GitVersionRunOptions.updateAssemblyInfo);
const updateAssemblyInfoFilename = this.buildAgent.getInput(GitVersionRunOptions.updateAssemblyInfoFilename);

const additionalArguments = this.buildAgent.getInput(GitVersionRunOptions.additionalArguments);

const srcDir = this.buildAgent.getSourceDir().replace(/\\/g, "/");

return {
targetPath,
useConfigFile,
configFilePath,
updateAssemblyInfo,
updateAssemblyInfoFilename,
additionalArguments,
srcDir,
};
}

public writeGitVersionToAgent(gitversion: GitVersionOutput): void {

this.buildAgent.setOutput("major", gitversion.Major.toString());
Expand Down
31 changes: 16 additions & 15 deletions src/tools/gitversion/models.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
export const GitVersionRunOptions = {
targetPath: "targetPath",
useConfigFile: "useConfigFile",
configFilePath: "configFilePath",
updateAssemblyInfo: "configFilePath",
updateAssemblyInfoFilename: "configFilePath",
additionalArguments: "additionalArguments",
export enum ExecuteFields {
targetPath = "targetPath",
useConfigFile = "useConfigFile",
configFilePath = "configFilePath",
updateAssemblyInfo = "updateAssemblyInfo",
updateAssemblyInfoFilename = "updateAssemblyInfoFilename",
additionalArguments = "additionalArguments",
srcDir = "srcDir",
};

export interface GitVersionInput {
targetPath: string;
useConfigFile: boolean;
configFilePath: string;
updateAssemblyInfo: boolean;
updateAssemblyInfoFilename: string;
additionalArguments: string;
srcDir: string;
export interface GitVersionSettings {
[ExecuteFields.targetPath]: string;
[ExecuteFields.useConfigFile]: boolean;
[ExecuteFields.configFilePath]: string;
[ExecuteFields.updateAssemblyInfo]: boolean;
[ExecuteFields.updateAssemblyInfoFilename]: string;
[ExecuteFields.additionalArguments]: string;
[ExecuteFields.srcDir]: string;
}

export interface GitVersionOutput {
Expand Down
30 changes: 30 additions & 0 deletions src/tools/gitversion/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IBuildAgent } from "../../core/common";

import { GitVersionSettings, ExecuteFields } from "./models";

export class Settings {

public static getGitVersionSettings(buildAgent: IBuildAgent): GitVersionSettings {
const targetPath = buildAgent.getInput(ExecuteFields.targetPath);

const useConfigFile = buildAgent.getBooleanInput(ExecuteFields.useConfigFile);
const configFilePath = buildAgent.getInput(ExecuteFields.configFilePath);

const updateAssemblyInfo = buildAgent.getBooleanInput(ExecuteFields.updateAssemblyInfo);
const updateAssemblyInfoFilename = buildAgent.getInput(ExecuteFields.updateAssemblyInfoFilename);

const additionalArguments = buildAgent.getInput(ExecuteFields.additionalArguments);

const srcDir = buildAgent.getSourceDir().replace(/\\/g, "/");

return {
targetPath,
useConfigFile,
configFilePath,
updateAssemblyInfo,
updateAssemblyInfoFilename,
additionalArguments,
srcDir,
};
}
}

0 comments on commit dab6b01

Please sign in to comment.