diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts index dc109aa6..3996f643 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts @@ -1,6 +1,9 @@ import { Logger } from "@octopusdeploy/api-client"; import { createCommandFromInputs } from "./inputCommandBuilder"; import { MockTaskWrapper } from "../../Utils/MockTaskWrapper"; +import * as path from "path"; +import fs from "fs"; +import os from "os"; describe("getInputCommand", () => { let logger: Logger; @@ -43,6 +46,32 @@ describe("getInputCommand", () => { expect(command.Packages).toStrictEqual(["Baz:2.5.0", "Step1:Foo:1.0.0", "Bar:2.0.0"]); }); + test("release notes file", async () => { + const tempOutDir = await fs.mkdtempSync(path.join(os.tmpdir(), "octopus_")); + const notesPath = path.join(tempOutDir, "notes.txt"); + + task.addVariableString("Space", "Default"); + task.addVariableString("Project", "Awesome project"); + task.addVariableString("ReleaseNotesFile", notesPath); + + fs.writeFileSync(notesPath, "this is a release note"); + const command = createCommandFromInputs(logger, task); + expect(command.ReleaseNotes).toBe("this is a release note"); + }); + + test("specifying both release notes and release notes file causes error", async () => { + const tempOutDir = await fs.mkdtempSync(path.join(os.tmpdir(), "octopus_")); + const notesPath = path.join(tempOutDir, "notes.txt"); + + task.addVariableString("Space", "Default"); + task.addVariableString("Project", "Awesome project"); + task.addVariableString("ReleaseNotes", "inline release notes"); + task.addVariableString("ReleaseNotesFile", notesPath); + + fs.writeFileSync(notesPath, "this is a release note"); + expect(() => createCommandFromInputs(logger, task)).toThrowError("cannot specify ReleaseNotes and ReleaseNotesFile"); + }); + test("duplicate variable name, variables field takes precedence", () => { task.addVariableString("Space", "Default"); task.addVariableString("Project", "Awesome project"); diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts index 8c228207..21444dbe 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts @@ -3,6 +3,8 @@ import shlex from "shlex"; import { getLineSeparatedItems } from "../../Utils/inputs"; import { CreateReleaseCommandV1, Logger } from "@octopusdeploy/api-client"; import { TaskWrapper } from "tasks/Utils/taskInput"; +import { isNullOrWhitespace } from "../../../tasksLegacy/Utils/inputs"; +import fs from "fs"; export function createCommandFromInputs(logger: Logger, task: TaskWrapper): CreateReleaseCommandV1 { const packages: string[] = []; @@ -64,6 +66,21 @@ export function createCommandFromInputs(logger: Logger, task: TaskWrapper): Crea GitCommit: task.getInput("GitCommit"), }; + const releaseNotesFilePath = task.getInput("ReleaseNotesFile"); + + if (command.ReleaseNotes && releaseNotesFilePath) { + const message = "cannot specify ReleaseNotes and ReleaseNotesFile"; + task.setFailure(message); + throw new Error(message); + } + + if (releaseNotesFilePath) { + const releaseNotesFile = releaseNotesFilePath; + if (!isNullOrWhitespace(releaseNotesFile) && fs.existsSync(releaseNotesFile) && fs.lstatSync(releaseNotesFile).isFile()) { + command.ReleaseNotes = fs.readFileSync(releaseNotesFile).toString(); + } + } + logger.debug?.(JSON.stringify(command)); return command; diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json index 44e86821..ace50e8d 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json @@ -92,7 +92,15 @@ "label": "Release Notes", "defaultValue": "", "required": false, - "helpMarkDown": "Octopus Release notes. This field supports markdown. To include newlines, you can use HTML linebreaks." + "helpMarkDown": "Octopus Release notes. This field supports markdown. To include newlines, you can use HTML linebreaks. Can only specify this if 'ReleaseNotesFile' is not supplied." + }, + { + "name": "ReleaseNotesFile", + "type": "string", + "label": "Release Notes File", + "defaultValue": "", + "required": false, + "helpMarkDown": "Octopus Release notes file. Path to a file that contains the release notes. Supports markdown. Can only specify this if 'ReleaseNotes' is not supplied." }, { "name": "GitRef",