Signed-off-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
Rui Chen 2025-06-11 01:51:29 -04:00
commit edc85f0b7e
No known key found for this signature in database
GPG key ID: 6577287BDCA70840
22 changed files with 3293 additions and 7437 deletions

View file

@ -1,14 +1,13 @@
import { setFailed, setOutput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHubReleaser, release, upload } from "./github";
import {
paths,
parseConfig,
isTag,
parseConfig,
paths,
unmatchedPatterns,
uploadUrl,
} from "./util";
import { release, upload, GitHubReleaser } from "./github";
import { getOctokit } from "@actions/github";
import { setFailed, setOutput } from "@actions/core";
import { GitHub, getOctokitOptions } from "@actions/github/lib/utils";
import { env } from "process";
@ -24,9 +23,13 @@ async function run() {
}
if (config.input_files) {
const patterns = unmatchedPatterns(config.input_files);
patterns.forEach((pattern) =>
console.warn(`🤔 Pattern '${pattern}' does not match any files.`)
);
patterns.forEach((pattern) => {
if (config.input_fail_on_unmatched_files) {
throw new Error(`⚠️ Pattern '${pattern}' does not match any files.`);
} else {
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`);
}
@ -60,33 +63,46 @@ async function run() {
});
//);
const rel = await release(config, new GitHubReleaser(gh));
if (config.input_files) {
if (config.input_files && config.input_files.length > 0) {
const files = paths(config.input_files);
if (files.length == 0) {
console.warn(`🤔 ${config.input_files} not include valid file.`);
if (config.input_fail_on_unmatched_files) {
throw new Error(
`⚠️ ${config.input_files} does not include a valid file.`
);
} else {
console.warn(
`🤔 ${config.input_files} does not include a valid file.`
);
}
}
const currentAssets = rel.assets;
const assets = await Promise.all(
files
.map(async (path) => {
const json = await upload(
config,
gh,
uploadUrl(rel.upload_url),
path,
currentAssets
);
if (json) {
delete json.uploader;
}
const uploadFile = async (path) => {
const json = await upload(
config,
gh,
uploadUrl(rel.upload_url),
path,
currentAssets
);
if (json) {
delete json.uploader;
}
return json;
};
return json;
})
.filter((json) => json !== null)
).catch((error) => {
throw error;
});
let results: (any | null)[];
if (!config.input_preserve_order) {
results = await Promise.all(files.map(uploadFile));
} else {
results = [];
for (const path of files) {
results.push(await uploadFile(path));
}
}
const assets = results.filter(Boolean);
setOutput("assets", assets);
}
console.log(`🎉 Release ready at ${rel.html_url}`);