Fix: skip uploading empty assets

This commit is contained in:
Loyalsoldier 2023-05-11 15:57:43 +08:00
parent c9b46fe7aa
commit e86d563ce8
No known key found for this signature in database
GPG key ID: 23829BBC1ACF2C90

View file

@ -148,6 +148,7 @@ export const upload = async (
const currentAsset = currentAssets.find( const currentAsset = currentAssets.find(
({ name: currentName }) => currentName == name ({ name: currentName }) => currentName == name
); );
// Delete old asset even if the size of currentAsset is 0
if (currentAsset) { if (currentAsset) {
console.log(`♻️ Deleting previously uploaded asset ${name}...`); console.log(`♻️ Deleting previously uploaded asset ${name}...`);
await github.rest.repos.deleteReleaseAsset({ await github.rest.repos.deleteReleaseAsset({
@ -156,6 +157,10 @@ export const upload = async (
repo, repo,
}); });
} }
if (size === 0) {
console.warn(`❌ Skip uploading release asset ${name} with 0 byte in size`);
return {}; // return empty JSON object for compatibility
}
console.log(`⬆️ Uploading ${name}...`); console.log(`⬆️ Uploading ${name}...`);
const endpoint = new URL(url); const endpoint = new URL(url);
endpoint.searchParams.append("name", name); endpoint.searchParams.append("name", name);