added GitVersion run implementation
This commit is contained in:
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -16,6 +16,3 @@ jobs:
|
|||||||
versionSpec: '5.1.x'
|
versionSpec: '5.1.x'
|
||||||
- name: Use GitVersion
|
- name: Use GitVersion
|
||||||
uses: ./execute
|
uses: ./execute
|
||||||
with:
|
|
||||||
targetPath: '.'
|
|
||||||
useConfigFile: 'true'
|
|
||||||
|
|||||||
876
dist/github/execute/index.js
vendored
876
dist/github/execute/index.js
vendored
File diff suppressed because one or more lines are too long
863
dist/github/setup/index.js
vendored
863
dist/github/setup/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -72,6 +72,18 @@ class BuildAgent implements IBuildAgent {
|
|||||||
public getBooleanInput(input: string, required?: boolean): boolean {
|
public getBooleanInput(input: string, required?: boolean): boolean {
|
||||||
return taskLib.getBoolInput(input, required);
|
return taskLib.getBoolInput(input, required);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isValidInputFile(input: string, file: string) {
|
||||||
|
return taskLib.filePathSupplied(input) && this.fileExists(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public fileExists(file: string) {
|
||||||
|
return taskLib.exist(file) && taskLib.stats(file).isFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public directoryExists(file: string) {
|
||||||
|
return taskLib.exist(file) && taskLib.stats(file).isDirectory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ class GitVersionTool implements IGitVersionTool {
|
|||||||
|
|
||||||
private buildAgent: IBuildAgent;
|
private buildAgent: IBuildAgent;
|
||||||
private dotnetTool: IDotnetTool;
|
private dotnetTool: IDotnetTool;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
||||||
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool,
|
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool,
|
||||||
@@ -161,10 +162,61 @@ class GitVersionTool implements IGitVersionTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public run(options: IGitVersionOptions): Promise<IExecResult> {
|
public run(options: IGitVersionOptions): Promise<IExecResult> {
|
||||||
console.log("Workspace: " + this.buildAgent.getSourceDir());
|
const workDir = this.getRepoDir(options.targetPath);
|
||||||
|
|
||||||
console.log(options);
|
const args = this.getArguments(workDir, options);
|
||||||
return;
|
|
||||||
|
return this.buildAgent.exec("dotnet-gitversion", args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getRepoDir(targetPath: string): string {
|
||||||
|
let workDir: string;
|
||||||
|
const srcDir = this.buildAgent.getSourceDir();
|
||||||
|
if (!targetPath) {
|
||||||
|
workDir = srcDir;
|
||||||
|
} else {
|
||||||
|
if (this.buildAgent.directoryExists(targetPath)) {
|
||||||
|
workDir = path.join(srcDir, targetPath);
|
||||||
|
} else {
|
||||||
|
throw new Error("Directory not found at " + targetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return workDir.replace(/\\/g, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
private getArguments(workDir: string, options: IGitVersionOptions) {
|
||||||
|
const args = [
|
||||||
|
workDir,
|
||||||
|
"/output",
|
||||||
|
"buildserver",
|
||||||
|
];
|
||||||
|
|
||||||
|
const {
|
||||||
|
useConfigFile,
|
||||||
|
configFilePath,
|
||||||
|
updateAssemblyInfo,
|
||||||
|
updateAssemblyInfoFilename,
|
||||||
|
additionalArguments,
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
if (useConfigFile) {
|
||||||
|
if (this.buildAgent.isValidInputFile("configFilePath", configFilePath)) {
|
||||||
|
args.push("/config", configFilePath);
|
||||||
|
} else {
|
||||||
|
throw new Error("GitVersion configuration file not found at " + configFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (updateAssemblyInfo) {
|
||||||
|
args.push("/updateassemblyinfo");
|
||||||
|
if (this.buildAgent.isValidInputFile("updateAssemblyInfoFilename", updateAssemblyInfoFilename)) {
|
||||||
|
args.push(updateAssemblyInfoFilename);
|
||||||
|
} else {
|
||||||
|
throw new Error("AssemblyInfoFilename file not found at " + updateAssemblyInfoFilename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push(additionalArguments);
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as uuidV4 from "uuid/v4";
|
import * as uuidV4 from "uuid/v4";
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ import { IBuildAgent, IExecResult } from "../interfaces";
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
class BuildAgent implements IBuildAgent {
|
class BuildAgent implements IBuildAgent {
|
||||||
|
public Stats;
|
||||||
|
|
||||||
public find(toolName: string, versionSpec: string, arch?: string): string {
|
public find(toolName: string, versionSpec: string, arch?: string): string {
|
||||||
return toolCache.find(toolName, versionSpec, arch);
|
return toolCache.find(toolName, versionSpec, arch);
|
||||||
@@ -111,7 +113,39 @@ class BuildAgent implements IBuildAgent {
|
|||||||
const inputValue = this.getInput(input, required);
|
const inputValue = this.getInput(input, required);
|
||||||
return (inputValue || "false").toLowerCase() === "true";
|
return (inputValue || "false").toLowerCase() === "true";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public isValidInputFile(input: string, file: string) {
|
||||||
|
const pathValue = path.resolve(this.getInput(input) || "");
|
||||||
|
const repoRoot = this.getSourceDir();
|
||||||
|
return pathValue !== repoRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public fileExists(file: string) {
|
||||||
|
return this._exist(file) && this._stats(file).isFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public directoryExists(file: string) {
|
||||||
|
return this._exist(file) && this._stats(file).isDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _exist(file: string): boolean {
|
||||||
|
let exist = false;
|
||||||
|
try {
|
||||||
|
exist = !!(file && fs.statSync(file) != null);
|
||||||
|
} catch (err) {
|
||||||
|
if (err && err.code === "ENOENT") {
|
||||||
|
exist = false;
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _stats(file: string): fs.Stats {
|
||||||
|
return fs.statSync(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
BuildAgent,
|
BuildAgent,
|
||||||
|
|||||||
@@ -9,16 +9,13 @@ const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
|||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
|
||||||
|
|
||||||
const inputOptions: IGitVersionOptions = getGitVersionOptions();
|
const inputOptions: IGitVersionOptions = getGitVersionOptions();
|
||||||
|
|
||||||
await gitVersionTool.run(inputOptions);
|
await gitVersionTool.run(inputOptions);
|
||||||
|
|
||||||
buildAgent.setSucceeded("GitVersion installed successfully", true);
|
buildAgent.setSucceeded("GitVersion installed successfully", true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
buildAgent.setFailed(error.message, true);
|
buildAgent.setFailed(error, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +31,8 @@ function getGitVersionOptions(): IGitVersionOptions {
|
|||||||
|
|
||||||
const additionalArguments = buildAgent.getInput(RunOptions.additionalArguments);
|
const additionalArguments = buildAgent.getInput(RunOptions.additionalArguments);
|
||||||
|
|
||||||
|
const srcDir = buildAgent.getSourceDir().replace(/\\/g, "/");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
targetPath,
|
targetPath,
|
||||||
useConfigFile,
|
useConfigFile,
|
||||||
@@ -41,6 +40,7 @@ function getGitVersionOptions(): IGitVersionOptions {
|
|||||||
updateAssemblyInfo,
|
updateAssemblyInfo,
|
||||||
updateAssemblyInfoFilename,
|
updateAssemblyInfoFilename,
|
||||||
additionalArguments,
|
additionalArguments,
|
||||||
|
srcDir,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ export interface IBuildAgent {
|
|||||||
which: (tool: string, check?: boolean) => Promise<string>;
|
which: (tool: string, check?: boolean) => Promise<string>;
|
||||||
exec: (exec: string, args: string[]) => Promise<IExecResult>;
|
exec: (exec: string, args: string[]) => Promise<IExecResult>;
|
||||||
getSourceDir: () => string;
|
getSourceDir: () => string;
|
||||||
|
isValidInputFile(input: string, file: string): boolean;
|
||||||
|
fileExists(file: string): boolean;
|
||||||
|
directoryExists(file: string): boolean;
|
||||||
|
|
||||||
getInput(input: string, required?: boolean): string;
|
getInput(input: string, required?: boolean): string;
|
||||||
getBooleanInput(input: string, required?: boolean): boolean;
|
getBooleanInput(input: string, required?: boolean): boolean;
|
||||||
@@ -49,4 +52,5 @@ export interface IGitVersionOptions {
|
|||||||
updateAssemblyInfo: boolean;
|
updateAssemblyInfo: boolean;
|
||||||
updateAssemblyInfoFilename: string;
|
updateAssemblyInfoFilename: string;
|
||||||
additionalArguments: string;
|
additionalArguments: string;
|
||||||
|
srcDir: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user