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

Retain original release info if the keys are not set #109

Merged
merged 1 commit into from Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -185,7 +185,12 @@ The following are optional as `step.with` keys
| `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing |
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. |

💡When providing a `body` and `body_path` at the same time, `body_path` will be attempted first, then falling back on `body` if the path can not be read from.
💡 When providing a `body` and `body_path` at the same time, `body_path` will be
attempted first, then falling back on `body` if the path can not be read from.

💡 When the release info keys (such as `name`, `body`, `draft`, `prerelease`, etc.)
are not explicitly set and there is already an existing release for the tag, the
release will retain its original info.

#### outputs

Expand Down
30 changes: 26 additions & 4 deletions __tests__/util.test.ts
Expand Up @@ -87,8 +87,8 @@ describe("util", () => {
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: false,
input_draft: undefined,
input_prerelease: undefined,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
Expand All @@ -109,8 +109,8 @@ describe("util", () => {
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: false,
input_draft: undefined,
input_prerelease: undefined,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
Expand All @@ -119,6 +119,28 @@ describe("util", () => {
}
);
});
it("parses basic config with draft and prerelease", () => {
assert.deepStrictEqual(
parseConfig({
INPUT_DRAFT: "false",
INPUT_PRERELEASE: "true"
}),
{
github_ref: "",
github_repository: "",
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: false,
input_prerelease: true,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
}
);
});
});
describe("isTag", () => {
it("returns true for tags", async () => {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions src/github.ts
Expand Up @@ -16,8 +16,11 @@ export interface Release {
upload_url: string;
html_url: string;
tag_name: string;
name: string;
body: string;
target_commitish: string;
draft: boolean;
prerelease: boolean;
}

export interface Releaser {
Expand Down Expand Up @@ -179,11 +182,24 @@ export const release = async (
} else {
target_commitish = existingRelease.data.target_commitish;
}

const tag_name = tag;
const name = config.input_name || tag;
const body = `${existingRelease.data.body}\n${releaseBody(config)}`;
const draft = config.input_draft;
const prerelease = config.input_prerelease;
const name = config.input_name || existingRelease.data.name || tag;

let body: string = "";
if (existingRelease.data.body) body += existingRelease.data.body;
let workflowBody = releaseBody(config);
if (existingRelease.data.body && workflowBody) body += "\n";
if (workflowBody) body += workflowBody;

const draft =
config.input_draft !== undefined
? config.input_draft
: existingRelease.data.draft;
const prerelease =
config.input_prerelease !== undefined
? config.input_prerelease
: existingRelease.data.prerelease;

const release = await releaser.updateRelease({
owner,
Expand Down
6 changes: 4 additions & 2 deletions src/util.ts
Expand Up @@ -49,8 +49,10 @@ export const parseConfig = (env: Env): Config => {
input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH,
input_files: parseInputFiles(env.INPUT_FILES || ""),
input_draft: env.INPUT_DRAFT === "true",
input_prerelease: env.INPUT_PRERELEASE == "true",
input_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === "true" : undefined,
input_prerelease: env.INPUT_PRERELEASE
? env.INPUT_PRERELEASE == "true"
: undefined,
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true",
input_target_commitish: env.INPUT_TARGET_COMMITISH
};
Expand Down