From 6071b6a76544a2479bcee615224f303f933ccae1 Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Tue, 17 Jun 2025 09:03:57 -0700 Subject: [PATCH 1/7] Adds duplicates parameter --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 80f9840f..98d98a34 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,9 @@ inputs: description: 'Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository\"s default branch (usually `main`).' repo_name: description: 'Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. Defaults to the current repository' + check_duplicates: + description: 'Check for duplicate assets with the same name in the release and skip uploading of those. Defaults to "true".' + default: true outputs: browser_download_url: description: 'The publicly available URL of the asset.' From 5b5f092beea3dd5657b81898467f8e335b4c0beb Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Tue, 17 Jun 2025 09:07:15 -0700 Subject: [PATCH 2/7] Only perform duplicate checking if parameter is enabled --- src/main.ts | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/main.ts b/src/main.ts index 748e72d9..953d08a4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -120,6 +120,7 @@ async function upload_to_release( tag: string, overwrite: boolean, octokit: ReturnType<(typeof github)['getOctokit']> + check_duplicates: boolean, ): Promise { const stat = fs.statSync(file) if (!stat.isFile()) { @@ -132,30 +133,32 @@ async function upload_to_release( return } - // Check for duplicates. - const assets: RepoAssetsResp = await octokit.paginate(repoAssets, { - ...repo(), - release_id: release.data.id - }) - const duplicate_asset = assets.find(a => a.name === asset_name) - if (duplicate_asset !== undefined) { - if (overwrite) { - core.debug( - `An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.` - ) - await octokit.request(deleteAssets, { + if (check_duplicates) { + // Check for duplicates. + const assets: RepoAssetsResp = await octokit.paginate(repoAssets, { ...repo(), - asset_id: duplicate_asset.id + release_id: release.data.id }) - } else { - core.setFailed(`An asset called ${asset_name} already exists.`) - return duplicate_asset.browser_download_url + const duplicate_asset = assets.find(a => a.name === asset_name) + if (duplicate_asset !== undefined) { + if (overwrite) { + core.debug( + `An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.` + ) + await octokit.request(deleteAssets, { + ...repo(), + asset_id: duplicate_asset.id + }) + } else { + core.setFailed(`An asset called ${asset_name} already exists.`) + return duplicate_asset.browser_download_url + } + } else { + core.debug( + `No pre-existing asset called ${asset_name} found in release ${tag}. All good.` + ) + } } - } else { - core.debug( - `No pre-existing asset called ${asset_name} found in release ${tag}. All good.` - ) - } core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`) @@ -219,6 +222,7 @@ async function run(): Promise { const make_latest = core.getInput('make_latest') != 'false' ? true : false const release_name = core.getInput('release_name') const target_commit = core.getInput('target_commit') + const check_duplicates = core.getInput('check_duplicates') == 'true' ? true : false const body = core .getInput('body') .replace(/%0A/gi, '\n') @@ -250,7 +254,8 @@ async function run(): Promise { asset_name, tag, overwrite, - octokit + octokit, + check_duplicates ) core.setOutput('browser_download_url', asset_download_url) } @@ -268,7 +273,8 @@ async function run(): Promise { asset_name, tag, overwrite, - octokit + octokit, + check_duplicates ) core.setOutput('browser_download_url', asset_download_url) } From f9a24140847e92696590aade304789dc8d51307a Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Tue, 17 Jun 2025 09:07:42 -0700 Subject: [PATCH 3/7] cleanup --- src/main.ts | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main.ts b/src/main.ts index 953d08a4..04ad38ae 100644 --- a/src/main.ts +++ b/src/main.ts @@ -119,8 +119,8 @@ async function upload_to_release( asset_name: string, tag: string, overwrite: boolean, - octokit: ReturnType<(typeof github)['getOctokit']> - check_duplicates: boolean, + octokit: ReturnType<(typeof github)['getOctokit']>, + check_duplicates: boolean ): Promise { const stat = fs.statSync(file) if (!stat.isFile()) { @@ -133,32 +133,32 @@ async function upload_to_release( return } - if (check_duplicates) { - // Check for duplicates. - const assets: RepoAssetsResp = await octokit.paginate(repoAssets, { - ...repo(), - release_id: release.data.id - }) - const duplicate_asset = assets.find(a => a.name === asset_name) - if (duplicate_asset !== undefined) { - if (overwrite) { - core.debug( - `An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.` - ) - await octokit.request(deleteAssets, { - ...repo(), - asset_id: duplicate_asset.id - }) - } else { - core.setFailed(`An asset called ${asset_name} already exists.`) - return duplicate_asset.browser_download_url - } - } else { + if (check_duplicates) { + // Check for duplicates. + const assets: RepoAssetsResp = await octokit.paginate(repoAssets, { + ...repo(), + release_id: release.data.id + }) + const duplicate_asset = assets.find(a => a.name === asset_name) + if (duplicate_asset !== undefined) { + if (overwrite) { core.debug( - `No pre-existing asset called ${asset_name} found in release ${tag}. All good.` + `An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.` ) + await octokit.request(deleteAssets, { + ...repo(), + asset_id: duplicate_asset.id + }) + } else { + core.setFailed(`An asset called ${asset_name} already exists.`) + return duplicate_asset.browser_download_url } + } else { + core.debug( + `No pre-existing asset called ${asset_name} found in release ${tag}. All good.` + ) } + } core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`) @@ -222,7 +222,8 @@ async function run(): Promise { const make_latest = core.getInput('make_latest') != 'false' ? true : false const release_name = core.getInput('release_name') const target_commit = core.getInput('target_commit') - const check_duplicates = core.getInput('check_duplicates') == 'true' ? true : false + const check_duplicates = + core.getInput('check_duplicates') == 'true' ? true : false const body = core .getInput('body') .replace(/%0A/gi, '\n') From b469d601c2a9d6838eb3e67e5596399e379a8b9c Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Tue, 17 Jun 2025 09:09:03 -0700 Subject: [PATCH 4/7] build --- dist/index.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8926a129..111763d2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -117,7 +117,7 @@ function get_release_by_tag(tag, draft, prerelease, make_latest, release_name, b return release; }); } -function upload_to_release(release, file, asset_name, tag, overwrite, octokit) { +function upload_to_release(release, file, asset_name, tag, overwrite, octokit, check_duplicates) { return __awaiter(this, void 0, void 0, function* () { const stat = fs.statSync(file); if (!stat.isFile()) { @@ -129,22 +129,24 @@ function upload_to_release(release, file, asset_name, tag, overwrite, octokit) { core.debug(`Skipping ${file}, since its size is 0`); return; } - // Check for duplicates. - const assets = yield octokit.paginate(repoAssets, Object.assign(Object.assign({}, repo()), { release_id: release.data.id })); - const duplicate_asset = assets.find(a => a.name === asset_name); - if (duplicate_asset !== undefined) { - if (overwrite) { - core.debug(`An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.`); - yield octokit.request(deleteAssets, Object.assign(Object.assign({}, repo()), { asset_id: duplicate_asset.id })); + if (check_duplicates) { + // Check for duplicates. + const assets = yield octokit.paginate(repoAssets, Object.assign(Object.assign({}, repo()), { release_id: release.data.id })); + const duplicate_asset = assets.find(a => a.name === asset_name); + if (duplicate_asset !== undefined) { + if (overwrite) { + core.debug(`An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.`); + yield octokit.request(deleteAssets, Object.assign(Object.assign({}, repo()), { asset_id: duplicate_asset.id })); + } + else { + core.setFailed(`An asset called ${asset_name} already exists.`); + return duplicate_asset.browser_download_url; + } } else { - core.setFailed(`An asset called ${asset_name} already exists.`); - return duplicate_asset.browser_download_url; + core.debug(`No pre-existing asset called ${asset_name} found in release ${tag}. All good.`); } } - else { - core.debug(`No pre-existing asset called ${asset_name} found in release ${tag}. All good.`); - } core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`); // @ts-ignore const uploaded_asset = yield (0, attempt_1.retry)(() => __awaiter(this, void 0, void 0, function* () { @@ -195,6 +197,7 @@ function run() { const make_latest = core.getInput('make_latest') != 'false' ? true : false; const release_name = core.getInput('release_name'); const target_commit = core.getInput('target_commit'); + const check_duplicates = core.getInput('check_duplicates') == 'true' ? true : false; const body = core .getInput('body') .replace(/%0A/gi, '\n') @@ -207,7 +210,7 @@ function run() { if (files.length > 0) { for (const file_ of files) { const asset_name = path.basename(file_); - const asset_download_url = yield upload_to_release(release, file_, asset_name, tag, overwrite, octokit); + const asset_download_url = yield upload_to_release(release, file_, asset_name, tag, overwrite, octokit, check_duplicates); core.setOutput('browser_download_url', asset_download_url); } } @@ -219,7 +222,7 @@ function run() { const asset_name = core.getInput('asset_name') !== '' ? core.getInput('asset_name').replace(/\$tag/g, tag) : path.basename(file); - const asset_download_url = yield upload_to_release(release, file, asset_name, tag, overwrite, octokit); + const asset_download_url = yield upload_to_release(release, file, asset_name, tag, overwrite, octokit, check_duplicates); core.setOutput('browser_download_url', asset_download_url); } } From 720234ecc42b49e3519b0cf11a485941bfba335e Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Fri, 20 Jun 2025 14:32:10 -0700 Subject: [PATCH 5/7] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 32c0a293..68584fd0 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Optional Arguments - `target_commit`: Sets the commit hash or branch for the tag to be based on (Default: the default branch, usually `main`). - `body`: Content of the release text (Default: `""`). - `repo_name`: Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. (Default: current repository). +- `check_duplicates`: Enable or disable the check for existing assets with the same name. If enabled, the action will skip uploading the asset if it already exists. (Default: `true`). ## Output variables From 7f715940f34b189d9d1569a4fd3bd11f7ce910b7 Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Fri, 20 Jun 2025 15:21:46 -0700 Subject: [PATCH 6/7] Fixed issue with default value of check_duplicates --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 04ad38ae..caefe65f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -223,7 +223,7 @@ async function run(): Promise { const release_name = core.getInput('release_name') const target_commit = core.getInput('target_commit') const check_duplicates = - core.getInput('check_duplicates') == 'true' ? true : false + core.getInput('check_duplicates') != 'false' ? true : false const body = core .getInput('body') .replace(/%0A/gi, '\n') From 83ec5bb4d8dedab119b591e10116af7cc0817151 Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Fri, 20 Jun 2025 15:22:21 -0700 Subject: [PATCH 7/7] cleanup --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 111763d2..613eca03 100644 --- a/dist/index.js +++ b/dist/index.js @@ -197,7 +197,7 @@ function run() { const make_latest = core.getInput('make_latest') != 'false' ? true : false; const release_name = core.getInput('release_name'); const target_commit = core.getInput('target_commit'); - const check_duplicates = core.getInput('check_duplicates') == 'true' ? true : false; + const check_duplicates = core.getInput('check_duplicates') != 'false' ? true : false; const body = core .getInput('body') .replace(/%0A/gi, '\n')