move to webpack

This commit is contained in:
Artur Stolear
2020-01-15 17:06:32 +02:00
parent f09d4de93d
commit 019e954030
39 changed files with 80567 additions and 87108 deletions

54
.vscode/launch.json vendored
View File

@@ -5,40 +5,52 @@
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"preLaunchTask": "tsc: build - src/azure/tsconfig.json",
"name": "Run Azure Pipeline (setup) Task",
"program": "${workspaceFolder}/src/azure/setup.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
"preLaunchTask": "Build-Mock",
"name": "Debug Mock Setup GitVersion",
"program": "${workspaceFolder}/dist/mock/setup-gitversion/bundle.js",
"outFiles": [ "${workspaceFolder}/**/*.js" ]
},
{
"type": "node",
"request": "launch",
"preLaunchTask": "tsc: build - src/github/tsconfig.json",
"name": "Run GitHub Actions (setup)",
"program": "${workspaceFolder}/src/github/setup.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
"preLaunchTask": "Build-Azure",
"name": "Debug Azure Setup GitVersion",
"program": "${workspaceFolder}/dist/azure/setup-gitversion/bundle.js",
"outFiles": [ "${workspaceFolder}/**/*.js" ]
},
{
"type": "node",
"request": "launch",
"preLaunchTask": "tsc: build - src/azure/tsconfig.json",
"name": "Run Azure Pipeline (execute) Task",
"program": "${workspaceFolder}/src/azure/execute.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
"preLaunchTask": "Build-GitHub",
"name": "Debug GitHub Setup GitVersion",
"program": "${workspaceFolder}/dist/github/setup-gitversion/bundle.js",
"outFiles": [ "${workspaceFolder}/**/*.js" ]
},
{
"type": "node",
"request": "launch",
"preLaunchTask": "tsc: build - src/github/tsconfig.json",
"name": "Run GitHub Actions (execute)",
"program": "${workspaceFolder}/src/github/execute.ts",
"outFiles": ["${workspaceFolder}/**/*.js"]
}
"preLaunchTask": "Build-Mock",
"name": "Debug Mock Execute GitVersion",
"program": "${workspaceFolder}/dist/mock/execute-gitversion/bundle.js",
"outFiles": [ "${workspaceFolder}/**/*.js" ]
},
{
"type": "node",
"request": "launch",
"preLaunchTask": "Build-Azure",
"name": "Debug Azure Execute GitVersion",
"program": "${workspaceFolder}/dist/azure/execute-gitversion/bundle.js",
"outFiles": [ "${workspaceFolder}/**/*.js" ]
},
{
"type": "node",
"request": "launch",
"preLaunchTask": "Build-GitHub",
"name": "Debug GitHub Execute GitVersion",
"program": "${workspaceFolder}/dist/github/execute-gitversion/bundle.js",
"outFiles": [ "${workspaceFolder}/**/*.js" ]
},
]
}

22
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build-Mock",
"type": "npm",
"script": "build:mock"
},
{
"label": "Build-Azure",
"type": "npm",
"script": "build:azure"
},
{
"label": "Build-GitHub",
"type": "npm",
"script": "build:github"
},
]
}

