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

Dynamic Filenames (or an array?) #4

Open
eduncan911 opened this issue Oct 12, 2019 · 9 comments
Open

Dynamic Filenames (or an array?) #4

eduncan911 opened this issue Oct 12, 2019 · 9 comments
Labels
question Further information is requested

Comments

@eduncan911
Copy link

eduncan911 commented Oct 12, 2019

Hello!

So our build job generates around 12 or so asset files with various extensions, signatures, sha, etc.

The thing is, we have dynamic names in our filenames based on dates. Would something like this work?

- name: Upload Asset to Release
  id: upload-release-asset 
  uses: actions/upload-release-asset@v1.0.0
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_FOR_RELEASES }}
  with:
    upload_url: ${{ steps.create_release.outputs.upload_url }}
    asset_path: ./release/usbarmory-mark-one-debian_stretch-base_image-usd-$(shell /bin/date -u "+%Y%m%d").zip
    asset_name: usbarmory-mark-one-debian_stretch-base_image-usd-$(shell /bin/date -u "+%Y%m%d").zip
    asset_content_type: application/zip

I'm asking because I'm still setting things up and it's going to be a while. Figured I'd ask before planning all around this.


As an alternative, could we add a way to pass/read in an array? Or, to run a bash command to obtain the filenames?

Because I can easily do something like this:

ls -1 release/

Where it would list all the files we want to upload.

This would actually be ideal so we can have just 1 upload-release-asset, instead of 12!!!

Thoughts?

@IAmHughes
Copy link
Contributor

Hey @eduncan911

How does this example look as a way to pass in variable inputs:


name: CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    
    steps:

    - name: Set an output
      id: get-date
      run: |
        echo ::set-output name=date::$(/bin/date -u "+%Y%m%d")
    - name: Use the output
      run: |
        echo 'The output date is ${{ steps.get-date.outputs.date }}'

@IAmHughes IAmHughes self-assigned this Oct 14, 2019
@IAmHughes IAmHughes added the question Further information is requested label Oct 14, 2019
@eduncan911
Copy link
Author

eduncan911 commented Oct 15, 2019

Yep, that'll work for individual files.

But again, we have 12 assets to upload. Any chance of accept an array?

From my research, GitHub actions don't accept arrays as inputs. However, others have either used a single string with spaces or linebreaks to pass in, or a json array in a single '' string quote so it's treated as a string. Then split it up on the action side.

@csexton
Copy link

csexton commented Oct 18, 2019

I was working on a similar action before I found out about this.

I took the following approaches for multiple files:

  1. New line separated list of files
- name: Upload multiple assets to release
  with:
    files: |
      release/first.zip
      build/second.zip
      third.tar.gz
  1. Pattern to glob for files
- name: Upload Assets to Release with a wildcard
  with:
    pattern: "release/*.zip"

Because I didn't want to require content-type or file-name as part of the file list I simply used the filename on disk and detected the mime-type based on the extension.

I'd be happy to open a PR if the maintainers wanted this functionality.

@eduncan911
Copy link
Author

@csexton yep, that's exactly what I started to modify this action for.

And to detect mime type per extension!

@wildone
Copy link

wildone commented Oct 20, 2019

here is an example https://github.com/meeDamian/github-release

@eine
Copy link

eine commented Oct 21, 2019

@csexton, in 1138-4EB/tip I use file-type to set content-type. Also, I take all the arguments to files as glob patterns, so there is no need for a separate pattern option:

https://github.com/1138-4EB/tip/blob/a7ad8ec4ef0d919ab02a6f72a507f54e1210a10a/ts/main.ts#L46-L82

You might want to review, reuse or discuss it. I believe that multiple actions will be written for similar tasks (e.g. yours, @wildone's, mine...). It'd be good if we could share best practices.

@IAmHughes
Copy link
Contributor

I think the logic I put in to just take a simple, single file, and then parse the file-type is just that, very simple. I would love to implement functionality to determine mime type as well as take a pattern or list of assets. Originally, I figured a simple approach and (worse case) you can use the Action in 5 steps to upload 5 assets. I understand that isn't SUPER clean or ideal though, would love to see what y'all come up with!

@jperl
Copy link

jperl commented Jan 15, 2020

@IAmHughes The linked github action support multiple files and works really well. Unfortunately it is now deprecated and references to use this one. I changed the github workflow to use this one instead but it requires a lot of duplication.

I believe it would be easy to submit a PR for multi-file support, in the same way the meeDamian action works. However I am concerned there are many PRs with improvements that are outstanding.

Do you have any plans to improve this action or add other contributors to help with the PR backlog?

@derTobsch
Copy link

@csexton I would be more than happy if you could provide a pr :)

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

No branches or pull requests

7 participants