diff --git a/README.md b/README.md index feb5e51..7d13dbf 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ jobs: asset_content_type: application/zip ``` -This will upload a release artifact to an existing release, outputting the `browser_download_url` for the asset which could be handled by a third party service, or by GitHub Actions for additional uses. For more information, see the GitHub Documentation for the [upload a release asset](https://developer.github.com/v3/repos/releases/#upload-a-release-asset) endpoint. +This will upload a release artifact to an existing release, outputting the `id` and `browser_download_url` for the asset which could be handled by a third party service, or by GitHub Actions for additional uses. For more information, see the GitHub Documentation for the [upload a release asset](https://developer.github.com/v3/repos/releases/#upload-a-release-asset) endpoint. ## Contributing We would love you to contribute to `@birjj/upload-release-asset`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. diff --git a/action.yml b/action.yml index 3b4ddb4..dd7d133 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,8 @@ inputs: description: 'The content-type of the asset you want to upload. See the supported Media Types here: https://www.iana.org/assignments/media-types/media-types.xhtml for more information' required: true outputs: + id: + description: 'The ID of the asset' browser_download_url: description: 'The URL users can navigate to in order to download the uploaded asset' runs: diff --git a/src/upload-release-asset.js b/src/upload-release-asset.js index 6ae19c6..3c2bf01 100644 --- a/src/upload-release-asset.js +++ b/src/upload-release-asset.js @@ -29,12 +29,13 @@ async function run() { file: fs.readFileSync(assetPath) }); - // Get the browser_download_url for the uploaded release asset from the response + // Get the id and browser_download_url for the uploaded release asset from the response const { - data: { browser_download_url: browserDownloadUrl } + data: { id, browser_download_url: browserDownloadUrl } } = uploadAssetResponse; // Set the output variable for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs + core.setOutput('id', id); core.setOutput('browser_download_url', browserDownloadUrl); } catch (error) { core.setFailed(error.message); diff --git a/tests/upload-release-asset.test.js b/tests/upload-release-asset.test.js index 1721b7e..83a37c3 100644 --- a/tests/upload-release-asset.test.js +++ b/tests/upload-release-asset.test.js @@ -24,6 +24,7 @@ describe('Upload Release Asset', () => { beforeEach(() => { uploadReleaseAsset = jest.fn().mockReturnValueOnce({ data: { + id: 'id', browser_download_url: 'browserDownloadUrl' } }); @@ -79,7 +80,8 @@ describe('Upload Release Asset', () => { await run(); - expect(core.setOutput).toHaveBeenNthCalledWith(1, 'browser_download_url', 'browserDownloadUrl'); + expect(core.setOutput).toHaveBeenNthCalledWith(1, 'id', 'id'); + expect(core.setOutput).toHaveBeenNthCalledWith(2, 'browser_download_url', 'browserDownloadUrl'); }); test('Action fails elegantly', async () => {