18303
dist/azure/execute-gitversion/bundle.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -13,6 +13,13 @@
"Patch": "2"
},
"minimumAgentVersion": "2.115.0",
"execution": {
"Node": {
"target": "bundle.js",
"argumentFormat": "",
"workingDirectory": "."
}
},
"instanceNameFormat": "gitversion-execute",
"groups": [{
"name": "gitversionDetails",
@@ -78,12 +85,4 @@
"groupName": "additional"
}
],
"execution": {
"Node": {
"target": "index.js",
"argumentFormat": "",
"workingDirectory": "."
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,14 +0,0 @@
{
"messages": {
"TOOL_LIB_CachingTool": "Caching tool: %s %s %s",
"_TOOL_LIB_CachingTool.comment": "This informational log message indicates that a tool, that was just downloaded, is being copied into the cache directory. %s %s %s represent the tool name, version information, and processor architecture.",
"TOOL_LIB_Downloading": "Downloading: %s",
"_TOOL_LIB_Downloading.comment": "This information log message indicates that a file is being downloaded. %s represents the URL being downloaded.",
"TOOL_LIB_ExtractingArchive": "Extracting archive",
"_TOOL_LIB_ExtractingArchive.comment": "This informational log message indicates that an archive file is being extracted. For example, a .zip file, .7z file, or .tar.gz file.",
"TOOL_LIB_FoundInCache": "Found tool in cache: %s %s %s",
"_TOOL_LIB_FoundInCache.comment": "This informational log message indicates that the request tool is already cached, and does not need to be downloaded again. %s %s %s represent the tool name, version information, and processor architecture.",
"TOOL_LIB_PrependPath": "Prepending PATH environment variable with directory: %s",
"_TOOL_LIB_PrependPath.comment": "This informational log message indicates that a directory is being prepended to the front of the PATH environment variable. The directories specified by the PATH environment variable are used to resolve the location of command line tools."
}
}

View File

@@ -1,36 +0,0 @@
{
"messages": {
"LIB_UnhandledEx": "Unhandled: %s",
"LIB_FailOnCode": "Failure return code: %d",
"LIB_MkdirFailed": "Unable to create directory '%s'. %s",
"LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'",
"LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'",
"LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.",
"LIB_MultilineSecret": "Secrets cannot contain multiple lines",
"LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s",
"LIB_ProcessExitCode": "The process '%s' failed with exit code %s",
"LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream",
"LIB_ReturnCode": "Return code: %d",
"LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
"LIB_ResourceFileAlreadySet": "Resource file has already set to: %s",
"LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s",
"LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.",
"LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
"LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.",
"LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
"LIB_ParameterIsRequired": "%s not supplied",
"LIB_InputRequired": "Input required: %s",
"LIB_InvalidPattern": "Invalid pattern: '%s'",
"LIB_EndpointNotExist": "Endpoint not present: %s",
"LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
"LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
"LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
"LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
"LIB_PathNotFound": "Not found %s: %s",
"LIB_PathHasNullByte": "Path cannot contain null bytes",
"LIB_OperationFailed": "Failed %s: %s",
"LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
"LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
"LIB_PlatformNotSupported": "Platform not supported: %s"
}
}

18303
dist/azure/setup-gitversion/bundle.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,14 +0,0 @@
{
"messages": {
"TOOL_LIB_CachingTool": "Caching tool: %s %s %s",
"_TOOL_LIB_CachingTool.comment": "This informational log message indicates that a tool, that was just downloaded, is being copied into the cache directory. %s %s %s represent the tool name, version information, and processor architecture.",
"TOOL_LIB_Downloading": "Downloading: %s",
"_TOOL_LIB_Downloading.comment": "This information log message indicates that a file is being downloaded. %s represents the URL being downloaded.",
"TOOL_LIB_ExtractingArchive": "Extracting archive",
"_TOOL_LIB_ExtractingArchive.comment": "This informational log message indicates that an archive file is being extracted. For example, a .zip file, .7z file, or .tar.gz file.",
"TOOL_LIB_FoundInCache": "Found tool in cache: %s %s %s",
"_TOOL_LIB_FoundInCache.comment": "This informational log message indicates that the request tool is already cached, and does not need to be downloaded again. %s %s %s represent the tool name, version information, and processor architecture.",
"TOOL_LIB_PrependPath": "Prepending PATH environment variable with directory: %s",
"_TOOL_LIB_PrependPath.comment": "This informational log message indicates that a directory is being prepended to the front of the PATH environment variable. The directories specified by the PATH environment variable are used to resolve the location of command line tools."
}
}

View File

@@ -1,36 +0,0 @@
{
"messages": {
"LIB_UnhandledEx": "Unhandled: %s",
"LIB_FailOnCode": "Failure return code: %d",
"LIB_MkdirFailed": "Unable to create directory '%s'. %s",
"LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'",
"LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'",
"LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.",
"LIB_MultilineSecret": "Secrets cannot contain multiple lines",
"LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s",
"LIB_ProcessExitCode": "The process '%s' failed with exit code %s",
"LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream",
"LIB_ReturnCode": "Return code: %d",
"LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
"LIB_ResourceFileAlreadySet": "Resource file has already set to: %s",
"LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s",
"LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.",
"LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
"LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.",
"LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
"LIB_ParameterIsRequired": "%s not supplied",
"LIB_InputRequired": "Input required: %s",
"LIB_InvalidPattern": "Invalid pattern: '%s'",
"LIB_EndpointNotExist": "Endpoint not present: %s",
"LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
"LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
"LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
"LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
"LIB_PathNotFound": "Not found %s: %s",
"LIB_PathHasNullByte": "Path cannot contain null bytes",
"LIB_OperationFailed": "Failed %s: %s",
"LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
"LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
"LIB_PlatformNotSupported": "Platform not supported: %s"
}
}

View File

@@ -13,6 +13,14 @@
"Patch": "2"
},
"minimumAgentVersion": "2.115.0",
"execution": {
"Node": {
"target": "bundle.js",
"argumentFormat": "",
"workingDirectory": "."
}
},
"instanceNameFormat": "gitversion-setup",
"inputs": [{
"name": "versionSpec",
"type": "string",
@@ -30,13 +38,4 @@
"helpMarkDown": "Include pre-release versions when matching a version"
}
],
"instanceNameFormat": "gitversion-setup",
"execution": {
"Node": {
"target": "index.js",
"argumentFormat": "",
"workingDirectory": "."
}
}
}

