feat: Introduce duplicated_error option

This commit is contained in:
Dmitry Patsura 2021-03-01 00:28:32 +03:00
parent 4e5de20777
commit ade2c57f28
No known key found for this signature in database
GPG Key ID: 503DBE40373517B0
3 changed files with 14 additions and 2 deletions

View File

@ -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: `""`).

View File

@ -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:

View File

@ -49,6 +49,7 @@ async function upload_to_release(
asset_name: string,
tag: string,
overwrite: boolean,
duplicated_error: boolean,
octokit: Octokit
): Promise<undefined | string> {
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<void> {
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<void> {
asset_name,
tag,
overwrite,
duplicated_error,
octokit
)
core.setOutput('browser_download_url', asset_download_url)