forked from mirrors/action-gh-release
Add 'fail_on_unmatched_files' input (#55)
This commit is contained in:
parent
9439581056
commit
4fb86a77e0
6 changed files with 54 additions and 17 deletions
11
src/main.ts
11
src/main.ts
|
@ -1,4 +1,4 @@
|
|||
import { paths, parseConfig, isTag } from "./util";
|
||||
import { paths, parseConfig, isTag, unmatchedPatterns } from "./util";
|
||||
import { release, upload, GitHubReleaser } from "./github";
|
||||
import { setFailed, setOutput } from "@actions/core";
|
||||
import { GitHub } from "@actions/github";
|
||||
|
@ -10,6 +10,15 @@ async function run() {
|
|||
if (!config.input_tag_name && !isTag(config.github_ref)) {
|
||||
throw new Error(`⚠️ GitHub Releases requires a tag`);
|
||||
}
|
||||
if (config.input_files) {
|
||||
const patterns = unmatchedPatterns(config.input_files);
|
||||
patterns.forEach(pattern =>
|
||||
console.warn(`🤔 Pattern '${pattern}' does not match any files.`)
|
||||
);
|
||||
if (patterns.length > 0 && config.input_fail_on_unmatched_files) {
|
||||
throw new Error(`⚠️ There were unmatched files`);
|
||||
}
|
||||
}
|
||||
GitHub.plugin([
|
||||
require("@octokit/plugin-throttling"),
|
||||
require("@octokit/plugin-retry")
|
||||
|
|
14
src/util.ts
14
src/util.ts
|
@ -13,6 +13,7 @@ export interface Config {
|
|||
input_files?: string[];
|
||||
input_draft?: boolean;
|
||||
input_prerelease?: boolean;
|
||||
input_fail_on_unmatched_files?: boolean;
|
||||
}
|
||||
|
||||
export const releaseBody = (config: Config): string | undefined => {
|
||||
|
@ -47,7 +48,8 @@ export const parseConfig = (env: Env): Config => {
|
|||
input_body_path: env.INPUT_BODY_PATH,
|
||||
input_files: parseInputFiles(env.INPUT_FILES || ""),
|
||||
input_draft: env.INPUT_DRAFT === "true",
|
||||
input_prerelease: env.INPUT_PRERELEASE == "true"
|
||||
input_prerelease: env.INPUT_PRERELEASE == "true",
|
||||
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true"
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -59,6 +61,16 @@ export const paths = (patterns: string[]): string[] => {
|
|||
}, []);
|
||||
};
|
||||
|
||||
export const unmatchedPatterns = (patterns: string[]): string[] => {
|
||||
return patterns.reduce((acc: string[], pattern: string): string[] => {
|
||||
return acc.concat(
|
||||
glob.sync(pattern).filter(path => lstatSync(path).isFile()).length == 0
|
||||
? [pattern]
|
||||
: []
|
||||
);
|
||||
}, []);
|
||||
};
|
||||
|
||||
export const isTag = (ref: string): boolean => {
|
||||
return ref.startsWith("refs/tags/");
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue