Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

How to upload multiple assets? #28

Open
riobard opened this issue Feb 15, 2020 · 20 comments
Open

How to upload multiple assets? #28

riobard opened this issue Feb 15, 2020 · 20 comments

Comments

@riobard
Copy link

riobard commented Feb 15, 2020

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

@tamalsaha
Copy link

tamalsaha commented Feb 24, 2020

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

@haampie
Copy link

haampie commented Apr 13, 2020

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

@hunterlong
Copy link

./builds/*.tar.gz

would be the beez kneez. 🐝

@superbrothers
Copy link

superbrothers commented Apr 21, 2020

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 }}

@stm2
Copy link

stm2 commented May 15, 2020

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

@tamalsaha
Copy link

https://github.com/github/hub

@sblantipodi
Copy link

sblantipodi commented Jul 13, 2020

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

@paradajz
Copy link

This is how I've solved it using hub:
shanteacontrols/OpenDeck@c0852b2#diff-b4298a7848e5ed756deb6d690bfe168bR29

@sblantipodi
Copy link

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

@paradajz
Copy link

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.

@sblantipodi
Copy link

@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
Copy link

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

hannesa2 added a commit to ytai/ioio that referenced this issue Sep 7, 2020
@kmturley
Copy link

kmturley commented Sep 25, 2020

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}`)
        });            
      }

#47 (comment)

@amacneil
Copy link

amacneil commented Nov 2, 2020

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
Copy link

amacneil commented Nov 2, 2020

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.

@Legion2
Copy link

Legion2 commented Nov 2, 2020

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

@eine
Copy link

eine commented Nov 2, 2020

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

@superarts
Copy link

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.

@hannesa2
Copy link

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

@eine
Copy link

eine commented Feb 18, 2021

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests