Skip to content

Commit

Permalink
dist update
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Dec 10, 2024
1 parent 364375b commit 693a36f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 125 deletions.
125 changes: 26 additions & 99 deletions dist/tools/libs/gitreleasemanager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -229,121 +229,48 @@ class Runner {
}
}
async setup() {
try {
this.disableTelemetry();
this.buildAgent.debug("Installing GitReleaseManager");
const toolPath = await this.gitReleaseManagerTool.install();
const pathVariable = this.gitReleaseManagerTool.toolPathVariable;
this.buildAgent.info(`Set ${pathVariable} to ${toolPath}`);
this.buildAgent.setVariable(pathVariable, toolPath);
this.buildAgent.setSucceeded("GitReleaseManager installed successfully", true);
return {
code: 0
};
} catch (error) {
if (error instanceof Error) {
this.buildAgent.setFailed(error.message, true);
}
return {
code: -1,
error
};
}
return this.safeExecute(async () => {
await this.gitReleaseManagerTool.install();
return { code: 0 };
}, "GitReleaseManager setup successfully");
}
async create() {
try {
this.disableTelemetry();
this.buildAgent.debug("Creating release");
const result = await this.gitReleaseManagerTool.create();
this.buildAgent.setSucceeded("GitReleaseManager created release successfully", true);
return result;
} catch (error) {
if (error instanceof Error) {
this.buildAgent.setFailed(error.message, true);
}
return {
code: -1,
error
};
}
return this.safeExecute(async () => this.gitReleaseManagerTool.create(), "GitReleaseManager created release successfully");
}
async discard() {
try {
this.disableTelemetry();
this.buildAgent.debug("Discarding release");
const result = await this.gitReleaseManagerTool.discard();
this.buildAgent.setSucceeded("GitReleaseManager discarded release successfully", true);
return result;
} catch (error) {
if (error instanceof Error) {
this.buildAgent.setFailed(error.message, true);
}
return {
code: -1,
error
};
}
return this.safeExecute(async () => this.gitReleaseManagerTool.discard(), "GitReleaseManager discarded release successfully");
}
async close() {
try {
this.disableTelemetry();
this.buildAgent.debug("Closing release");
const result = await this.gitReleaseManagerTool.close();
this.buildAgent.setSucceeded("GitReleaseManager closed release successfully", true);
return result;
} catch (error) {
if (error instanceof Error) {
this.buildAgent.setFailed(error.message, true);
}
return {
code: -1,
error
};
}
return this.safeExecute(async () => this.gitReleaseManagerTool.close(), "GitReleaseManager closed release successfully");
}
async open() {
try {
this.disableTelemetry();
this.buildAgent.debug("Opening release");
const result = await this.gitReleaseManagerTool.open();
this.buildAgent.setSucceeded("GitReleaseManager opened release successfully", true);
return result;
} catch (error) {
if (error instanceof Error) {
this.buildAgent.setFailed(error.message, true);
}
return {
code: -1,
error
};
}
return this.safeExecute(async () => this.gitReleaseManagerTool.open(), "GitReleaseManager opened release successfully");
}
async publish() {
try {
this.disableTelemetry();
this.buildAgent.debug("Publishing release");
const result = await this.gitReleaseManagerTool.publish();
this.buildAgent.setSucceeded("GitReleaseManager published release successfully", true);
return result;
} catch (error) {
if (error instanceof Error) {
this.buildAgent.setFailed(error.message, true);
}
return {
code: -1,
error
};
}
return this.safeExecute(async () => this.gitReleaseManagerTool.publish(), "GitReleaseManager published release successfully");
}
async addAsset() {
return this.safeExecute(async () => this.gitReleaseManagerTool.addAsset(), "GitReleaseManager added assets to release successfully");
}
async safeExecute(action, successMessage) {
try {
this.disableTelemetry();
this.buildAgent.debug("Adding asset to release");
const result = await this.gitReleaseManagerTool.addAsset();
this.buildAgent.setSucceeded("GitReleaseManager added assets to release successfully", true);
return result;
const result = await action();
if (result.code === 0) {
this.buildAgent.info("Output:");
this.buildAgent.info("-------------------");
this.buildAgent.info(result.stdout);
this.buildAgent.info("-------------------");
this.buildAgent.setSucceeded(successMessage, true);
return result;
} else {
this.buildAgent.error(result.stderr);
this.buildAgent.setFailed(result.stderr, true);
return result;
}
} catch (error) {
if (error instanceof Error) {
this.buildAgent.error(error.message);
this.buildAgent.setFailed(error.message, true);
}
return {
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/libs/gitreleasemanager.mjs.map

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions dist/tools/libs/gitversion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,7 @@ class Runner {
async setup() {
try {
this.disableTelemetry();
this.buildAgent.debug("Installing GitVersion");
const toolPath = await this.gitVersionTool.install();
const pathVariable = this.gitVersionTool.toolPathVariable;
this.buildAgent.info(`Set ${pathVariable} to ${toolPath}`);
this.buildAgent.setVariable(pathVariable, toolPath);
this.buildAgent.setSucceeded("GitVersion installed successfully", true);
await this.gitVersionTool.install();
return {
code: 0
};
Expand All @@ -262,20 +257,7 @@ class Runner {
this.buildAgent.info(stdout);
this.buildAgent.info("-------------------");
this.buildAgent.debug("Parsing GitVersion output");
if (stdout.lastIndexOf("{") === -1 || stdout.lastIndexOf("}") === -1) {
this.buildAgent.debug("GitVersion output is not valid JSON");
this.buildAgent.setFailed("GitVersion output is not valid JSON", true);
return {
code: -1,
error: new Error("GitVersion output is not valid JSON")
};
} else {
const jsonOutput = stdout.substring(stdout.lastIndexOf("{"), stdout.lastIndexOf("}") + 1);
const gitVersionOutput = JSON.parse(jsonOutput);
this.gitVersionTool.writeGitVersionToAgent(gitVersionOutput);
this.buildAgent.setSucceeded("GitVersion executed successfully", true);
return result;
}
return this.processGitVersionOutput(result);
} else {
this.buildAgent.debug("GitVersion failed");
const error = result.error;
Expand Down Expand Up @@ -326,6 +308,23 @@ class Runner {
};
}
}
processGitVersionOutput(result) {
const stdout = result.stdout;
if (stdout.lastIndexOf("{") === -1 || stdout.lastIndexOf("}") === -1) {
this.buildAgent.debug("GitVersion output is not valid JSON");
this.buildAgent.setFailed("GitVersion output is not valid JSON", true);
return {
code: -1,
error: new Error("GitVersion output is not valid JSON")
};
} else {
const jsonOutput = stdout.substring(stdout.lastIndexOf("{"), stdout.lastIndexOf("}") + 1);
const gitVersionOutput = JSON.parse(jsonOutput);
this.gitVersionTool.writeGitVersionToAgent(gitVersionOutput);
this.buildAgent.setSucceeded("GitVersion executed successfully", true);
return result;
}
}
disableTelemetry() {
this.buildAgent.info(`Running on: '${this.buildAgent.agentName}'`);
this.buildAgent.debug("Disabling telemetry");
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/libs/gitversion.mjs.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/tools/libs/tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class DotnetTool {
}
this.buildAgent.info(`Prepending ${toolPath} to PATH`);
this.buildAgent.addPath(toolPath);
const pathVariable = this.toolPathVariable;
this.buildAgent.info(`Set ${pathVariable} to ${toolPath}`);
this.buildAgent.setVariable(pathVariable, toolPath);
this.buildAgent.setSucceeded(`${this.packageName} installed successfully`, true);
return toolPath;
}
async execute(cmd, args) {
Expand All @@ -70,9 +74,9 @@ class DotnetTool {
}
async executeTool(args) {
let toolPath;
const gitVersionPath = this.buildAgent.getVariableAsPath(this.toolPathVariable);
if (gitVersionPath) {
toolPath = path.join(gitVersionPath, os.platform() === "win32" ? `${this.toolName}.exe` : this.toolName);
const variableAsPath = this.buildAgent.getVariableAsPath(this.toolPathVariable);
if (variableAsPath) {
toolPath = path.join(variableAsPath, os.platform() === "win32" ? `${this.toolName}.exe` : this.toolName);
}
if (!toolPath) {
toolPath = await this.buildAgent.which(this.toolName, true);
Expand Down
Loading

0 comments on commit 693a36f

Please sign in to comment.