From dededbbd4c967df645e0a6900769a61a0f2bbf65 Mon Sep 17 00:00:00 2001 From: Ben Pearce Date: Tue, 2 May 2023 17:36:43 +1000 Subject: [PATCH 1/4] added release notes file option for create-release v6 --- .../inputCommandBuilder.test.ts | 16 ++++++++++++++++ .../inputCommandBuilder.ts | 9 +++++++++ .../CreateOctopusReleaseV6/task.json | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts index dc109aa6..080218cb 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,19 @@ 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("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..ea6a8db5 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,13 @@ export function createCommandFromInputs(logger: Logger, task: TaskWrapper): Crea GitCommit: task.getInput("GitCommit"), }; + if (!command.ReleaseNotes) { + const releaseNotesFile = task.getInput("ReleaseNotesFile"); + 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..1c08c111 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json @@ -94,6 +94,14 @@ "required": false, "helpMarkDown": "Octopus Release notes. This field supports markdown. To include newlines, you can use HTML linebreaks." }, + { + "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. Will only be used if the Release Notes field is empty." + }, { "name": "GitRef", "type": "string", From 80b20d9cddbeab744fde06a52332c76c6e472359 Mon Sep 17 00:00:00 2001 From: Ben Pearce Date: Tue, 2 May 2023 17:43:30 +1000 Subject: [PATCH 2/4] added extra test --- .../inputCommandBuilder.test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts index 080218cb..6b172a42 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts @@ -57,7 +57,21 @@ describe("getInputCommand", () => { fs.writeFileSync(notesPath, "this is a release note"); const command = createCommandFromInputs(logger, task); expect(command.ReleaseNotes).toBe("this is a release note"); - }) + }); + + test("release notes takes precedence", 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"); + const command = createCommandFromInputs(logger, task); + expect(command.ReleaseNotes).toBe("inline release notes"); + }); test("duplicate variable name, variables field takes precedence", () => { task.addVariableString("Space", "Default"); From fa7085cb7291995cc94f8f05db68f76e9a348ef0 Mon Sep 17 00:00:00 2001 From: Ben Pearce Date: Thu, 4 May 2023 14:25:00 +1000 Subject: [PATCH 3/4] specifying both fields is an error --- .../CreateOctopusReleaseV6/inputCommandBuilder.ts | 12 ++++++++++-- .../CreateOctopusReleaseV6/task.json | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts index ea6a8db5..21444dbe 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.ts @@ -66,8 +66,16 @@ export function createCommandFromInputs(logger: Logger, task: TaskWrapper): Crea GitCommit: task.getInput("GitCommit"), }; - if (!command.ReleaseNotes) { - const releaseNotesFile = task.getInput("ReleaseNotesFile"); + 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(); } diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json index 1c08c111..ace50e8d 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/task.json @@ -92,7 +92,7 @@ "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", @@ -100,7 +100,7 @@ "label": "Release Notes File", "defaultValue": "", "required": false, - "helpMarkDown": "Octopus Release notes file. Path to a file that contains the release notes. Supports markdown. Will only be used if the Release Notes field is empty." + "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", From 9e08e8c12a7e0948cd8b6ff706766967d2dacac0 Mon Sep 17 00:00:00 2001 From: Ben Pearce Date: Thu, 4 May 2023 14:51:42 +1000 Subject: [PATCH 4/4] fix test --- .../CreateOctopusReleaseV6/inputCommandBuilder.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts index 6b172a42..3996f643 100644 --- a/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts +++ b/source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/inputCommandBuilder.test.ts @@ -59,7 +59,7 @@ describe("getInputCommand", () => { expect(command.ReleaseNotes).toBe("this is a release note"); }); - test("release notes takes precedence", async () => { + 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"); @@ -69,8 +69,7 @@ describe("getInputCommand", () => { task.addVariableString("ReleaseNotesFile", notesPath); fs.writeFileSync(notesPath, "this is a release note"); - const command = createCommandFromInputs(logger, task); - expect(command.ReleaseNotes).toBe("inline release notes"); + expect(() => createCommandFromInputs(logger, task)).toThrowError("cannot specify ReleaseNotes and ReleaseNotesFile"); }); test("duplicate variable name, variables field takes precedence", () => {