upload-release-asset icon indicating copy to clipboard operation
upload-release-asset copied to clipboard

How to upload multiple assets?

Open riobard opened this issue 5 years ago • 20 comments

I have several build artifacts to upload together. What is the correct way to do so?

riobard avatar Feb 15 '20 12:02 riobard

I have the same issue and came across this alternative action: https://github.com/softprops/action-gh-release

tamalsaha avatar Feb 24 '20 10:02 tamalsaha

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:
    ...

haampie avatar Apr 13 '20 19:04 haampie

./builds/*.tar.gz

would be the beez kneez. 🐝

hunterlong avatar Apr 17 '20 14:04 hunterlong

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

superbrothers avatar Apr 21 '20 14:04 superbrothers

What is the hub command and where can I find documentation on it?

stm2 avatar May 15 '20 09:05 stm2

https://github.com/github/hub

tamalsaha avatar May 15 '20 09:05 tamalsaha

I think that this action should have the possibility to upload multiple files.

sblantipodi avatar Jul 13 '20 22:07 sblantipodi

This is how I've solved it using hub: https://github.com/paradajz/OpenDeck/commit/c0852b245e9fe148aea4b3d64ad9223916758335#diff-b4298a7848e5ed756deb6d690bfe168bR29

paradajz avatar Aug 15 '20 12:08 paradajz

@paradajz I don't get it, can you explain me it please?

sblantipodi avatar Aug 18 '20 00:08 sblantipodi

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 avatar Aug 18 '20 07:08 paradajz

@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?

sblantipodi avatar Aug 23 '20 21:08 sblantipodi

edit: I setup a GITHUB_TOKEN and it worked like a charm. Thanks a billion paradajz.

sblantipodi avatar Aug 23 '20 21:08 sblantipodi

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

kmturley avatar Sep 25 '20 05:09 kmturley

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.

amacneil avatar Nov 02 '20 01:11 amacneil

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 avatar Nov 02 '20 04:11 amacneil

@amacneil This action is not maintained by GitHub, see #58

Legion2 avatar Nov 02 '20 12:11 Legion2

@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.

eine avatar Nov 02 '20 12:11 eine

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 -p to define draft and prerelease.
  • Use multiple -m to define release description.

superarts avatar Dec 30 '20 13:12 superarts

When I've to collect artifacts from different machines (Linux, Windows, Mac) how to archive this ?

hannesa2 avatar Feb 18 '21 13:02 hannesa2

@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

eine avatar Feb 18 '21 13:02 eine