move to webpack
This commit is contained in:
@@ -3,11 +3,15 @@ import { injectable } from "inversify";
|
||||
import * as taskLib from "azure-pipelines-task-lib/task";
|
||||
import * as toolLib from "azure-pipelines-tool-lib/tool";
|
||||
|
||||
import { IBuildAgent, IExecResult } from "../core/interfaces";
|
||||
import { IBuildAgent, IExecResult } from "../../core/interfaces";
|
||||
|
||||
@injectable()
|
||||
class BuildAgent implements IBuildAgent {
|
||||
|
||||
public get agentName(): string {
|
||||
return "Azure Pipelines";
|
||||
}
|
||||
|
||||
public find(toolName: string, versionSpec: string, arch?: string): string {
|
||||
return toolLib.findLocalTool(toolName, versionSpec, arch);
|
||||
}
|
||||
@@ -77,15 +81,15 @@ class BuildAgent implements IBuildAgent {
|
||||
return taskLib.getBoolInput(input, required);
|
||||
}
|
||||
|
||||
public isValidInputFile(input: string, file: string) {
|
||||
public isValidInputFile(input: string, file: string): boolean {
|
||||
return taskLib.filePathSupplied(input) && this.fileExists(file);
|
||||
}
|
||||
|
||||
public fileExists(file: string) {
|
||||
public fileExists(file: string): boolean {
|
||||
return taskLib.exist(file) && taskLib.stats(file).isFile();
|
||||
}
|
||||
|
||||
public directoryExists(file: string) {
|
||||
public directoryExists(file: string): boolean {
|
||||
return taskLib.exist(file) && taskLib.stats(file).isDirectory();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as uuidV4 from "uuid/v4";
|
||||
|
||||
import uuidv4 from "uuid";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import * as exe from "@actions/exec";
|
||||
@@ -9,11 +10,15 @@ import * as toolCache from "@actions/tool-cache";
|
||||
|
||||
import { injectable } from "inversify";
|
||||
|
||||
import { IBuildAgent, IExecResult } from "../core/interfaces";
|
||||
import { IBuildAgent, IExecResult } from "../../core/interfaces";
|
||||
|
||||
@injectable()
|
||||
class BuildAgent implements IBuildAgent {
|
||||
|
||||
public get agentName(): string {
|
||||
return "GitHub Actions";
|
||||
}
|
||||
|
||||
public find(toolName: string, versionSpec: string, arch?: string): string {
|
||||
return toolCache.find(toolName, versionSpec, arch);
|
||||
}
|
||||
@@ -41,7 +46,7 @@ class BuildAgent implements IBuildAgent {
|
||||
}
|
||||
tempDirectory = path.join(baseLocation, "actions", "temp");
|
||||
}
|
||||
const dest = path.join(tempDirectory, uuidV4());
|
||||
const dest = path.join(tempDirectory, uuidv4());
|
||||
await io.mkdirP(dest);
|
||||
return dest;
|
||||
}
|
||||
@@ -117,17 +122,17 @@ class BuildAgent implements IBuildAgent {
|
||||
return (inputValue || "false").toLowerCase() === "true";
|
||||
}
|
||||
|
||||
public isValidInputFile(input: string, file: string) {
|
||||
public isValidInputFile(input: string, file: string): boolean {
|
||||
const pathValue = path.resolve(this.getInput(input) || "");
|
||||
const repoRoot = this.getSourceDir();
|
||||
return pathValue !== repoRoot;
|
||||
}
|
||||
|
||||
public fileExists(file: string) {
|
||||
public fileExists(file: string): boolean {
|
||||
return this._exist(file) && this._stats(file).isFile();
|
||||
}
|
||||
|
||||
public directoryExists(file: string) {
|
||||
public directoryExists(file: string): boolean {
|
||||
return this._exist(file) && this._stats(file).isDirectory();
|
||||
}
|
||||
|
||||
104
src/agent/mock/build-agent.ts
Normal file
104
src/agent/mock/build-agent.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { injectable } from "inversify";
|
||||
|
||||
import { IBuildAgent, IExecResult } from "../../core/interfaces";
|
||||
|
||||
@injectable()
|
||||
class BuildAgent implements IBuildAgent {
|
||||
|
||||
public get agentName(): string {
|
||||
console.log("getAgentName");
|
||||
return "Mock";
|
||||
}
|
||||
|
||||
public find(toolName: string, versionSpec: string, arch?: string): string {
|
||||
console.log("find");
|
||||
return "find";
|
||||
}
|
||||
|
||||
public cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string> {
|
||||
console.log("cacheDir");
|
||||
return Promise.resolve("cacheDir");
|
||||
}
|
||||
|
||||
public createTempDir(): Promise<string> {
|
||||
console.log("createTempDir");
|
||||
return Promise.resolve("createTempDir");
|
||||
}
|
||||
|
||||
public debug(message: string): void {
|
||||
console.log("debug");
|
||||
}
|
||||
|
||||
public setFailed(message: string, done?: boolean): void {
|
||||
console.log("setFailed");
|
||||
}
|
||||
|
||||
public setSucceeded(message: string, done?: boolean): void {
|
||||
console.log("setSucceeded");
|
||||
}
|
||||
|
||||
public exportVariable(name: string, val: string): void {
|
||||
console.log("exportVariable");
|
||||
}
|
||||
|
||||
public getVariable(name: string): string {
|
||||
console.log("getVariable");
|
||||
return "getVariable";
|
||||
}
|
||||
|
||||
public addPath(inputPath: string): void {
|
||||
console.log("addPath");
|
||||
}
|
||||
|
||||
public which(tool: string, check?: boolean): Promise<string> {
|
||||
console.log("which");
|
||||
return Promise.resolve("which");
|
||||
}
|
||||
|
||||
public exec(exec: string, args: string[]): Promise<IExecResult> {
|
||||
return Promise.resolve({
|
||||
code: 0,
|
||||
error: null,
|
||||
stderr: "result.stderr",
|
||||
stdout: "result.stdout",
|
||||
});
|
||||
}
|
||||
|
||||
public getSourceDir(): string {
|
||||
console.log("getSourceDir");
|
||||
return "getSourceDir";
|
||||
}
|
||||
|
||||
public setOutput(name: string, value: string): void {
|
||||
console.log("setOutput");
|
||||
}
|
||||
|
||||
public getInput(input: string, required?: boolean): string {
|
||||
console.log("getInput");
|
||||
return "getInput";
|
||||
}
|
||||
|
||||
public getBooleanInput(input: string, required?: boolean): boolean {
|
||||
console.log("getBooleanInput");
|
||||
return false;
|
||||
}
|
||||
|
||||
public isValidInputFile(input: string, file: string) {
|
||||
console.log("isValidInputFile");
|
||||
return false;
|
||||
}
|
||||
|
||||
public fileExists(file: string) {
|
||||
console.log("fileExists");
|
||||
return false;
|
||||
}
|
||||
|
||||
public directoryExists(file: string) {
|
||||
console.log("directoryExists");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
BuildAgent,
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
import "reflect-metadata";
|
||||
|
||||
import { IBuildAgent, IGitVersionTool } from "../core/interfaces";
|
||||
import { ioc } from "../core/ioc";
|
||||
import { run } from "../core/main";
|
||||
import { TYPES } from "../core/types";
|
||||
import { BuildAgent } from "./build-agent";
|
||||
|
||||
ioc.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent);
|
||||
|
||||
const gitVersionTool = ioc.get<IGitVersionTool>(TYPES.IGitVersionTool);
|
||||
const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
||||
|
||||
run(buildAgent, gitVersionTool);
|
||||
@@ -1,14 +0,0 @@
|
||||
import "reflect-metadata";
|
||||
|
||||
import { IBuildAgent, IGitVersionTool } from "../core/interfaces";
|
||||
import { ioc } from "../core/ioc";
|
||||
import { setup } from "../core/main";
|
||||
import { TYPES } from "../core/types";
|
||||
import { BuildAgent } from "./build-agent";
|
||||
|
||||
ioc.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent);
|
||||
|
||||
const gitVersionTool = ioc.get<IGitVersionTool>(TYPES.IGitVersionTool);
|
||||
const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
||||
|
||||
setup(buildAgent, gitVersionTool);
|
||||
@@ -1,8 +1,11 @@
|
||||
import { IBuildAgent, IGitVersion, IGitVersionOptions, IGitVersionTool } from "./interfaces";
|
||||
import { ioc } from "./ioc";
|
||||
import { RunOptions, SetupOptions, TYPES } from "./types";
|
||||
|
||||
import { RunOptions, SetupOptions } from "./types";
|
||||
const gitVersionTool = ioc.get<IGitVersionTool>(TYPES.IGitVersionTool);
|
||||
const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
||||
|
||||
export async function setup(buildAgent: IBuildAgent, gitVersionTool: IGitVersionTool) {
|
||||
export async function setup() {
|
||||
try {
|
||||
|
||||
buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
||||
@@ -18,14 +21,14 @@ export async function setup(buildAgent: IBuildAgent, gitVersionTool: IGitVersion
|
||||
}
|
||||
}
|
||||
|
||||
export async function run(buildAgent: IBuildAgent, gitVersionTool: IGitVersionTool) {
|
||||
export async function run() {
|
||||
try {
|
||||
const inputOptions: IGitVersionOptions = getGitVersionOptions(buildAgent);
|
||||
const inputOptions: IGitVersionOptions = getGitVersionOptions();
|
||||
|
||||
const result = await gitVersionTool.run(inputOptions);
|
||||
|
||||
const gitversion = JSON.parse(result.stdout) as IGitVersion;
|
||||
writeGitVersionToAgent(buildAgent, gitversion);
|
||||
writeGitVersionToAgent(gitversion);
|
||||
|
||||
if (result.code === 0) {
|
||||
buildAgent.setSucceeded("GitVersion executed successfully", true);
|
||||
@@ -38,7 +41,7 @@ export async function run(buildAgent: IBuildAgent, gitVersionTool: IGitVersionTo
|
||||
}
|
||||
}
|
||||
|
||||
function getGitVersionOptions(buildAgent: IBuildAgent): IGitVersionOptions {
|
||||
function getGitVersionOptions(): IGitVersionOptions {
|
||||
|
||||
const targetPath = buildAgent.getInput(RunOptions.targetPath);
|
||||
|
||||
@@ -63,7 +66,7 @@ function getGitVersionOptions(buildAgent: IBuildAgent): IGitVersionOptions {
|
||||
};
|
||||
}
|
||||
|
||||
function writeGitVersionToAgent(buildAgent: IBuildAgent, gitversion: IGitVersion): void {
|
||||
function writeGitVersionToAgent(gitversion: IGitVersion): void {
|
||||
|
||||
buildAgent.setOutput("major", gitversion.Major.toString());
|
||||
buildAgent.setOutput("minor", gitversion.Minor.toString());
|
||||
@@ -5,6 +5,7 @@ export interface IVersionManager {
|
||||
}
|
||||
|
||||
export interface IBuildAgent {
|
||||
agentName: string;
|
||||
find(toolName: string, versionSpec: string, arch?: string): string;
|
||||
cacheDir(sourceDir: string, tool: string, version: string, arch?: string): Promise<string>;
|
||||
createTempDir(): Promise<string>;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { Container } from "inversify";
|
||||
|
||||
import { BuildAgent } from "../agent/mock/build-agent";
|
||||
import { DotnetTool, GitVersionTool, VersionManager } from "./common";
|
||||
import { IDotnetTool, IGitVersionTool, IVersionManager } from "./interfaces";
|
||||
import { IBuildAgent, IDotnetTool, IGitVersionTool, IVersionManager } from "./interfaces";
|
||||
import { TYPES } from "./types";
|
||||
|
||||
const ioc = new Container();
|
||||
|
||||
ioc.bind<IVersionManager>(TYPES.IVersionManager).to(VersionManager);
|
||||
ioc.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent);
|
||||
ioc.bind<IDotnetTool>(TYPES.IDotnetTool).to(DotnetTool);
|
||||
ioc.bind<IGitVersionTool>(TYPES.IGitVersionTool).to(GitVersionTool);
|
||||
|
||||
|
||||
4
src/execute-gitversion.ts
Normal file
4
src/execute-gitversion.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import "reflect-metadata";
|
||||
import { run } from "./core/gitversion";
|
||||
|
||||
run();
|
||||
@@ -1,14 +0,0 @@
|
||||
import "reflect-metadata";
|
||||
|
||||
import { IBuildAgent, IGitVersionTool } from "../core/interfaces";
|
||||
import { ioc } from "../core/ioc";
|
||||
import { run } from "../core/main";
|
||||
import { TYPES } from "../core/types";
|
||||
import { BuildAgent } from "./build-agent";
|
||||
|
||||
ioc.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent);
|
||||
|
||||
const gitVersionTool = ioc.get<IGitVersionTool>(TYPES.IGitVersionTool);
|
||||
const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
||||
|
||||
run(buildAgent, gitVersionTool);
|
||||
@@ -1,14 +0,0 @@
|
||||
import "reflect-metadata";
|
||||
|
||||
import { IBuildAgent, IGitVersionTool } from "../core/interfaces";
|
||||
import { ioc } from "../core/ioc";
|
||||
import { setup } from "../core/main";
|
||||
import { TYPES } from "../core/types";
|
||||
import { BuildAgent } from "./build-agent";
|
||||
|
||||
ioc.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent);
|
||||
|
||||
const gitVersionTool = ioc.get<IGitVersionTool>(TYPES.IGitVersionTool);
|
||||
const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
||||
|
||||
setup(buildAgent, gitVersionTool);
|
||||
4
src/setup-gitversion.ts
Normal file
4
src/setup-gitversion.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import "reflect-metadata";
|
||||
import { setup } from "./core/gitversion";
|
||||
|
||||
setup();
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"target": "es2015",
|
||||
"sourceMap": false,
|
||||
"lib": ["es2015", "dom"],
|
||||
"types": ["reflect-metadata"],
|
||||
"inlineSourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user