2019-09-09 21:20:59 +09:00
|
|
|
import * as glob from "glob";
|
2021-11-24 18:00:17 +01:00
|
|
|
import { statSync, readFileSync } from "fs";
|
2019-09-09 17:10:07 +09:00
|
|
|
|
|
|
|
export interface Config {
|
2019-09-09 21:20:59 +09:00
|
|
|
github_token: string;
|
|
|
|
github_ref: string;
|
|
|
|
github_repository: string;
|
|
|
|
// user provided
|
|
|
|
input_name?: string;
|
2020-01-09 15:06:19 +09:00
|
|
|
input_tag_name?: string;
|
2020-12-20 14:44:30 -05:00
|
|
|
input_repository?: string;
|
2019-09-09 21:20:59 +09:00
|
|
|
input_body?: string;
|
|
|
|
input_body_path?: string;
|
|
|
|
input_files?: string[];
|
|
|
|
input_draft?: boolean;
|
2019-09-17 23:30:36 +09:00
|
|
|
input_prerelease?: boolean;
|
2020-06-24 23:11:41 -07:00
|
|
|
input_fail_on_unmatched_files?: boolean;
|
2021-05-03 02:43:58 +02:00
|
|
|
input_target_commitish?: string;
|
2021-08-08 02:07:02 -04:00
|
|
|
input_discussion_category_name?: string;
|
2021-11-07 17:06:35 -05:00
|
|
|
input_generate_release_notes?: boolean;
|
2022-01-23 00:40:31 +08:00
|
|
|
input_append_body?: boolean;
|
2019-09-09 17:10:07 +09:00
|
|
|
}
|
|
|
|
|
2021-08-08 00:28:01 -04:00
|
|
|
export const uploadUrl = (url: string): string => {
|
|
|
|
const templateMarkerPos = url.indexOf("{");
|
|
|
|
if (templateMarkerPos > -1) {
|
|
|
|
return url.substring(0, templateMarkerPos);
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2019-09-29 02:15:58 -04:00
|
|
|
export const releaseBody = (config: Config): string | undefined => {
|
|
|
|
return (
|
|
|
|
(config.input_body_path &&
|
2021-03-21 13:52:16 +08:00
|
|
|
readFileSync(config.input_body_path).toString("utf8")) ||
|
|
|
|
config.input_body
|
2019-09-29 02:15:58 -04:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-09-09 17:10:07 +09:00
|
|
|
type Env = { [key: string]: string | undefined };
|
|
|
|
|
2019-09-17 23:14:30 +09:00
|
|
|
export const parseInputFiles = (files: string): string[] => {
|
|
|
|
return files.split(/\r?\n/).reduce<string[]>(
|
|
|
|
(acc, line) =>
|
|
|
|
acc
|
|
|
|
.concat(line.split(","))
|
2022-11-21 06:50:24 +00:00
|
|
|
.filter((pat) => pat)
|
|
|
|
.map((pat) => pat.trim()),
|
2019-09-17 23:14:30 +09:00
|
|
|
[]
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-09-09 17:10:07 +09:00
|
|
|
export const parseConfig = (env: Env): Config => {
|
|
|
|
return {
|
2021-07-30 18:41:53 -04:00
|
|
|
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || "",
|
2019-09-09 21:20:59 +09:00
|
|
|
github_ref: env.GITHUB_REF || "",
|
2020-12-20 14:44:30 -05:00
|
|
|
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
|
2019-09-09 17:10:07 +09:00
|
|
|
input_name: env.INPUT_NAME,
|
2021-07-30 16:09:00 +03:00
|
|
|
input_tag_name: env.INPUT_TAG_NAME?.trim(),
|
2019-09-09 17:10:07 +09:00
|
|
|
input_body: env.INPUT_BODY,
|
|
|
|
input_body_path: env.INPUT_BODY_PATH,
|
2019-09-17 23:14:30 +09:00
|
|
|
input_files: parseInputFiles(env.INPUT_FILES || ""),
|
2021-07-18 01:27:42 +02:00
|
|
|
input_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === "true" : undefined,
|
|
|
|
input_prerelease: env.INPUT_PRERELEASE
|
|
|
|
? env.INPUT_PRERELEASE == "true"
|
|
|
|
: undefined,
|
2021-05-03 02:43:58 +02:00
|
|
|
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true",
|
2021-08-09 23:57:43 -04:00
|
|
|
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
|
|
|
|
input_discussion_category_name:
|
2021-11-07 17:06:35 -05:00
|
|
|
env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
|
2022-01-23 00:40:31 +08:00
|
|
|
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES == "true",
|
2022-11-21 06:50:24 +00:00
|
|
|
input_append_body: env.INPUT_APPEND_BODY == "true",
|
2019-09-09 21:20:59 +09:00
|
|
|
};
|
|
|
|
};
|
2019-09-09 17:10:07 +09:00
|
|
|
|
|
|
|
export const paths = (patterns: string[]): string[] => {
|
|
|
|
return patterns.reduce((acc: string[], pattern: string): string[] => {
|
2019-09-09 21:20:59 +09:00
|
|
|
return acc.concat(
|
2022-11-21 06:50:24 +00:00
|
|
|
glob.sync(pattern).filter((path) => statSync(path).isFile())
|
2019-09-09 21:20:59 +09:00
|
|
|
);
|
|
|
|
}, []);
|
|
|
|
};
|
2019-09-09 17:10:07 +09:00
|
|
|
|
2020-06-24 23:11:41 -07:00
|
|
|
export const unmatchedPatterns = (patterns: string[]): string[] => {
|
|
|
|
return patterns.reduce((acc: string[], pattern: string): string[] => {
|
|
|
|
return acc.concat(
|
2022-11-21 06:50:24 +00:00
|
|
|
glob.sync(pattern).filter((path) => statSync(path).isFile()).length == 0
|
2020-06-24 23:11:41 -07:00
|
|
|
? [pattern]
|
|
|
|
: []
|
|
|
|
);
|
|
|
|
}, []);
|
|
|
|
};
|
|
|
|
|
2019-09-09 17:10:07 +09:00
|
|
|
export const isTag = (ref: string): boolean => {
|
2019-09-09 21:20:59 +09:00
|
|
|
return ref.startsWith("refs/tags/");
|
|
|
|
};
|