2019-09-09 21:20:59 +09:00
|
|
|
import * as glob from "glob";
|
|
|
|
import { lstatSync } 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;
|
|
|
|
input_body?: string;
|
|
|
|
input_body_path?: string;
|
|
|
|
input_files?: string[];
|
|
|
|
input_draft?: boolean;
|
2019-09-09 17:10:07 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
type Env = { [key: string]: string | undefined };
|
|
|
|
|
|
|
|
export const parseConfig = (env: Env): Config => {
|
|
|
|
return {
|
|
|
|
github_token: env.GITHUB_TOKEN || "",
|
2019-09-09 21:20:59 +09:00
|
|
|
github_ref: env.GITHUB_REF || "",
|
2019-09-09 17:10:07 +09:00
|
|
|
github_repository: env.GITHUB_REPOSITORY || "",
|
|
|
|
input_name: env.INPUT_NAME,
|
|
|
|
input_body: env.INPUT_BODY,
|
|
|
|
input_body_path: env.INPUT_BODY_PATH,
|
|
|
|
input_files: (env.INPUT_FILES || "").split(","),
|
2019-09-09 21:20:59 +09:00
|
|
|
input_draft: env.INPUT_DRAFT === "true"
|
|
|
|
};
|
|
|
|
};
|
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(
|
|
|
|
glob.sync(pattern).filter(path => lstatSync(path).isFile())
|
|
|
|
);
|
|
|
|
}, []);
|
|
|
|
};
|
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/");
|
|
|
|
};
|