From ade2c57f28d4f5d0b06bdcf5e17b889a9b18ded6 Mon Sep 17 00:00:00 2001 From: Dmitry Patsura Date: Mon, 1 Mar 2021 00:28:32 +0300 Subject: [PATCH] feat: Introduce duplicated_error option --- README.md | 1 + action.yml | 5 ++++- src/main.ts | 10 +++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c2b3c7..8f1df39 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Optional Arguments This is not used if `file_glob` is set to `true`. - `file_glob`: If set to true, the file argument can be a glob pattern (`asset_name` is ignored in this case) (Default: `false`) - `overwrite`: If an asset with the same name already exists, overwrite it (Default: `false`). +- `duplicated_error`: If an asset with the same name already exists, throw error (Default: `true`). - `prerelease`: Mark the release as a pre-release (Default: `false`). - `release_name`: Explicitly set a release name. (Defaults: implicitly same as `tag` via GitHub API). - `body`: Content of the release text (Default: `""`). diff --git a/action.yml b/action.yml index d86edeb..192c3a1 100644 --- a/action.yml +++ b/action.yml @@ -17,7 +17,10 @@ inputs: asset_name: description: 'Name of the asset. When not provided will use the file name. Unused if file_glob is set to "true".' overwrite: - description: 'Overwrite the release in case it already exists.' + description: 'If an asset with the same name already exists, overwrite it.' + duplicated_error: + description: 'If an asset with the same name already exists, throw error.' + default: "true" file_glob: description: 'If true the file can be a glob pattern, asset_name is ignored if this is true.' prerelease: diff --git a/src/main.ts b/src/main.ts index a1a64c0..7d77cc0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -49,6 +49,7 @@ async function upload_to_release( asset_name: string, tag: string, overwrite: boolean, + duplicated_error: boolean, octokit: Octokit ): Promise { const stat = fs.statSync(file) @@ -78,7 +79,12 @@ async function upload_to_release( asset_id: duplicate_asset.id }) } else { - core.setFailed(`An asset called ${asset_name} already exists.`) + if (duplicated_error) { + core.setFailed(`An asset called ${asset_name} already exists.`) + return duplicate_asset.browser_download_url + } + + core.warn(`An asset called ${asset_name} already exists.`) return duplicate_asset.browser_download_url } } else { @@ -134,6 +140,7 @@ async function run(): Promise { const file_glob = core.getInput('file_glob') == 'true' ? true : false const overwrite = core.getInput('overwrite') == 'true' ? true : false + const duplicated_error = core.getInput('duplicated_error') == 'true' ? true : false const prerelease = core.getInput('prerelease') == 'true' ? true : false const release_name = core.getInput('release_name') const body = core.getInput('body') @@ -158,6 +165,7 @@ async function run(): Promise { asset_name, tag, overwrite, + duplicated_error, octokit ) core.setOutput('browser_download_url', asset_download_url)