upload-release-asset
upload-release-asset copied to clipboard
How to upload multiple assets?
I have several build artifacts to upload together. What is the correct way to do so?
I have the same issue and came across this alternative action: https://github.com/softprops/action-gh-release
For everybody struggling with this, just add multiple steps:
- name: Upload binaries
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
...
- name: Upload docs
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
...
- name: Upload sources
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
...
./builds/*.tar.gz
would be the beez kneez. 🐝
We can easily upload multiple assets at once by using the hub command as follows:
name: Release
on:
push:
tags: ["v*"]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
set -x
assets=()
for asset in ./*.md; do
assets+=("-a" "$asset")
done
tag_name="${GITHUB_REF##*/}"
hub release create "${assets[@]}" -m "$tag_name" "$tag_name"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- https://gist.github.com/superbrothers/af84a2f8af394a62352e06537a640746
What is the hub command and where can I find documentation on it?
https://github.com/github/hub
I think that this action should have the possibility to upload multiple files.
This is how I've solved it using hub:
https://github.com/paradajz/OpenDeck/commit/c0852b245e9fe148aea4b3d64ad9223916758335#diff-b4298a7848e5ed756deb6d690bfe168bR29
@paradajz I don't get it, can you explain me it please?
I create a new release manually, first, via GitHub releases page. There I list all the changes and general information about the release. The workflow I've linked is run only when there's a new release created. To upload assets to an existing release, I'm using hub cli. The syntax to upload a single asset to existing release is the following:
hub release edit -a <path/to/asset> -m "" <tag_name>
-m "" means "do not edit the text of release", otherwise default text editor will open.
To add multiple assets to release, syntax would be the following:
hub release edit -a <path/to/asset1> -a <path/to/asset2> -m "" <tag_name>
The following line in my script will search for all the files matching the pattern I want (in my case, all files ending with .sysex extension) and will append "-a" before the path:
$(find . -type f -name "*.sysex" -printf "-a %p ")
${GITHUB_REF##*/} contains the tag name of the latest release in this case.
Hope this makes is clearer.
@paradajz thanks for the very informative answer.
I am trying it in my workflow but hub command want a username, a password and a two factor authentication code.
Is there a way to pass those information to the hub command inside a github workflow/action?
edit: I setup a GITHUB_TOKEN and it worked like a charm. Thanks a billion paradajz.
Another workaround solution using github-script:
- name: Create Release
uses: actions/github-script@v2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);
const fs = require('fs').promises;
const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });
const release = await github.repos.createRelease({
owner, repo,
tag_name: process.env.GITHUB_REF,
draft: true,
target_commitish: sha
});
console.log('created release', { release });
for (let file of await fs.readdir('.')) {
// do whatever filtering you want here, I'm just uploading all the files
console.log('uploading', file);
await github.repos.uploadReleaseAsset({
owner, repo,
release_id: release.data.id,
name: file,
data: await fs.readFile(`./${file}`)
});
}
https://github.com/actions/upload-release-asset/issues/47#issuecomment-659071145
Unclear why this is so difficult and why it's even a separate action from actions/create-release. It should be trivial to create a release and upload a directory of multiple assets in one step.
The solution appears to be to use a third party action: https://github.com/softprops/action-gh-release
It's a shame Github Actions doesn't yet support such a basic feature to create (or update) a release and upload a directory of assets in one step. Travis CI has great support for this.
@amacneil This action is not maintained by GitHub, see #58
@amacneil, meanwhile, you might want to write your own script/Action using e.g. PyGitHub. See https://github.com/eine/tip/blob/master/tip.py.
I create a new release manually, first, via GitHub releases page. There I list all the changes and general information about the release. The workflow I've linked is run only when there's a new release created. To upload assets to an existing release, I'm using hub cli. The syntax to upload a single asset to existing release is the following:
hub release edit -a <path/to/asset> -m "" <tag_name>
-m ""means "do not edit the text of release", otherwise default text editor will open.To add multiple assets to release, syntax would be the following:
hub release edit -a <path/to/asset1> -a <path/to/asset2> -m "" <tag_name>The following line in my script will search for all the files matching the pattern I want (in my case, all files ending with .sysex extension) and will append "-a" before the path:
$(find . -type f -name "*.sysex" -printf "-a %p ")
${GITHUB_REF##*/}contains the tag name of the latest release in this case.Hope this makes is clearer.
Thanks for this solution! More information can be found here, these are useful to me particularly:
- Use
-d -pto definedraftandprerelease. - Use multiple
-mto define release description.
When I've to collect artifacts from different machines (Linux, Windows, Mac) how to archive this ?
@hannesa2, use a last job which depends on the others, and download the artifacts (without a name arg, it will download all). For example: https://github.com/ghdl/ghdl/blob/master/.github/workflows/Test.yml#L327-L347