2025-06-11 11:34:43 -04:00
|
|
|
import * as glob from 'glob';
|
|
|
|
|
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[];
|
2025-06-11 02:54:42 -03:00
|
|
|
input_overwrite_files?: boolean;
|
2019-09-09 21:20:59 +09:00
|
|
|
input_draft?: boolean;
|
2024-11-11 21:14:02 +01:00
|
|
|
input_preserve_order?: 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;
|
2025-06-11 11:34:43 -04:00
|
|
|
input_make_latest: 'true' | 'false' | 'legacy' | undefined;
|
2019-09-09 17:10:07 +09:00
|
|
|
}
|
|
|
|
|
|
2021-08-08 00:28:01 -04:00
|
|
|
export const uploadUrl = (url: string): string => {
|
2025-06-11 11:34:43 -04:00
|
|
|
const templateMarkerPos = url.indexOf('{');
|
2021-08-08 00:28:01 -04:00
|
|
|
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 (
|
2025-06-11 11:34:43 -04:00
|
|
|
(config.input_body_path && readFileSync(config.input_body_path).toString('utf8')) ||
|
2021-03-21 13:52:16 +08:00
|
|
|
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
|
2025-06-11 11:34:43 -04:00
|
|
|
.concat(line.split(','))
|
2022-11-21 06:50:24 +00:00
|
|
|
.filter((pat) => pat)
|
|
|
|
|
.map((pat) => pat.trim()),
|
2024-07-18 16:05:39 -04:00
|
|
|
[],
|
2019-09-17 23:14:30 +09:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-09 17:10:07 +09:00
|
|
|
export const parseConfig = (env: Env): Config => {
|
|
|
|
|
return {
|
2025-06-11 11:34:43 -04:00
|
|
|
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || '',
|
|
|
|
|
github_ref: env.GITHUB_REF || '',
|
|
|
|
|
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,
|
2025-06-11 11:34:43 -04:00
|
|
|
input_files: parseInputFiles(env.INPUT_FILES || ''),
|
2025-06-11 02:54:42 -03:00
|
|
|
input_overwrite_files: env.INPUT_OVERWRITE_FILES
|
2025-06-11 11:34:43 -04:00
|
|
|
? env.INPUT_OVERWRITE_FILES == 'true'
|
2025-06-11 02:54:42 -03:00
|
|
|
: undefined,
|
2025-06-11 11:34:43 -04:00
|
|
|
input_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === 'true' : undefined,
|
|
|
|
|
input_preserve_order: env.INPUT_PRESERVE_ORDER ? env.INPUT_PRESERVE_ORDER == 'true' : undefined,
|
|
|
|
|
input_prerelease: env.INPUT_PRERELEASE ? env.INPUT_PRERELEASE == 'true' : undefined,
|
|
|
|
|
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,
|
2025-06-11 11:34:43 -04:00
|
|
|
input_discussion_category_name: env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
|
|
|
|
|
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES == 'true',
|
|
|
|
|
input_append_body: env.INPUT_APPEND_BODY == 'true',
|
2024-07-18 17:37:44 -04:00
|
|
|
input_make_latest: parseMakeLatest(env.INPUT_MAKE_LATEST),
|
2019-09-09 21:20:59 +09:00
|
|
|
};
|
|
|
|
|
};
|
2019-09-09 17:10:07 +09:00
|
|
|
|
2025-06-11 11:34:43 -04:00
|
|
|
const parseMakeLatest = (value: string | undefined): 'true' | 'false' | 'legacy' | undefined => {
|
|
|
|
|
if (value === 'true' || value === 'false' || value === 'legacy') {
|
2024-07-18 17:37:44 -04:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
return undefined;
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-09 17:10:07 +09:00
|
|
|
export const paths = (patterns: string[]): string[] => {
|
|
|
|
|
return patterns.reduce((acc: string[], pattern: string): string[] => {
|
2025-06-11 11:34:43 -04:00
|
|
|
return acc.concat(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(
|
2025-06-11 11:34:43 -04:00
|
|
|
glob.sync(pattern).filter((path) => statSync(path).isFile()).length == 0 ? [pattern] : [],
|
2020-06-24 23:11:41 -07:00
|
|
|
);
|
|
|
|
|
}, []);
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-09 17:10:07 +09:00
|
|
|
export const isTag = (ref: string): boolean => {
|
2025-06-11 11:34:43 -04:00
|
|
|
return ref.startsWith('refs/tags/');
|
2019-09-09 21:20:59 +09:00
|
|
|
};
|
2024-11-11 21:12:02 +01:00
|
|
|
|
|
|
|
|
export const alignAssetName = (assetName: string): string => {
|
2025-06-11 11:34:43 -04:00
|
|
|
return assetName.replace(/ /g, '.');
|
2024-11-11 21:12:02 +01:00
|
|
|
};
|