Skip to content

Commit

Permalink
Retain original release info if the keys are not set (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 authored and softprops committed Jul 25, 2021
1 parent 04c14f5 commit 59b9126
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -175,7 +175,12 @@ The following are optional as `step.with` keys
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. |
| `token` | String | Secret GitHub Personal Access Token. Defaults to `${{ github.token }}` |

💡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 @@ -187,11 +190,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 @@ -50,8 +50,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

0 comments on commit 59b9126

Please sign in to comment.