upload-release-asset
upload-release-asset copied to clipboard
Dynamic Filenames (or an array?)
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/[email protected]
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?
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 }}'
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.
I was working on a similar action before I found out about this.
I took the following approaches for multiple files:
- New line separated list of files
- name: Upload multiple assets to release
with:
files: |
release/first.zip
build/second.zip
third.tar.gz
- 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.
@csexton yep, that's exactly what I started to modify this action for.
And to detect mime type per extension!
here is an example https://github.com/meeDamian/github-release
@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.
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!
@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?
@csexton I would be more than happy if you could provide a pr :)