-
Notifications
You must be signed in to change notification settings - Fork 44
/
action.yml
70 lines (70 loc) · 2.33 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: "Storage upload"
description: "Upload a file or directory to private storage"
inputs:
path:
description: "Path of the file or directory to upload"
required: true
name:
description: "Storage id for the given path"
required: false
default: ""
storage-url:
description: "Url of private storage"
required: true
username:
description: "Username for private storage access"
required: false
default: ""
password:
description: "Password for private storage access"
required: false
default: ""
storage-path:
description: "Custom storage path"
required: false
default: ""
storage-compression:
description: "Specify if compression is required"
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Generate and upload package
shell: bash
run: |
set -e
export XZ_OPT='-T0'
PKG_NAME="${{inputs.name}}"
if [[ -z "$PKG_NAME" ]]; then
PKG_NAME="$(basename ${{inputs.path}})"
if [[ "$PKG_NAME" = "." || "$PKG_NAME" = "*" ]]; then
PKG_NAME="$(basename $(dirname "${{inputs.path}}"))"
fi
fi
TAR_OPT="-cf"
if [[ "${{inputs.storage-compression}}" != "false" ]]; then
TAR_OPT="-cJf"
fi
PKG_FILE="$PKG_NAME.gh.pkg"
if [[ ! -z "${{inputs.storage-path}}" ]]; then
PKG_URL="${{inputs.storage-url}}/${{inputs.storage-path}}/$PKG_FILE"
else
PKG_URL="${{inputs.storage-url}}/${{github.head_ref}}/$PKG_FILE"
fi
CURL_CMD='curl -L --fail -T- '
if [[ ! -z '${{inputs.username}}' ]]; then
CURL_CMD+='-u ${{inputs.username}}:${{inputs.password}} '
fi
if [[ -f "${{inputs.path}}" || -d "${{inputs.path}}" ]]; then
tar -C "$(dirname ${{inputs.path}})" "$(basename ${{inputs.path}})" --mode="u+rwX,g+rwX,o+rX" $TAR_OPT - | $CURL_CMD "$PKG_URL"
TMP="$(mktemp /tmp/nfo_XXXXXX)"
echo "${{inputs.storage-compression}}" > $TMP
find ${{inputs.path}} -type f -print0 | sort -z | xargs -0 sha1sum >> $TMP
$CURL_CMD "$PKG_URL.nfo" < $TMP
rm -rf $TMP
echo "Package successfully uploaded to $PKG_URL"
else
echo "Path '${{inputs.path}}' does not name a file or directory"
exit -1;
fi