From f66c1c98f12e032443e806fae4882a05368df40c Mon Sep 17 00:00:00 2001 From: Akkuman Date: Wed, 25 Jun 2025 10:51:48 +0800 Subject: [PATCH] fix: deletion of old releases Duplicate deletions occur when users generate their own .md5 and .sha256 files and do not use action's built-in md5sum and sha256sum functions. issue: https://github.com/akkuman/gitea-release-action/issues/5 --- dist/index.js | 29 ++++++++++++++++++----------- main.js | 29 ++++++++++++++++++----------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/dist/index.js b/dist/index.js index f046a5f..f4be3fd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -48279,18 +48279,25 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) { id: release_id, }) // deleted old release attachment + const will_deleted = new Set(); for (const filepath of all_files) { - for (const attachment of attachments) { - let will_deleted = [external_path_.basename(filepath), `${external_path_.basename(filepath)}.md5`, `${external_path_.basename(filepath)}.sha256`] - if (will_deleted.includes(attachment.name)) { - await client.repository.repoDeleteReleaseAttachment({ - owner: owner, - repo: repo, - id: release_id, - attachmentId: attachment.id, - }) - console.log(`Successfully deleted old release attachment ${attachment.name}`) - } + will_deleted.add(external_path_.basename(filepath)); + if (params.md5sum) { + will_deleted.add(`${external_path_.basename(filepath)}.md5`); + } + if (params.sha256sum) { + will_deleted.add(`${external_path_.basename(filepath)}.sha256`); + } + } + for (const attachment of attachments) { + if (will_deleted.has(attachment.name)) { + await client.repository.repoDeleteReleaseAttachment({ + owner: owner, + repo: repo, + id: release_id, + attachmentId: attachment.id, + }) + console.log(`Successfully deleted old release attachment ${attachment.name}`) } } // upload new release attachment diff --git a/main.js b/main.js index e9987b3..4f5f42c 100644 --- a/main.js +++ b/main.js @@ -143,18 +143,25 @@ async function uploadFiles(client, owner, repo, release_id, all_files, params) { id: release_id, }) // deleted old release attachment + const will_deleted = new Set(); for (const filepath of all_files) { - for (const attachment of attachments) { - let will_deleted = [path.basename(filepath), `${path.basename(filepath)}.md5`, `${path.basename(filepath)}.sha256`] - if (will_deleted.includes(attachment.name)) { - await client.repository.repoDeleteReleaseAttachment({ - owner: owner, - repo: repo, - id: release_id, - attachmentId: attachment.id, - }) - console.log(`Successfully deleted old release attachment ${attachment.name}`) - } + will_deleted.add(path.basename(filepath)); + if (params.md5sum) { + will_deleted.add(`${path.basename(filepath)}.md5`); + } + if (params.sha256sum) { + will_deleted.add(`${path.basename(filepath)}.sha256`); + } + } + for (const attachment of attachments) { + if (will_deleted.has(attachment.name)) { + await client.repository.repoDeleteReleaseAttachment({ + owner: owner, + repo: repo, + id: release_id, + attachmentId: attachment.id, + }) + console.log(`Successfully deleted old release attachment ${attachment.name}`) } } // upload new release attachment