Skip to content

Commit

Permalink
GitTools#1389 - fix setting the build version in azure devops
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Dec 10, 2024
1 parent 1a151a8 commit 4862fb5
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions dist/tools/azure/agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class BuildAgent extends BuildAgentBase {
setFailed = (message, done) => this._setResult(TaskResult.Failed, message, done);
setOutput = (name, value) => this._setVariable(name, value, true);
setVariable = (name, value) => this._setVariable(name, value);
updateBuildNumber = (version) => this._updateBuildNumber(version);
_updateBuildNumber(version) {
this.debug(`build number: ${version}`);
issueCommand("build.updatebuildnumber", {}, version);
}
_setResult(result, message, done) {
this.debug(`task result: ${TaskResult[result]}`);
if (result === TaskResult.Failed && message) {
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/azure/agent.mjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/tools/github/agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class BuildAgent extends BuildAgentBase {
}
issueCommand("set-env", { name }, convertedVal);
};
updateBuildNumber = (version) => this.debug(`updateBuildNumber - ${version}`);
}

export { BuildAgent };
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/github/agent.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tools/libs/agents.mjs.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/tools/libs/gitversion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class GitVersionTool extends DotnetTool {
this.buildAgent.error(`Unable to set output/variable for ${property}`);
}
}
if (output.FullSemVer.endsWith("+0")) {
output.FullSemVer = output.FullSemVer.slice(0, -2);
}
this.buildAgent.updateBuildNumber(output.FullSemVer);
}
async getRepoDir(settings) {
return await super.getRepoPath(settings.targetPath);
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/libs/gitversion.mjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/tools/local/agent.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BuildAgent extends BuildAgentBase {
this.debug(`setVariable - ${name} - ${value}`);
process.env[name] = value;
}
updateBuildNumber = (version) => this.debug(`updateBuildNumber - ${version}`);
}

export { BuildAgent };
Expand Down
2 changes: 1 addition & 1 deletion dist/tools/local/agent.mjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/__tests__/tools/gitversion/tool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ describe('GitVersionTool', () => {
},
setVariable(name: string, value: string) {
variables.set(name, value)
},
updateBuildNumber(_version: string): void {
return
}
} as IBuildAgent
tool = new TestGitVersionTool(buildAgent)
Expand Down
7 changes: 7 additions & 0 deletions src/agents/azure/build-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export class BuildAgent extends BuildAgentBase implements IBuildAgent {

setVariable = (name: string, value: string): void => this._setVariable(name, value)

updateBuildNumber = (version: string): void => this._updateBuildNumber(version)

private _updateBuildNumber(version: string): void {
this.debug(`build number: ${version}`)
issueCommand('build.updatebuildnumber', {}, version)
}

private _setResult(result: TaskResult, message: string, done?: boolean): void {
this.debug(`task result: ${TaskResult[result]}`)
// add an error issue
Expand Down
4 changes: 4 additions & 0 deletions src/agents/common/build-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export interface IBuildAgent {

setVariable(name: string, value: string): void

updateBuildNumber: (version: string) => void

which(tool: string, check?: boolean): Promise<string>
}

Expand All @@ -86,6 +88,8 @@ export abstract class BuildAgentBase implements IBuildAgent {

abstract setVariable(name: string, value: string): void

abstract updateBuildNumber: (version: string) => void

get sourceDir(): string {
return this.getVariableAsPath(this.sourceDirVariable)?.replace(/\\/g, '/')
}
Expand Down
2 changes: 2 additions & 0 deletions src/agents/github/build-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ export class BuildAgent extends BuildAgentBase implements IBuildAgent {

issueCommand('set-env', { name }, convertedVal)
}

updateBuildNumber = (version: string): void => this.debug(`updateBuildNumber - ${version}`)
}
2 changes: 2 additions & 0 deletions src/agents/local/build-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export class BuildAgent extends BuildAgentBase implements IBuildAgent {
this.debug(`setVariable - ${name} - ${value}`)
process.env[name] = value
}

updateBuildNumber = (version: string): void => this.debug(`updateBuildNumber - ${version}`)
}
5 changes: 5 additions & 0 deletions src/tools/gitversion/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export class GitVersionTool extends DotnetTool {
this.buildAgent.error(`Unable to set output/variable for ${property}`)
}
}

if (output.FullSemVer.endsWith('+0')) {
output.FullSemVer = output.FullSemVer.slice(0, -2)
}
this.buildAgent.updateBuildNumber(output.FullSemVer)
}

protected async getRepoDir(settings: ExecuteSettings | CommandSettings): Promise<string> {
Expand Down

0 comments on commit 4862fb5

Please sign in to comment.