Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added release notes file option for create-release v6 #309

Merged
merged 4 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,6 +46,33 @@ 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("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");
task.addVariableString("Project", "Awesome project");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down