16724
dist/azure/setup/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,14 +0,0 @@
{
"messages": {
"TOOL_LIB_CachingTool": "Caching tool: %s %s %s",
"_TOOL_LIB_CachingTool.comment": "This informational log message indicates that a tool, that was just downloaded, is being copied into the cache directory. %s %s %s represent the tool name, version information, and processor architecture.",
"TOOL_LIB_Downloading": "Downloading: %s",
"_TOOL_LIB_Downloading.comment": "This information log message indicates that a file is being downloaded. %s represents the URL being downloaded.",
"TOOL_LIB_ExtractingArchive": "Extracting archive",
"_TOOL_LIB_ExtractingArchive.comment": "This informational log message indicates that an archive file is being extracted. For example, a .zip file, .7z file, or .tar.gz file.",
"TOOL_LIB_FoundInCache": "Found tool in cache: %s %s %s",
"_TOOL_LIB_FoundInCache.comment": "This informational log message indicates that the request tool is already cached, and does not need to be downloaded again. %s %s %s represent the tool name, version information, and processor architecture.",
"TOOL_LIB_PrependPath": "Prepending PATH environment variable with directory: %s",
"_TOOL_LIB_PrependPath.comment": "This informational log message indicates that a directory is being prepended to the front of the PATH environment variable. The directories specified by the PATH environment variable are used to resolve the location of command line tools."
}
}

View File

@@ -1,36 +0,0 @@
{
"messages": {
"LIB_UnhandledEx": "Unhandled: %s",
"LIB_FailOnCode": "Failure return code: %d",
"LIB_MkdirFailed": "Unable to create directory '%s'. %s",
"LIB_MkdirFailedFileExists": "Unable to create directory '%s'. Conflicting file exists: '%s'",
"LIB_MkdirFailedInvalidDriveRoot": "Unable to create directory '%s'. Root directory does not exist: '%s'",
"LIB_MkdirFailedInvalidShare": "Unable to create directory '%s'. Unable to verify the directory exists: '%s'. If directory is a file share, please verify the share name is correct, the share is online, and the current process has permission to access the share.",
"LIB_MultilineSecret": "Secrets cannot contain multiple lines",
"LIB_ProcessError": "There was an error when attempting to execute the process '%s'. This may indicate the process failed to start. Error: %s",
"LIB_ProcessExitCode": "The process '%s' failed with exit code %s",
"LIB_ProcessStderr": "The process '%s' failed because one or more lines were written to the STDERR stream",
"LIB_ReturnCode": "Return code: %d",
"LIB_ResourceFileNotExist": "Resource file doesn\\'t exist: %s",
"LIB_ResourceFileAlreadySet": "Resource file has already set to: %s",
"LIB_ResourceFileNotSet": "Resource file haven\\'t set, can\\'t find loc string for key: %s",
"LIB_StdioNotClosed": "The STDIO streams did not close within %s seconds of the exit event from process '%s'. This may indicate a child process inherited the STDIO streams and has not yet exited.",
"LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
"LIB_WhichNotFound_Win": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.",
"LIB_LocStringNotFound": "Can\\'t find loc string for key: %s",
"LIB_ParameterIsRequired": "%s not supplied",
"LIB_InputRequired": "Input required: %s",
"LIB_InvalidPattern": "Invalid pattern: '%s'",
"LIB_EndpointNotExist": "Endpoint not present: %s",
"LIB_EndpointDataNotExist": "Endpoint data parameter %s not present: %s",
"LIB_EndpointAuthNotExist": "Endpoint auth data not present: %s",
"LIB_InvalidEndpointAuth": "Invalid endpoint auth: %s",
"LIB_InvalidSecureFilesInput": "Invalid secure file input: %s",
"LIB_PathNotFound": "Not found %s: %s",
"LIB_PathHasNullByte": "Path cannot contain null bytes",
"LIB_OperationFailed": "Failed %s: %s",
"LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
"LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
"LIB_PlatformNotSupported": "Platform not supported: %s"
}
}

12000
dist/github/execute-gitversion/bundle.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

