From 588487bf0966abc9cbeb416733f74984151b8f3a Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Fri, 3 Jul 2020 09:17:13 +0200 Subject: [PATCH] Default asset_name to the original file name (fixes #4) --- README.md | 3 ++- action.yml | 19 +++++++++---------- dist/index.js | 6 +++--- src/main.ts | 7 ++++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d32d28e..0dd16b8 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,12 @@ You must provide: - `repo_token`: Usually you'll want to set this to `${{ secrets.GITHUB_TOKEN }}`. - `file`: A local file to be uploaded as the asset. -- `asset_name`: The name the file gets as an asset on a release. Use `$tag` to include the tag name. - `tag`: The tag to upload into. If you want the current event's tag, use `${{ github.ref }}` (the `refs/tags/` prefix will be automatically stripped). Optional Arguments +- `asset_name`: The name the file gets as an asset on a release. Use `$tag` to include the tag name. When not provided it will default to the filename. + 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`). - `prerelease`: Mark the release as a pre-release (Default: `false`). diff --git a/action.yml b/action.yml index 757ab0d..1a50147 100644 --- a/action.yml +++ b/action.yml @@ -6,25 +6,24 @@ branding: color: orange inputs: repo_token: - description: 'GitHub token' + description: 'GitHub token.' required: true file: - description: 'Local file to upload' - required: true - asset_name: - description: 'Name of the asset' + description: 'Local file to upload.' required: true tag: - description: 'Tag to use as a release' + description: 'Tag to use as a release.' required: true + 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: 'Overwrite the release in case it already exists.' file_glob: - description: 'If true the file can be a glob pattern, asset_name is ignored if this is true' + description: 'If true the file can be a glob pattern, asset_name is ignored if this is true.' prerelease: - description: 'Mark the release as a pre-release' + description: 'Mark the release as a pre-release.' body: - description: 'Content of the release text' + description: 'Content of the release text.' outputs: browser_download_url: description: 'The publicly available URL of the asset.' diff --git a/dist/index.js b/dist/index.js index a9bba5e..1e03236 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2284,9 +2284,9 @@ function run() { } } else { - const asset_name = core - .getInput('asset_name', { required: true }) - .replace(/\$tag/g, tag); + 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); core.setOutput('browser_download_url', asset_download_url); } diff --git a/src/main.ts b/src/main.ts index 7ed3462..41d2177 100644 --- a/src/main.ts +++ b/src/main.ts @@ -131,9 +131,10 @@ async function run(): Promise { core.setFailed('No files matching the glob pattern found.') } } else { - const asset_name = core - .getInput('asset_name', {required: true}) - .replace(/\$tag/g, tag) + const asset_name = + core.getInput('asset_name') !== '' + ? core.getInput('asset_name').replace(/\$tag/g, tag) + : path.basename(file) const asset_download_url = await upload_to_release( release, file,