2019-09-29 06:15:58 +00:00
|
|
|
import {
|
|
|
|
releaseBody,
|
|
|
|
isTag,
|
|
|
|
paths,
|
|
|
|
parseConfig,
|
2020-06-25 06:11:41 +00:00
|
|
|
parseInputFiles,
|
2021-08-08 04:28:01 +00:00
|
|
|
unmatchedPatterns,
|
|
|
|
uploadUrl
|
2019-09-29 06:15:58 +00:00
|
|
|
} from "../src/util";
|
2019-09-09 12:20:59 +00:00
|
|
|
import * as assert from "assert";
|
2019-09-09 08:10:07 +00:00
|
|
|
|
2019-09-09 12:20:59 +00:00
|
|
|
describe("util", () => {
|
2021-08-08 04:28:01 +00:00
|
|
|
describe("uploadUrl", () => {
|
|
|
|
it("stripts template", () => {
|
|
|
|
assert.equal(
|
|
|
|
uploadUrl(
|
|
|
|
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}"
|
|
|
|
),
|
|
|
|
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-09-17 14:14:30 +00:00
|
|
|
describe("parseInputFiles", () => {
|
|
|
|
it("parses empty strings", () => {
|
|
|
|
assert.deepStrictEqual(parseInputFiles(""), []);
|
|
|
|
});
|
|
|
|
it("parses comma-delimited strings", () => {
|
|
|
|
assert.deepStrictEqual(parseInputFiles("foo,bar"), ["foo", "bar"]);
|
|
|
|
});
|
|
|
|
it("parses newline and comma-delimited (and then some)", () => {
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
parseInputFiles("foo,bar\nbaz,boom,\n\ndoom,loom "),
|
|
|
|
["foo", "bar", "baz", "boom", "doom", "loom"]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-09-29 06:15:58 +00:00
|
|
|
describe("releaseBody", () => {
|
|
|
|
it("uses input body", () => {
|
|
|
|
assert.equal(
|
|
|
|
"foo",
|
|
|
|
releaseBody({
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "",
|
|
|
|
input_body: "foo",
|
|
|
|
input_body_path: undefined,
|
|
|
|
input_draft: false,
|
|
|
|
input_prerelease: false,
|
|
|
|
input_files: [],
|
2020-01-09 06:06:19 +00:00
|
|
|
input_name: undefined,
|
2021-05-03 00:43:58 +00:00
|
|
|
input_tag_name: undefined,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: undefined
|
2019-09-29 06:15:58 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it("uses input body path", () => {
|
|
|
|
assert.equal(
|
|
|
|
"bar",
|
|
|
|
releaseBody({
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "",
|
|
|
|
input_body: undefined,
|
|
|
|
input_body_path: "__tests__/release.txt",
|
|
|
|
input_draft: false,
|
|
|
|
input_prerelease: false,
|
|
|
|
input_files: [],
|
2020-01-09 06:06:19 +00:00
|
|
|
input_name: undefined,
|
2021-05-03 00:43:58 +00:00
|
|
|
input_tag_name: undefined,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: undefined
|
2019-09-29 06:15:58 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-03-21 05:52:16 +00:00
|
|
|
it("defaults to body path when both body and body path are provided", () => {
|
2019-09-29 06:15:58 +00:00
|
|
|
assert.equal(
|
2021-03-21 05:52:16 +00:00
|
|
|
"bar",
|
2019-09-29 06:15:58 +00:00
|
|
|
releaseBody({
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "",
|
|
|
|
input_body: "foo",
|
|
|
|
input_body_path: "__tests__/release.txt",
|
|
|
|
input_draft: false,
|
|
|
|
input_prerelease: false,
|
|
|
|
input_files: [],
|
2020-01-09 06:06:19 +00:00
|
|
|
input_name: undefined,
|
2021-05-03 00:43:58 +00:00
|
|
|
input_tag_name: undefined,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: undefined
|
2019-09-29 06:15:58 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2019-09-17 14:14:30 +00:00
|
|
|
describe("parseConfig", () => {
|
|
|
|
it("parses basic config", () => {
|
|
|
|
assert.deepStrictEqual(parseConfig({}), {
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "",
|
|
|
|
input_body: undefined,
|
|
|
|
input_body_path: undefined,
|
2021-07-17 23:27:42 +00:00
|
|
|
input_draft: undefined,
|
|
|
|
input_prerelease: undefined,
|
2019-09-17 14:14:30 +00:00
|
|
|
input_files: [],
|
2020-01-09 06:06:19 +00:00
|
|
|
input_name: undefined,
|
2020-06-25 06:11:41 +00:00
|
|
|
input_tag_name: undefined,
|
2021-05-03 00:43:58 +00:00
|
|
|
input_fail_on_unmatched_files: false,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: undefined
|
2019-09-17 14:14:30 +00:00
|
|
|
});
|
|
|
|
});
|
2021-07-30 22:41:53 +00:00
|
|
|
|
2021-05-03 00:43:58 +00:00
|
|
|
it("parses basic config with commitish", () => {
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
parseConfig({
|
|
|
|
INPUT_TARGET_COMMITISH: "affa18ef97bc9db20076945705aba8c516139abd"
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "",
|
|
|
|
input_body: undefined,
|
|
|
|
input_body_path: undefined,
|
2021-07-17 23:27:42 +00:00
|
|
|
input_draft: undefined,
|
|
|
|
input_prerelease: undefined,
|
2021-05-03 00:43:58 +00:00
|
|
|
input_files: [],
|
|
|
|
input_name: undefined,
|
|
|
|
input_tag_name: undefined,
|
|
|
|
input_fail_on_unmatched_files: false,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: "affa18ef97bc9db20076945705aba8c516139abd",
|
|
|
|
input_discussion_category_name: undefined
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it("supports discussion category names", () => {
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
parseConfig({
|
|
|
|
INPUT_DISCUSSION_CATEGORY_NAME: "releases"
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "",
|
|
|
|
input_body: undefined,
|
|
|
|
input_body_path: undefined,
|
|
|
|
input_draft: undefined,
|
|
|
|
input_prerelease: undefined,
|
|
|
|
input_files: [],
|
|
|
|
input_name: undefined,
|
|
|
|
input_tag_name: undefined,
|
|
|
|
input_fail_on_unmatched_files: false,
|
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: "releases"
|
2021-05-03 00:43:58 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2021-07-30 22:41:53 +00:00
|
|
|
it("prefers GITHUB_TOKEN over token input for backwards compatibility", () => {
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
parseConfig({
|
|
|
|
INPUT_DRAFT: "false",
|
|
|
|
INPUT_PRERELEASE: "true",
|
|
|
|
GITHUB_TOKEN: "env-token",
|
|
|
|
INPUT_TOKEN: "input-token"
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "env-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,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: undefined
|
2021-07-30 22:41:53 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it("uses input token as the source of GITHUB_TOKEN by default", () => {
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
parseConfig({
|
|
|
|
INPUT_DRAFT: "false",
|
|
|
|
INPUT_PRERELEASE: "true",
|
|
|
|
INPUT_TOKEN: "input-token"
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
github_ref: "",
|
|
|
|
github_repository: "",
|
|
|
|
github_token: "input-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,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: undefined
|
2021-07-30 22:41:53 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2021-07-17 23:27:42 +00:00
|
|
|
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,
|
2021-08-08 06:07:02 +00:00
|
|
|
input_target_commitish: undefined,
|
|
|
|
input_discussion_category_name: undefined
|
2021-07-17 23:27:42 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2021-05-03 00:43:58 +00:00
|
|
|
});
|
2019-09-09 12:20:59 +00:00
|
|
|
describe("isTag", () => {
|
|
|
|
it("returns true for tags", async () => {
|
|
|
|
assert.equal(isTag("refs/tags/foo"), true);
|
2019-09-09 08:10:07 +00:00
|
|
|
});
|
2019-09-09 12:20:59 +00:00
|
|
|
it("returns false for other kinds of refs", async () => {
|
|
|
|
assert.equal(isTag("refs/heads/master"), false);
|
|
|
|
});
|
|
|
|
});
|
2019-09-09 08:10:07 +00:00
|
|
|
|
2019-09-09 12:20:59 +00:00
|
|
|
describe("paths", () => {
|
|
|
|
it("resolves files given a set of paths", async () => {
|
2020-06-25 06:11:41 +00:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
paths(["tests/data/**/*", "tests/data/does/not/exist/*"]),
|
|
|
|
["tests/data/foo/bar.txt"]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("unmatchedPatterns", () => {
|
|
|
|
it("returns the patterns that don't match any files", async () => {
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
unmatchedPatterns(["tests/data/**/*", "tests/data/does/not/exist/*"]),
|
|
|
|
["tests/data/does/not/exist/*"]
|
|
|
|
);
|
2019-09-09 08:10:07 +00:00
|
|
|
});
|
2019-09-09 12:20:59 +00:00
|
|
|
});
|
|
|
|
});
|