re-arranged files
This commit is contained in:
14
.eslintrc.js
Normal file
14
.eslintrc.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: [
|
||||||
|
'@typescript-eslint',
|
||||||
|
'sort-keys-fix'
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/eslint-recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'prettier/@typescript-eslint',
|
||||||
|
],
|
||||||
|
};
|
||||||
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@@ -8,6 +8,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [windows-latest, ubuntu-latest, macos-latest]
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Fetch all history for all tags and branches
|
- name: Fetch all history for all tags and branches
|
||||||
|
|||||||
245
dist/azure/gitreleasemanager/setup/bundle.js
vendored
245
dist/azure/gitreleasemanager/setup/bundle.js
vendored
File diff suppressed because one or more lines are too long
465
dist/azure/gitversion/execute/bundle.js
vendored
465
dist/azure/gitversion/execute/bundle.js
vendored
File diff suppressed because one or more lines are too long
367
dist/azure/gitversion/setup/bundle.js
vendored
367
dist/azure/gitversion/setup/bundle.js
vendored
File diff suppressed because one or more lines are too long
685
dist/github/gitreleasemanager/setup/bundle.js
vendored
685
dist/github/gitreleasemanager/setup/bundle.js
vendored
File diff suppressed because one or more lines are too long
905
dist/github/gitversion/execute/bundle.js
vendored
905
dist/github/gitversion/execute/bundle.js
vendored
File diff suppressed because one or more lines are too long
807
dist/github/gitversion/setup/bundle.js
vendored
807
dist/github/gitversion/setup/bundle.js
vendored
File diff suppressed because one or more lines are too long
245
dist/mock/gitreleasemanager/setup/bundle.js
vendored
245
dist/mock/gitreleasemanager/setup/bundle.js
vendored
File diff suppressed because one or more lines are too long
465
dist/mock/gitversion/execute/bundle.js
vendored
465
dist/mock/gitversion/execute/bundle.js
vendored
File diff suppressed because one or more lines are too long
367
dist/mock/gitversion/setup/bundle.js
vendored
367
dist/mock/gitversion/setup/bundle.js
vendored
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@ import { injectable } from "inversify";
|
|||||||
import * as taskLib from "azure-pipelines-task-lib/task";
|
import * as taskLib from "azure-pipelines-task-lib/task";
|
||||||
import * as toolLib from "azure-pipelines-tool-lib/tool";
|
import * as toolLib from "azure-pipelines-tool-lib/tool";
|
||||||
|
|
||||||
import { IBuildAgent, IExecResult } from "../../core/interfaces";
|
import { IBuildAgent, IExecResult } from "../../core/common";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
class BuildAgent implements IBuildAgent {
|
class BuildAgent implements IBuildAgent {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import * as toolCache from "@actions/tool-cache";
|
|||||||
|
|
||||||
import { injectable } from "inversify";
|
import { injectable } from "inversify";
|
||||||
|
|
||||||
import { IBuildAgent, IExecResult } from "../../core/interfaces";
|
import { IBuildAgent, IExecResult } from "../../core/common";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
class BuildAgent implements IBuildAgent {
|
class BuildAgent implements IBuildAgent {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { injectable } from "inversify";
|
import { injectable } from "inversify";
|
||||||
|
|
||||||
import { IBuildAgent, IExecResult } from "../../core/interfaces";
|
import { IBuildAgent, IExecResult } from "../../core/common";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
class BuildAgent implements IBuildAgent {
|
class BuildAgent implements IBuildAgent {
|
||||||
|
|||||||
@@ -9,16 +9,65 @@ import cmp from "semver-compare";
|
|||||||
|
|
||||||
import { inject, injectable } from "inversify";
|
import { inject, injectable } from "inversify";
|
||||||
|
|
||||||
import { IBuildAgent,
|
import { BuildAgent } from "../agent/mock/build-agent";
|
||||||
IDotnetTool,
|
import { Container } from "inversify";
|
||||||
IExecResult,
|
|
||||||
IGitReleaseManagerTool,
|
|
||||||
IGitVersionOptions,
|
|
||||||
IGitVersionTool,
|
|
||||||
IVersionManager,
|
|
||||||
} from "./interfaces";
|
|
||||||
|
|
||||||
import { TYPES } from "./types";
|
const container = new Container();
|
||||||
|
|
||||||
|
export interface IVersionManager {
|
||||||
|
isExplicitVersion(versionSpec: string): boolean;
|
||||||
|
evaluateVersions(versions: string[], versionSpec: string): string;
|
||||||
|
cleanVersion(version: string): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
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>;
|
||||||
|
debug(message: string): void;
|
||||||
|
setFailed(message: string, done?: boolean): void;
|
||||||
|
setSucceeded(message: string, done?: boolean): void;
|
||||||
|
exportVariable(name: string, val: string): void;
|
||||||
|
getVariable(name: string): string;
|
||||||
|
addPath(inputPath: string): void;
|
||||||
|
which(tool: string, check?: boolean): Promise<string>;
|
||||||
|
exec(exec: string, args: string[]): Promise<IExecResult>;
|
||||||
|
|
||||||
|
getSourceDir(): string;
|
||||||
|
isValidInputFile(input: string, file: string): boolean;
|
||||||
|
fileExists(file: string): boolean;
|
||||||
|
directoryExists(file: string): boolean;
|
||||||
|
|
||||||
|
setOutput(name: string, value: string): void;
|
||||||
|
getInput(input: string, required?: boolean): string;
|
||||||
|
getBooleanInput(input: string, required?: boolean): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IDotnetTool {
|
||||||
|
run(args: string[]): Promise<IExecResult>;
|
||||||
|
toolInstall(toolName: string, versionSpec: string, checkLatest: boolean, includePre: boolean): Promise<string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IExecResult {
|
||||||
|
stdout: string;
|
||||||
|
stderr: string;
|
||||||
|
code: number;
|
||||||
|
error: Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TYPES = {
|
||||||
|
IBuildAgent: Symbol.for("BuildAgent"),
|
||||||
|
IDotnetTool: Symbol.for("DotnetTool"),
|
||||||
|
IGitVersionTool: Symbol.for("GitVersionTool"),
|
||||||
|
IGitReleaseManagerTool: Symbol.for("GitReleaseManagerTool"),
|
||||||
|
IVersionManager: Symbol.for("VersionManager"),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SetupOptions = {
|
||||||
|
includePrerelease: "includePrerelease",
|
||||||
|
versionSpec: "versionSpec",
|
||||||
|
};
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
class DotnetTool implements IDotnetTool {
|
class DotnetTool implements IDotnetTool {
|
||||||
@@ -119,7 +168,7 @@ class DotnetTool implements IDotnetTool {
|
|||||||
const body: string = await res.readBody();
|
const body: string = await res.readBody();
|
||||||
const data = JSON.parse(body).data;
|
const data = JSON.parse(body).data;
|
||||||
|
|
||||||
const versions = (data[0].versions as Array<{ version: string }>).map((x) => x.version);
|
const versions = (data[0].versions as { version: string }[]).map((x) => x.version);
|
||||||
if (!versions || !versions.length) {
|
if (!versions || !versions.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -153,102 +202,6 @@ class DotnetTool implements IDotnetTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
|
||||||
class GitVersionTool implements IGitVersionTool {
|
|
||||||
|
|
||||||
private buildAgent: IBuildAgent;
|
|
||||||
private dotnetTool: IDotnetTool;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
|
||||||
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool,
|
|
||||||
) {
|
|
||||||
this.buildAgent = buildAgent;
|
|
||||||
this.dotnetTool = dotnetTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async install(versionSpec: string, includePrerelease: boolean): Promise<void> {
|
|
||||||
await this.dotnetTool.toolInstall("GitVersion.Tool", versionSpec, false, includePrerelease);
|
|
||||||
}
|
|
||||||
|
|
||||||
public run(options: IGitVersionOptions): Promise<IExecResult> {
|
|
||||||
const workDir = this.getRepoDir(options.targetPath);
|
|
||||||
|
|
||||||
const args = this.getArguments(workDir, options);
|
|
||||||
|
|
||||||
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): string[] {
|
|
||||||
const args = [
|
|
||||||
workDir,
|
|
||||||
"/output",
|
|
||||||
"json", // need to use buildserver later
|
|
||||||
];
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
class GitReleaseManagerTool implements IGitReleaseManagerTool {
|
|
||||||
|
|
||||||
private buildAgent: IBuildAgent;
|
|
||||||
private dotnetTool: IDotnetTool;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
|
||||||
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool,
|
|
||||||
) {
|
|
||||||
this.buildAgent = buildAgent;
|
|
||||||
this.dotnetTool = dotnetTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async install(versionSpec: string, includePrerelease: boolean): Promise<void> {
|
|
||||||
await this.dotnetTool.toolInstall("GitReleaseManager.Tool", versionSpec, false, includePrerelease);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
class VersionManager implements IVersionManager {
|
class VersionManager implements IVersionManager {
|
||||||
|
|
||||||
@@ -297,9 +250,8 @@ class VersionManager implements IVersionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
container.bind<IVersionManager>(TYPES.IVersionManager).to(VersionManager);
|
||||||
DotnetTool,
|
container.bind<IBuildAgent>(TYPES.IBuildAgent).to(BuildAgent);
|
||||||
GitReleaseManagerTool,
|
container.bind<IDotnetTool>(TYPES.IDotnetTool).to(DotnetTool);
|
||||||
GitVersionTool,
|
|
||||||
VersionManager,
|
export { container };
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import { IBuildAgent, IGitReleaseManagerTool } from "./interfaces";
|
import { IDotnetTool, IBuildAgent, TYPES } from "./common";
|
||||||
import { ioc } from "./ioc";
|
import { injectable, inject } from "inversify";
|
||||||
import { SetupOptions, TYPES } from "./types";
|
|
||||||
|
|
||||||
const gitReleaseManagerTool = ioc.get<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool);
|
export interface IGitReleaseManagerTool {
|
||||||
const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
install(versionSpec: string, includePrerelease: boolean): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
export async function setup() {
|
@injectable()
|
||||||
try {
|
export class GitReleaseManagerTool implements IGitReleaseManagerTool {
|
||||||
|
|
||||||
buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
private dotnetTool: IDotnetTool;
|
||||||
|
|
||||||
const versionSpec = buildAgent.getInput(SetupOptions.versionSpec);
|
constructor(
|
||||||
const includePrerelease = buildAgent.getBooleanInput(SetupOptions.includePrerelease);
|
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
||||||
|
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool,
|
||||||
|
) {
|
||||||
|
this.dotnetTool = dotnetTool;
|
||||||
|
}
|
||||||
|
|
||||||
await gitReleaseManagerTool.install(versionSpec, includePrerelease);
|
public async install(versionSpec: string, includePrerelease: boolean): Promise<void> {
|
||||||
|
await this.dotnetTool.toolInstall("GitReleaseManager.Tool", versionSpec, false, includePrerelease);
|
||||||
buildAgent.setSucceeded("GitVersionManager installed successfully", true);
|
|
||||||
} catch (error) {
|
|
||||||
buildAgent.setFailed(error.message, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,102 +1,201 @@
|
|||||||
import { IBuildAgent, IGitVersion, IGitVersionOptions, IGitVersionTool } from "./interfaces";
|
import { IBuildAgent, IDotnetTool, IExecResult, TYPES } from "./common";
|
||||||
import { ioc } from "./ioc";
|
import { injectable, inject } from "inversify";
|
||||||
import { RunOptions, SetupOptions, TYPES } from "./types";
|
import path = require("path");
|
||||||
|
|
||||||
const gitVersionTool = ioc.get<IGitVersionTool>(TYPES.IGitVersionTool);
|
export interface IGitVersionOptions {
|
||||||
const buildAgent = ioc.get<IBuildAgent>(TYPES.IBuildAgent);
|
targetPath: string;
|
||||||
|
useConfigFile: boolean;
|
||||||
export async function setup() {
|
configFilePath: string;
|
||||||
try {
|
updateAssemblyInfo: boolean;
|
||||||
|
updateAssemblyInfoFilename: string;
|
||||||
buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
additionalArguments: string;
|
||||||
|
srcDir: string;
|
||||||
const versionSpec = buildAgent.getInput(SetupOptions.versionSpec);
|
|
||||||
const includePrerelease = buildAgent.getBooleanInput(SetupOptions.includePrerelease);
|
|
||||||
|
|
||||||
await gitVersionTool.install(versionSpec, includePrerelease);
|
|
||||||
|
|
||||||
buildAgent.setSucceeded("GitVersion installed successfully", true);
|
|
||||||
} catch (error) {
|
|
||||||
buildAgent.setFailed(error.message, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run() {
|
export const RunOptions = {
|
||||||
try {
|
targetPath: "targetPath",
|
||||||
const inputOptions: IGitVersionOptions = getGitVersionOptions();
|
|
||||||
|
|
||||||
const result = await gitVersionTool.run(inputOptions);
|
useConfigFile: "useConfigFile",
|
||||||
|
configFilePath: "configFilePath",
|
||||||
|
|
||||||
const gitversion = JSON.parse(result.stdout) as IGitVersion;
|
updateAssemblyInfo: "configFilePath",
|
||||||
writeGitVersionToAgent(gitversion);
|
updateAssemblyInfoFilename: "configFilePath",
|
||||||
|
|
||||||
if (result.code === 0) {
|
additionalArguments: "additionalArguments",
|
||||||
buildAgent.setSucceeded("GitVersion executed successfully", true);
|
};
|
||||||
|
|
||||||
|
export interface IGitVersion {
|
||||||
|
Major: number;
|
||||||
|
Minor: number;
|
||||||
|
Patch: number;
|
||||||
|
PreReleaseTag: string;
|
||||||
|
PreReleaseTagWithDash: string;
|
||||||
|
PreReleaseLabel: string;
|
||||||
|
PreReleaseNumber: number;
|
||||||
|
WeightedPreReleaseNumber: number;
|
||||||
|
BuildMetaData: number;
|
||||||
|
BuildMetaDataPadded: string;
|
||||||
|
FullBuildMetaData: string;
|
||||||
|
MajorMinorPatch: string;
|
||||||
|
SemVer: string;
|
||||||
|
LegacySemVer: string;
|
||||||
|
LegacySemVerPadded: string;
|
||||||
|
AssemblySemVer: string;
|
||||||
|
AssemblySemFileVer: string;
|
||||||
|
FullSemVer: string;
|
||||||
|
InformationalVersion: string;
|
||||||
|
BranchName: string;
|
||||||
|
Sha: string;
|
||||||
|
ShortSha: string;
|
||||||
|
NuGetVersionV2: string;
|
||||||
|
NuGetVersion: string;
|
||||||
|
NuGetPreReleaseTagV2: string;
|
||||||
|
NuGetPreReleaseTag: string;
|
||||||
|
VersionSourceSha: string;
|
||||||
|
CommitsSinceVersionSource: number;
|
||||||
|
CommitsSinceVersionSourcePadded: string;
|
||||||
|
CommitDate: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IGitVersionTool {
|
||||||
|
install(versionSpec: string, includePrerelease: boolean): Promise<void>;
|
||||||
|
run(options: IGitVersionOptions): Promise<IExecResult>;
|
||||||
|
writeGitVersionToAgent(gitversion: IGitVersion): void;
|
||||||
|
getGitVersionOptions(): IGitVersionOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class GitVersionTool implements IGitVersionTool {
|
||||||
|
|
||||||
|
private buildAgent: IBuildAgent;
|
||||||
|
private dotnetTool: IDotnetTool;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@inject(TYPES.IBuildAgent) buildAgent: IBuildAgent,
|
||||||
|
@inject(TYPES.IDotnetTool) dotnetTool: IDotnetTool,
|
||||||
|
) {
|
||||||
|
this.buildAgent = buildAgent;
|
||||||
|
this.dotnetTool = dotnetTool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async install(versionSpec: string, includePrerelease: boolean): Promise<void> {
|
||||||
|
await this.dotnetTool.toolInstall("GitVersion.Tool", versionSpec, false, includePrerelease);
|
||||||
|
}
|
||||||
|
|
||||||
|
public run(options: IGitVersionOptions): Promise<IExecResult> {
|
||||||
|
const workDir = this.getRepoDir(options.targetPath);
|
||||||
|
|
||||||
|
const args = this.getArguments(workDir, options);
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
buildAgent.setFailed(result.error.message, true);
|
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): string[] {
|
||||||
|
const args = [
|
||||||
|
workDir,
|
||||||
|
"/output",
|
||||||
|
"json", // need to use buildserver later
|
||||||
|
];
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
args.push(additionalArguments);
|
||||||
buildAgent.setFailed(error, true);
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getGitVersionOptions(): IGitVersionOptions {
|
||||||
|
|
||||||
|
const targetPath = this.buildAgent.getInput(RunOptions.targetPath);
|
||||||
|
|
||||||
|
const useConfigFile = this.buildAgent.getBooleanInput(RunOptions.useConfigFile);
|
||||||
|
const configFilePath = this.buildAgent.getInput(RunOptions.configFilePath);
|
||||||
|
|
||||||
|
const updateAssemblyInfo = this.buildAgent.getBooleanInput(RunOptions.updateAssemblyInfo);
|
||||||
|
const updateAssemblyInfoFilename = this.buildAgent.getInput(RunOptions.updateAssemblyInfoFilename);
|
||||||
|
|
||||||
|
const additionalArguments = this.buildAgent.getInput(RunOptions.additionalArguments);
|
||||||
|
|
||||||
|
const srcDir = this.buildAgent.getSourceDir().replace(/\\/g, "/");
|
||||||
|
|
||||||
|
return {
|
||||||
|
targetPath,
|
||||||
|
useConfigFile,
|
||||||
|
configFilePath,
|
||||||
|
updateAssemblyInfo,
|
||||||
|
updateAssemblyInfoFilename,
|
||||||
|
additionalArguments,
|
||||||
|
srcDir,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public writeGitVersionToAgent(gitversion: IGitVersion): void {
|
||||||
|
|
||||||
|
this.buildAgent.setOutput("major", gitversion.Major.toString());
|
||||||
|
this.buildAgent.setOutput("minor", gitversion.Minor.toString());
|
||||||
|
this.buildAgent.setOutput("patch", gitversion.Patch.toString());
|
||||||
|
this.buildAgent.setOutput("preReleaseTag", gitversion.PreReleaseTag);
|
||||||
|
this.buildAgent.setOutput("preReleaseTagWithDash", gitversion.PreReleaseTagWithDash);
|
||||||
|
this.buildAgent.setOutput("preReleaseLabel", gitversion.PreReleaseLabel);
|
||||||
|
this.buildAgent.setOutput("preReleaseNumber", gitversion.PreReleaseNumber.toString());
|
||||||
|
this.buildAgent.setOutput("weightedPreReleaseNumber", gitversion.WeightedPreReleaseNumber.toString());
|
||||||
|
this.buildAgent.setOutput("buildMetaData", gitversion.BuildMetaData.toString());
|
||||||
|
this.buildAgent.setOutput("buildMetaDataPadded", gitversion.BuildMetaDataPadded);
|
||||||
|
this.buildAgent.setOutput("fullBuildMetaData", gitversion.FullBuildMetaData);
|
||||||
|
this.buildAgent.setOutput("majorMinorPatch", gitversion.MajorMinorPatch);
|
||||||
|
this.buildAgent.setOutput("semVer", gitversion.SemVer);
|
||||||
|
this.buildAgent.setOutput("legacySemVer", gitversion.LegacySemVer);
|
||||||
|
this.buildAgent.setOutput("legacySemVerPadded", gitversion.LegacySemVerPadded);
|
||||||
|
this.buildAgent.setOutput("assemblySemVer", gitversion.AssemblySemVer);
|
||||||
|
this.buildAgent.setOutput("assemblySemFileVer", gitversion.AssemblySemFileVer);
|
||||||
|
this.buildAgent.setOutput("fullSemVer", gitversion.FullSemVer);
|
||||||
|
this.buildAgent.setOutput("informationalVersion", gitversion.InformationalVersion);
|
||||||
|
this.buildAgent.setOutput("branchName", gitversion.BranchName);
|
||||||
|
this.buildAgent.setOutput("sha", gitversion.Sha);
|
||||||
|
this.buildAgent.setOutput("shortSha", gitversion.ShortSha);
|
||||||
|
this.buildAgent.setOutput("nuGetVersionV2", gitversion.NuGetVersionV2);
|
||||||
|
this.buildAgent.setOutput("nuGetVersion", gitversion.NuGetVersion);
|
||||||
|
this.buildAgent.setOutput("nuGetPreReleaseTagV2", gitversion.NuGetPreReleaseTagV2);
|
||||||
|
this.buildAgent.setOutput("nuGetPreReleaseTag", gitversion.NuGetPreReleaseTag);
|
||||||
|
this.buildAgent.setOutput("versionSourceSha", gitversion.VersionSourceSha);
|
||||||
|
this.buildAgent.setOutput("commitsSinceVersionSource", gitversion.CommitsSinceVersionSource.toString());
|
||||||
|
this.buildAgent.setOutput("commitsSinceVersionSourcePadded", gitversion.CommitsSinceVersionSourcePadded);
|
||||||
|
this.buildAgent.setOutput("commitDate", gitversion.CommitDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGitVersionOptions(): IGitVersionOptions {
|
|
||||||
|
|
||||||
const targetPath = buildAgent.getInput(RunOptions.targetPath);
|
|
||||||
|
|
||||||
const useConfigFile = buildAgent.getBooleanInput(RunOptions.useConfigFile);
|
|
||||||
const configFilePath = buildAgent.getInput(RunOptions.configFilePath);
|
|
||||||
|
|
||||||
const updateAssemblyInfo = buildAgent.getBooleanInput(RunOptions.updateAssemblyInfo);
|
|
||||||
const updateAssemblyInfoFilename = buildAgent.getInput(RunOptions.updateAssemblyInfoFilename);
|
|
||||||
|
|
||||||
const additionalArguments = buildAgent.getInput(RunOptions.additionalArguments);
|
|
||||||
|
|
||||||
const srcDir = buildAgent.getSourceDir().replace(/\\/g, "/");
|
|
||||||
|
|
||||||
return {
|
|
||||||
targetPath,
|
|
||||||
useConfigFile,
|
|
||||||
configFilePath,
|
|
||||||
updateAssemblyInfo,
|
|
||||||
updateAssemblyInfoFilename,
|
|
||||||
additionalArguments,
|
|
||||||
srcDir,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeGitVersionToAgent(gitversion: IGitVersion): void {
|
|
||||||
|
|
||||||
buildAgent.setOutput("major", gitversion.Major.toString());
|
|
||||||
buildAgent.setOutput("minor", gitversion.Minor.toString());
|
|
||||||
buildAgent.setOutput("patch", gitversion.Patch.toString());
|
|
||||||
buildAgent.setOutput("preReleaseTag", gitversion.PreReleaseTag);
|
|
||||||
buildAgent.setOutput("preReleaseTagWithDash", gitversion.PreReleaseTagWithDash);
|
|
||||||
buildAgent.setOutput("preReleaseLabel", gitversion.PreReleaseLabel);
|
|
||||||
buildAgent.setOutput("preReleaseNumber", gitversion.PreReleaseNumber.toString());
|
|
||||||
buildAgent.setOutput("weightedPreReleaseNumber", gitversion.WeightedPreReleaseNumber.toString());
|
|
||||||
buildAgent.setOutput("buildMetaData", gitversion.BuildMetaData.toString());
|
|
||||||
buildAgent.setOutput("buildMetaDataPadded", gitversion.BuildMetaDataPadded);
|
|
||||||
buildAgent.setOutput("fullBuildMetaData", gitversion.FullBuildMetaData);
|
|
||||||
buildAgent.setOutput("majorMinorPatch", gitversion.MajorMinorPatch);
|
|
||||||
buildAgent.setOutput("semVer", gitversion.SemVer);
|
|
||||||
buildAgent.setOutput("legacySemVer", gitversion.LegacySemVer);
|
|
||||||
buildAgent.setOutput("legacySemVerPadded", gitversion.LegacySemVerPadded);
|
|
||||||
buildAgent.setOutput("assemblySemVer", gitversion.AssemblySemVer);
|
|
||||||
buildAgent.setOutput("assemblySemFileVer", gitversion.AssemblySemFileVer);
|
|
||||||
buildAgent.setOutput("fullSemVer", gitversion.FullSemVer);
|
|
||||||
buildAgent.setOutput("informationalVersion", gitversion.InformationalVersion);
|
|
||||||
buildAgent.setOutput("branchName", gitversion.BranchName);
|
|
||||||
buildAgent.setOutput("sha", gitversion.Sha);
|
|
||||||
buildAgent.setOutput("shortSha", gitversion.ShortSha);
|
|
||||||
buildAgent.setOutput("nuGetVersionV2", gitversion.NuGetVersionV2);
|
|
||||||
buildAgent.setOutput("nuGetVersion", gitversion.NuGetVersion);
|
|
||||||
buildAgent.setOutput("nuGetPreReleaseTagV2", gitversion.NuGetPreReleaseTagV2);
|
|
||||||
buildAgent.setOutput("nuGetPreReleaseTag", gitversion.NuGetPreReleaseTag);
|
|
||||||
buildAgent.setOutput("versionSourceSha", gitversion.VersionSourceSha);
|
|
||||||
buildAgent.setOutput("commitsSinceVersionSource", gitversion.CommitsSinceVersionSource.toString());
|
|
||||||
buildAgent.setOutput("commitsSinceVersionSourcePadded", gitversion.CommitsSinceVersionSourcePadded);
|
|
||||||
buildAgent.setOutput("commitDate", gitversion.CommitDate);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
export interface IVersionManager {
|
|
||||||
isExplicitVersion(versionSpec: string): boolean;
|
|
||||||
evaluateVersions(versions: string[], versionSpec: string): string;
|
|
||||||
cleanVersion(version: string): string;
|
|
||||||
}
|
|
||||||
|
|
||||||
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>;
|
|
||||||
debug(message: string): void;
|
|
||||||
setFailed(message: string, done?: boolean): void;
|
|
||||||
setSucceeded(message: string, done?: boolean): void;
|
|
||||||
exportVariable(name: string, val: string): void;
|
|
||||||
getVariable(name: string): string;
|
|
||||||
addPath(inputPath: string): void;
|
|
||||||
which(tool: string, check?: boolean): Promise<string>;
|
|
||||||
exec(exec: string, args: string[]): Promise<IExecResult>;
|
|
||||||
|
|
||||||
getSourceDir(): string;
|
|
||||||
isValidInputFile(input: string, file: string): boolean;
|
|
||||||
fileExists(file: string): boolean;
|
|
||||||
directoryExists(file: string): boolean;
|
|
||||||
|
|
||||||
setOutput(name: string, value: string): void;
|
|
||||||
getInput(input: string, required?: boolean): string;
|
|
||||||
getBooleanInput(input: string, required?: boolean): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IDotnetTool {
|
|
||||||
run(args: string[]): Promise<IExecResult>;
|
|
||||||
toolInstall(toolName: string, versionSpec: string, checkLatest: boolean, includePre: boolean): Promise<string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Argument {
|
|
||||||
constructor(public readonly name: string, public readonly value: string) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export interface IGitVersionTool {
|
|
||||||
install(versionSpec: string, includePrerelease: boolean): Promise<void>;
|
|
||||||
run(options: IGitVersionOptions): Promise<IExecResult>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGitReleaseManagerTool {
|
|
||||||
install(versionSpec: string, includePrerelease: boolean): Promise<void>;
|
|
||||||
}
|
|
||||||
export interface IExecResult {
|
|
||||||
stdout: string;
|
|
||||||
stderr: string;
|
|
||||||
code: number;
|
|
||||||
error: Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGitVersionOptions {
|
|
||||||
targetPath: string;
|
|
||||||
useConfigFile: boolean;
|
|
||||||
configFilePath: string;
|
|
||||||
updateAssemblyInfo: boolean;
|
|
||||||
updateAssemblyInfoFilename: string;
|
|
||||||
additionalArguments: string;
|
|
||||||
srcDir: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IGitVersion {
|
|
||||||
Major: number;
|
|
||||||
Minor: number;
|
|
||||||
Patch: number;
|
|
||||||
PreReleaseTag: string;
|
|
||||||
PreReleaseTagWithDash: string;
|
|
||||||
PreReleaseLabel: string;
|
|
||||||
PreReleaseNumber: number;
|
|
||||||
WeightedPreReleaseNumber: number;
|
|
||||||
BuildMetaData: number;
|
|
||||||
BuildMetaDataPadded: string;
|
|
||||||
FullBuildMetaData: string;
|
|
||||||
MajorMinorPatch: string;
|
|
||||||
SemVer: string;
|
|
||||||
LegacySemVer: string;
|
|
||||||
LegacySemVerPadded: string;
|
|
||||||
AssemblySemVer: string;
|
|
||||||
AssemblySemFileVer: string;
|
|
||||||
FullSemVer: string;
|
|
||||||
InformationalVersion: string;
|
|
||||||
BranchName: string;
|
|
||||||
Sha: string;
|
|
||||||
ShortSha: string;
|
|
||||||
NuGetVersionV2: string;
|
|
||||||
NuGetVersion: string;
|
|
||||||
NuGetPreReleaseTagV2: string;
|
|
||||||
NuGetPreReleaseTag: string;
|
|
||||||
VersionSourceSha: string;
|
|
||||||
CommitsSinceVersionSource: number;
|
|
||||||
CommitsSinceVersionSourcePadded: string;
|
|
||||||
CommitDate: string;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { Container } from "inversify";
|
|
||||||
|
|
||||||
import { BuildAgent } from "../agent/mock/build-agent";
|
|
||||||
import { DotnetTool, GitReleaseManagerTool, GitVersionTool, VersionManager } from "./common";
|
|
||||||
import { IBuildAgent, IDotnetTool, IGitReleaseManagerTool, 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);
|
|
||||||
ioc.bind<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool).to(GitReleaseManagerTool);
|
|
||||||
|
|
||||||
export { ioc };
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
const TYPES = {
|
|
||||||
IBuildAgent: Symbol.for("BuildAgent"),
|
|
||||||
IDotnetTool: Symbol.for("DotnetTool"),
|
|
||||||
IGitVersionTool: Symbol.for("GitVersionTool"),
|
|
||||||
IGitReleaseManagerTool: Symbol.for("GitReleaseManagerTool"),
|
|
||||||
IVersionManager: Symbol.for("VersionManager"),
|
|
||||||
};
|
|
||||||
|
|
||||||
const SetupOptions = {
|
|
||||||
includePrerelease: "includePrerelease",
|
|
||||||
versionSpec: "versionSpec",
|
|
||||||
};
|
|
||||||
|
|
||||||
const RunOptions = {
|
|
||||||
targetPath: "targetPath",
|
|
||||||
|
|
||||||
useConfigFile: "useConfigFile",
|
|
||||||
configFilePath: "configFilePath",
|
|
||||||
|
|
||||||
updateAssemblyInfo: "configFilePath",
|
|
||||||
updateAssemblyInfoFilename: "configFilePath",
|
|
||||||
|
|
||||||
additionalArguments: "additionalArguments",
|
|
||||||
};
|
|
||||||
|
|
||||||
export { SetupOptions, RunOptions, TYPES };
|
|
||||||
23
src/tasks/gitreleasemanager/main.ts
Normal file
23
src/tasks/gitreleasemanager/main.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { container, IBuildAgent, TYPES, SetupOptions } from "../../core/common";
|
||||||
|
import { IGitReleaseManagerTool, GitReleaseManagerTool } from "../../core/gitreleasemanager";
|
||||||
|
|
||||||
|
container.bind<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool).to(GitReleaseManagerTool);
|
||||||
|
|
||||||
|
const gitReleaseManagerTool = container.get<IGitReleaseManagerTool>(TYPES.IGitReleaseManagerTool);
|
||||||
|
const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent);
|
||||||
|
|
||||||
|
export async function setup() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
||||||
|
|
||||||
|
const versionSpec = buildAgent.getInput(SetupOptions.versionSpec);
|
||||||
|
const includePrerelease = buildAgent.getBooleanInput(SetupOptions.includePrerelease);
|
||||||
|
|
||||||
|
await gitReleaseManagerTool.install(versionSpec, includePrerelease);
|
||||||
|
|
||||||
|
buildAgent.setSucceeded("GitVersionManager installed successfully", true);
|
||||||
|
} catch (error) {
|
||||||
|
buildAgent.setFailed(error.message, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { setup } from "../../core/gitreleasemanager";
|
import { setup } from "./main";
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { run } from "../../core/gitversion";
|
import { run } from "./main";
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|||||||
43
src/tasks/gitversion/main.ts
Normal file
43
src/tasks/gitversion/main.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { container, IBuildAgent, TYPES, SetupOptions } from "../../core/common";
|
||||||
|
import { IGitVersionTool, IGitVersionOptions, IGitVersion, GitVersionTool } from "../../core/gitversion";
|
||||||
|
|
||||||
|
container.bind<IGitVersionTool>(TYPES.IGitVersionTool).to(GitVersionTool);
|
||||||
|
|
||||||
|
const gitVersionTool = container.get<IGitVersionTool>(TYPES.IGitVersionTool);
|
||||||
|
const buildAgent = container.get<IBuildAgent>(TYPES.IBuildAgent);
|
||||||
|
|
||||||
|
export async function setup() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
buildAgent.exportVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
||||||
|
|
||||||
|
const versionSpec = buildAgent.getInput(SetupOptions.versionSpec);
|
||||||
|
const includePrerelease = buildAgent.getBooleanInput(SetupOptions.includePrerelease);
|
||||||
|
|
||||||
|
await gitVersionTool.install(versionSpec, includePrerelease);
|
||||||
|
|
||||||
|
buildAgent.setSucceeded("GitVersion installed successfully", true);
|
||||||
|
} catch (error) {
|
||||||
|
buildAgent.setFailed(error.message, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function run() {
|
||||||
|
try {
|
||||||
|
const inputOptions: IGitVersionOptions = gitVersionTool.getGitVersionOptions();
|
||||||
|
|
||||||
|
const result = await gitVersionTool.run(inputOptions);
|
||||||
|
|
||||||
|
const gitversion = JSON.parse(result.stdout) as IGitVersion;
|
||||||
|
gitVersionTool.writeGitVersionToAgent(gitversion);
|
||||||
|
|
||||||
|
if (result.code === 0) {
|
||||||
|
buildAgent.setSucceeded("GitVersion executed successfully", true);
|
||||||
|
} else {
|
||||||
|
buildAgent.setFailed(result.error.message, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
buildAgent.setFailed(error, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { setup } from "../../core/gitversion";
|
import { setup } from "./main";
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|||||||
Reference in New Issue
Block a user