mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-06-28 06:16:01 +00:00
chore: add prettier config
Signed-off-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
parent
605f567f95
commit
cb9d16a07e
7 changed files with 273 additions and 355 deletions
60
src/util.ts
60
src/util.ts
|
@ -1,5 +1,5 @@
|
|||
import * as glob from "glob";
|
||||
import { statSync, readFileSync } from "fs";
|
||||
import * as glob from 'glob';
|
||||
import { statSync, readFileSync } from 'fs';
|
||||
|
||||
export interface Config {
|
||||
github_token: string;
|
||||
|
@ -21,11 +21,11 @@ export interface Config {
|
|||
input_discussion_category_name?: string;
|
||||
input_generate_release_notes?: boolean;
|
||||
input_append_body?: boolean;
|
||||
input_make_latest: "true" | "false" | "legacy" | undefined;
|
||||
input_make_latest: 'true' | 'false' | 'legacy' | undefined;
|
||||
}
|
||||
|
||||
export const uploadUrl = (url: string): string => {
|
||||
const templateMarkerPos = url.indexOf("{");
|
||||
const templateMarkerPos = url.indexOf('{');
|
||||
if (templateMarkerPos > -1) {
|
||||
return url.substring(0, templateMarkerPos);
|
||||
}
|
||||
|
@ -34,8 +34,7 @@ export const uploadUrl = (url: string): string => {
|
|||
|
||||
export const releaseBody = (config: Config): string | undefined => {
|
||||
return (
|
||||
(config.input_body_path &&
|
||||
readFileSync(config.input_body_path).toString("utf8")) ||
|
||||
(config.input_body_path && readFileSync(config.input_body_path).toString('utf8')) ||
|
||||
config.input_body
|
||||
);
|
||||
};
|
||||
|
@ -46,7 +45,7 @@ export const parseInputFiles = (files: string): string[] => {
|
|||
return files.split(/\r?\n/).reduce<string[]>(
|
||||
(acc, line) =>
|
||||
acc
|
||||
.concat(line.split(","))
|
||||
.concat(line.split(','))
|
||||
.filter((pat) => pat)
|
||||
.map((pat) => pat.trim()),
|
||||
[],
|
||||
|
@ -55,38 +54,31 @@ export const parseInputFiles = (files: string): string[] => {
|
|||
|
||||
export const parseConfig = (env: Env): Config => {
|
||||
return {
|
||||
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || "",
|
||||
github_ref: env.GITHUB_REF || "",
|
||||
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || "",
|
||||
github_token: env.GITHUB_TOKEN || env.INPUT_TOKEN || '',
|
||||
github_ref: env.GITHUB_REF || '',
|
||||
github_repository: env.INPUT_REPOSITORY || env.GITHUB_REPOSITORY || '',
|
||||
input_name: env.INPUT_NAME,
|
||||
input_tag_name: env.INPUT_TAG_NAME?.trim(),
|
||||
input_body: env.INPUT_BODY,
|
||||
input_body_path: env.INPUT_BODY_PATH,
|
||||
input_files: parseInputFiles(env.INPUT_FILES || ""),
|
||||
input_files: parseInputFiles(env.INPUT_FILES || ''),
|
||||
input_overwrite_files: env.INPUT_OVERWRITE_FILES
|
||||
? env.INPUT_OVERWRITE_FILES == "true"
|
||||
? env.INPUT_OVERWRITE_FILES == 'true'
|
||||
: undefined,
|
||||
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",
|
||||
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',
|
||||
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
|
||||
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",
|
||||
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',
|
||||
input_make_latest: parseMakeLatest(env.INPUT_MAKE_LATEST),
|
||||
};
|
||||
};
|
||||
|
||||
const parseMakeLatest = (
|
||||
value: string | undefined,
|
||||
): "true" | "false" | "legacy" | undefined => {
|
||||
if (value === "true" || value === "false" || value === "legacy") {
|
||||
const parseMakeLatest = (value: string | undefined): 'true' | 'false' | 'legacy' | undefined => {
|
||||
if (value === 'true' || value === 'false' || value === 'legacy') {
|
||||
return value;
|
||||
}
|
||||
return undefined;
|
||||
|
@ -94,26 +86,22 @@ const parseMakeLatest = (
|
|||
|
||||
export const paths = (patterns: string[]): string[] => {
|
||||
return patterns.reduce((acc: string[], pattern: string): string[] => {
|
||||
return acc.concat(
|
||||
glob.sync(pattern).filter((path) => statSync(path).isFile()),
|
||||
);
|
||||
return acc.concat(glob.sync(pattern).filter((path) => statSync(path).isFile()));
|
||||
}, []);
|
||||
};
|
||||
|
||||
export const unmatchedPatterns = (patterns: string[]): string[] => {
|
||||
return patterns.reduce((acc: string[], pattern: string): string[] => {
|
||||
return acc.concat(
|
||||
glob.sync(pattern).filter((path) => statSync(path).isFile()).length == 0
|
||||
? [pattern]
|
||||
: [],
|
||||
glob.sync(pattern).filter((path) => statSync(path).isFile()).length == 0 ? [pattern] : [],
|
||||
);
|
||||
}, []);
|
||||
};
|
||||
|
||||
export const isTag = (ref: string): boolean => {
|
||||
return ref.startsWith("refs/tags/");
|
||||
return ref.startsWith('refs/tags/');
|
||||
};
|
||||
|
||||
export const alignAssetName = (assetName: string): string => {
|
||||
return assetName.replace(/ /g, ".");
|
||||
return assetName.replace(/ /g, '.');
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue