feat: add input option overwrite_files. (#343)
Some checks are pending
main / build (push) Waiting to run

* Add input option overwrite_files.

* Fix description.

* update test and run fmt/build

Signed-off-by: Rui Chen <rui@chenrui.dev>

---------

Signed-off-by: Rui Chen <rui@chenrui.dev>
Co-authored-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
Adriano dos Santos Fernandes 2025-06-11 02:54:42 -03:00 committed by GitHub
parent 5822334cb4
commit 605f567f95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 18 deletions

View file

@ -168,12 +168,19 @@ export const upload = async (
({ name: currentName }) => currentName == alignAssetName(name),
);
if (currentAsset) {
console.log(`♻️ Deleting previously uploaded asset ${name}...`);
await github.rest.repos.deleteReleaseAsset({
asset_id: currentAsset.id || 1,
owner,
repo,
});
if (config.input_overwrite_files === false) {
console.log(
`Asset ${name} already exists and overwrite_files is false...`,
);
return null;
} else {
console.log(`♻️ Deleting previously uploaded asset ${name}...`);
await github.rest.repos.deleteReleaseAsset({
asset_id: currentAsset.id || 1,
owner,
repo,
});
}
}
console.log(`⬆️ Uploading ${name}...`);
const endpoint = new URL(url);

View file

@ -1,13 +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 { env } from "process";
@ -86,19 +86,23 @@ async function run() {
path,
currentAssets,
);
delete json.uploader;
if (json) {
delete json.uploader;
}
return json;
};
let assets;
let results: (any | null)[];
if (!config.input_preserve_order) {
assets = await Promise.all(files.map(uploadFile));
results = await Promise.all(files.map(uploadFile));
} else {
assets = [];
results = [];
for (const path of files) {
assets.push(await uploadFile(path));
results.push(await uploadFile(path));
}
}
const assets = results.filter(Boolean);
setOutput("assets", assets);
}
console.log(`🎉 Release ready at ${rel.html_url}`);

View file

@ -12,6 +12,7 @@ export interface Config {
input_body?: string;
input_body_path?: string;
input_files?: string[];
input_overwrite_files?: boolean;
input_draft?: boolean;
input_preserve_order?: boolean;
input_prerelease?: boolean;
@ -62,6 +63,9 @@ export const parseConfig = (env: Env): Config => {
input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH,
input_files: parseInputFiles(env.INPUT_FILES || ""),
input_overwrite_files: env.INPUT_OVERWRITE_FILES
? 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"