2025-06-11 11:34:43 -04:00
|
|
|
import { setFailed, setOutput } from '@actions/core';
|
|
|
|
|
import { getOctokit } from '@actions/github';
|
|
|
|
|
import { GitHubReleaser, release, upload } from './github';
|
|
|
|
|
import { isTag, parseConfig, paths, unmatchedPatterns, uploadUrl } from './util';
|
2021-08-08 00:28:01 -04:00
|
|
|
|
2025-06-11 11:34:43 -04:00
|
|
|
import { env } from 'process';
|
2019-09-09 17:10:07 +09:00
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
|
try {
|
2019-09-09 20:16:58 +09:00
|
|
|
const config = parseConfig(env);
|
2025-06-11 11:34:43 -04:00
|
|
|
if (!config.input_tag_name && !isTag(config.github_ref) && !config.input_draft) {
|
2019-09-09 17:10:07 +09:00
|
|
|
throw new Error(`⚠️ GitHub Releases requires a tag`);
|
|
|
|
|
}
|
2020-06-24 23:11:41 -07:00
|
|
|
if (config.input_files) {
|
2025-10-06 19:51:45 -07:00
|
|
|
const patterns = unmatchedPatterns(config.input_files, config.input_working_directory);
|
2024-03-08 16:13:09 -05:00
|
|
|
patterns.forEach((pattern) => {
|
2024-03-10 00:56:17 -05:00
|
|
|
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.`);
|
|
|
|
|
}
|
2024-03-08 16:13:09 -05:00
|
|
|
});
|
2020-06-24 23:11:41 -07:00
|
|
|
if (patterns.length > 0 && config.input_fail_on_unmatched_files) {
|
|
|
|
|
throw new Error(`⚠️ There were unmatched files`);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-08 00:28:01 -04:00
|
|
|
|
|
|
|
|
// const oktokit = GitHub.plugin(
|
|
|
|
|
// require("@octokit/plugin-throttling"),
|
|
|
|
|
// require("@octokit/plugin-retry")
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
const gh = getOctokit(config.github_token, {
|
|
|
|
|
//new oktokit(
|
2020-05-25 02:39:23 +02:00
|
|
|
throttle: {
|
|
|
|
|
onRateLimit: (retryAfter, options) => {
|
2025-06-11 11:34:43 -04:00
|
|
|
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`);
|
2020-05-25 02:39:23 +02:00
|
|
|
if (options.request.retryCount === 0) {
|
|
|
|
|
// only retries once
|
|
|
|
|
console.log(`Retrying after ${retryAfter} seconds!`);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onAbuseLimit: (retryAfter, options) => {
|
|
|
|
|
// does not retry, only logs a warning
|
2025-06-11 11:34:43 -04:00
|
|
|
console.warn(`Abuse detected for request ${options.method} ${options.url}`);
|
2022-11-21 06:50:24 +00:00
|
|
|
},
|
|
|
|
|
},
|
2019-10-02 20:51:12 -04:00
|
|
|
});
|
2021-08-08 00:28:01 -04:00
|
|
|
//);
|
|
|
|
|
const rel = await release(config, new GitHubReleaser(gh));
|
2024-03-08 17:47:54 -03:00
|
|
|
if (config.input_files && config.input_files.length > 0) {
|
2025-10-06 19:51:45 -07:00
|
|
|
const files = paths(config.input_files, config.input_working_directory);
|
2019-12-29 06:07:38 +08:00
|
|
|
if (files.length == 0) {
|
2024-03-12 12:22:52 -04:00
|
|
|
if (config.input_fail_on_unmatched_files) {
|
2025-06-11 11:34:43 -04:00
|
|
|
throw new Error(`⚠️ ${config.input_files} does not include a valid file.`);
|
2024-03-12 12:22:52 -04:00
|
|
|
} else {
|
2025-06-11 11:34:43 -04:00
|
|
|
console.warn(`🤔 ${config.input_files} does not include a valid file.`);
|
2024-03-12 12:22:52 -04:00
|
|
|
}
|
2019-12-29 06:07:38 +08:00
|
|
|
}
|
2021-11-26 00:02:50 +01:00
|
|
|
const currentAssets = rel.assets;
|
2024-11-11 21:14:02 +01:00
|
|
|
|
|
|
|
|
const uploadFile = async (path) => {
|
2025-06-11 11:34:43 -04:00
|
|
|
const json = await upload(config, gh, uploadUrl(rel.upload_url), path, currentAssets);
|
2025-06-11 02:54:42 -03:00
|
|
|
if (json) {
|
|
|
|
|
delete json.uploader;
|
|
|
|
|
}
|
2024-11-11 21:14:02 +01:00
|
|
|
return json;
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-11 02:54:42 -03:00
|
|
|
let results: (any | null)[];
|
2024-11-11 21:14:02 +01:00
|
|
|
if (!config.input_preserve_order) {
|
2025-06-11 02:54:42 -03:00
|
|
|
results = await Promise.all(files.map(uploadFile));
|
2024-11-11 21:14:02 +01:00
|
|
|
} else {
|
2025-06-11 02:54:42 -03:00
|
|
|
results = [];
|
2024-11-11 21:14:02 +01:00
|
|
|
for (const path of files) {
|
2025-06-11 02:54:42 -03:00
|
|
|
results.push(await uploadFile(path));
|
2024-11-11 21:14:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-11 02:54:42 -03:00
|
|
|
|
|
|
|
|
const assets = results.filter(Boolean);
|
2025-06-11 11:34:43 -04:00
|
|
|
setOutput('assets', assets);
|
2019-09-09 17:10:07 +09:00
|
|
|
}
|
2019-09-09 21:20:59 +09:00
|
|
|
console.log(`🎉 Release ready at ${rel.html_url}`);
|
2025-06-11 11:34:43 -04:00
|
|
|
setOutput('url', rel.html_url);
|
|
|
|
|
setOutput('id', rel.id.toString());
|
|
|
|
|
setOutput('upload_url', rel.upload_url);
|
2019-09-09 17:10:07 +09:00
|
|
|
} catch (error) {
|
2019-09-09 18:14:17 +09:00
|
|
|
setFailed(error.message);
|
2019-09-09 17:10:07 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 21:20:59 +09:00
|
|
|
run();
|