Skip to content

Commit

Permalink
Add assets action output (softprops#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncfavier authored Nov 25, 2021
1 parent b260a9f commit 58fa4b7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Add `asset` output as a JSON array containing information about the uploaded assets

## 0.1.14

- provides an new workflow input option `generate_release_notes` which when set to true will automatically generate release notes for you based on GitHub activity [#179](https://github.com/softprops/action-gh-release/pull/179). Please see the [GitHub docs for this feature](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes) for more information
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ The following outputs can be accessed via `${{ steps.<step-id>.outputs }}` from
| `url` | String | Github.com URL for the release |
| `id` | String | Release ID |
| `upload_url` | String | URL for uploading assets to the release |
| `assets` | String | JSON array containing information about each uploaded asset, in the format given [here](https://docs.github.com/en/rest/reference/repos#upload-a-release-asset--code-samples) (minus the `uploader` field) |

As an example, you can use `${{ fromJSON(steps.<step-id>.outputs.assets)[0].browser_download_url }}` to get the download URL of the first asset.

#### environment variables

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ outputs:
description: "Release ID"
upload_url:
description: "URL for uploading assets to the release"
assets:
description: "JSON array containing information about each uploaded asset, in the format given [here](https://docs.github.com/en/rest/reference/repos#upload-a-release-asset--code-samples) (minus the `uploader` field)"
runs:
using: "node12"
main: "dist/index.js"
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,23 @@ async function run() {
if (files.length == 0) {
console.warn(`🤔 ${config.input_files} not include valid file.`);
}
const currentAsserts = rel.assets;
await Promise.all(
const currentAssets = rel.assets;
const assets = await Promise.all(
files.map(async path => {
await upload(
const json = await upload(
config,
gh,
uploadUrl(rel.upload_url),
path,
currentAsserts
currentAssets
);
delete json.uploader;
return json;
})
).catch(error => {
throw error;
});
setOutput("assets", assets);
}
console.log(`🎉 Release ready at ${rel.html_url}`);
setOutput("url", rel.html_url);
Expand Down

0 comments on commit 58fa4b7

Please sign in to comment.