-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yml
40 lines (40 loc) · 1.38 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: 'Upload GitHub release assets'
description: 'Upload file to GitHub release assets'
inputs:
tag:
description: 'git tag'
required: true
default: ${{ github.ref }}
asset-path:
description: 'file path to be uploaded'
required: true
default: ''
runs:
using: "composite"
steps:
- run: |
GH_RELEASE=$(sed s#/refs/tags## <<< "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ inputs.tag }}")
upload_url=$(curl -s --request GET --url $GH_RELEASE | grep -oP '(?<="upload_url": ")[^"]*' | cut -d'{' -f1)
j=0
if [ -d ${{ inputs.asset-path }} ]; then
for filename in `ls ${{ inputs.asset-path }}`;
do
folder_list[j]=${{ inputs.asset-path }}/$filename
j=`expr $j + 1`
done
else
folder_list[0]=${{ inputs.asset-path }}
fi
echo "Uploading asset... "
for filepath in ${folder_list[@]};
do
filename=$(basename "${filepath}")
content_type=$(file -b --mime-type ${filepath})
curl --silent \
--request POST \
--url "$upload_url?name=$filename" \
--header "authorization: Bearer ${{ github.token }}" \
--header "content-type: $content_type" \
--data-binary @"${filepath}"
done
shell: bash