Skip to content

Commit

Permalink
fix: add 'id' to output, as documented in README
Browse files Browse the repository at this point in the history
Co-authored-by: Mario Reggiori <[email protected]>
  • Loading branch information
2 people authored and Johan Ringmann Fagerberg (JHR) committed Mar 1, 2024
1 parent 164f059 commit 4099be2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/upload-release-asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion tests/upload-release-asset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('Upload Release Asset', () => {
beforeEach(() => {
uploadReleaseAsset = jest.fn().mockReturnValueOnce({
data: {
id: 'id',
browser_download_url: 'browserDownloadUrl'
}
});
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 4099be2

Please sign in to comment.