12000
dist/github/setup-gitversion/bundle.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

7712
dist/mock/execute-gitversion/bundle.js vendored Normal file

File diff suppressed because one or more lines are too long

7712
dist/mock/setup-gitversion/bundle.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -4,6 +4,9 @@ author: GitTools
branding:
color: gray-dark
icon: git-pull-request
runs:
using: node12
main: ../dist/github/execute-gitversion/bundle.js
inputs:
targetPath:
description: Optionally supply the path to the working directory
@@ -89,7 +92,4 @@ outputs:
commitsSinceVersionSourcePadded:
description: 'The CommitsSinceVersionSourcePadded value'
commitDate:
description: 'The CommitDate value'
runs:
using: node12
main: ../dist/github/execute/index.js
description: 'The CommitDate value'

4312
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,13 +8,12 @@
},
"main": "main.js",
"scripts": {
"package": "npm run package-github && npm run package-azure",
"package-azure": "npm run package-azure-setup && npm run package-azure-execute",
"package-github": "npm run package-github-setup && npm run package-github-execute",
"package-azure-setup": "ncc build src/azure/setup.ts -o dist/azure/setup",
"package-azure-execute": "ncc build src/azure/execute.ts -o dist/azure/execute",
"package-github-setup": "ncc build src/github/setup.ts -o dist/github/setup",
"package-github-execute": "ncc build src/github/execute.ts -o dist/github/execute",
"build:mock": "webpack --config webpack.config.js --env.agent=mock",
"build:azure": "webpack --config webpack.config.js --env.agent=azure",
"build:github": "webpack --config webpack.config.js --env.agent=github",
"build:mock:prod": "npm run build:mock -- --env.mode=production",
"build:azure:prod": "npm run build:azure -- --env.mode=production",
"build:github:prod": "npm run build:github -- --env.mode=production",
"publish-azure": "tfx extension publish --root ./dist/azure --no-wait-validation --auth-type pat"
},
"author": "GitTools",
@@ -23,23 +22,27 @@
],
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/exec": "^1.0.1",
"@actions/io": "^1.0.1",
"@actions/tool-cache": "^1.1.2",
"azure-pipelines-task-lib": "2.9.3",
"azure-pipelines-tool-lib": "0.12.0",
"@actions/core": "^1.2.1",
"@actions/exec": "^1.0.3",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.3.0",
"azure-pipelines-task-lib": "^2.9.3",
"azure-pipelines-tool-lib": "^0.12.0",
"inversify": "^5.0.1",
"typed-rest-client": "1.5.0",
"typed-rest-client": "^1.7.1",
"uuid": "^3.3.3"
},
"devDependencies": {
"@types/node": "12.12.11",
"@types/q": "1.5.2",
"@types/node": "^13.1.7",
"@types/q": "^1.5.2",
"@types/uuid": "^3.4.6",
"@zeit/ncc": "^0.20.5",
"reflect-metadata": "^0.1.13",
"tfx-cli": "0.7.11",
"tfx-cli": "^0.7.11",
"ts-loader": "^6.2.1",
"tslint": "^5.20.1",
"typescript": "^3.7.2",
"@zeit/ncc": "^0.20.5"
"typescript": "^3.7.4",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"
}
}

View File

@@ -4,6 +4,9 @@ author: GitTools
branding:
color: gray-dark
icon: git-pull-request
runs:
using: node12
main: ../dist/github/setup-gitversion/bundle.js
inputs:
versionSpec:
description: Required version in the form of 5.x or exact version like 5.0.0
@@ -12,7 +15,4 @@ inputs:
includePrerelease:
description: Include pre-release versions when matching a version
required: false
default: false
runs:
using: node12
main: ../dist/github/setup/index.js
default: false

View File

@@ -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();
}
}

View File

@@ -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();
}

View 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,
};

View File

@@ -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);

View File

@@ -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);

View File

@@ -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());

View File

@@ -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>;

View File

@@ -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);

View File

@@ -0,0 +1,4 @@
import "reflect-metadata";
import { run } from "./core/gitversion";
run();

View File

@@ -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);

View File

@@ -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
View File

@@ -0,0 +1,4 @@
import "reflect-metadata";
import { setup } from "./core/gitversion";
setup();

View File

@@ -3,10 +3,11 @@
"module": "commonjs",
"moduleResolution": "node",
"target": "es2015",
"sourceMap": false,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"sourceMap": true,
"lib": ["es2015"],
"types": ["reflect-metadata"],
"inlineSourceMap": true,
"esModuleInterop":true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}