diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2025-01-13 17:02:44 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2025-01-13 17:02:44 +0100 |
| commit | 2ddaeadd4f11551fd7a711153e2067bad7600a01 (patch) | |
| tree | 7cbc6b2744dd99757b7d024421112b93c980b741 | |
| parent | e60e313f81326b5c2fd28d1f55ac4311a3a3ce16 (diff) | |
Support uploading artifacts to a directory
So far, the root directory (i.e., /) was assumed as the directory to
upload artifacts to. This might be too limiting for some users.
| -rwxr-xr-x | upload-artifact | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/upload-artifact b/upload-artifact index 2dfb989..478d8af 100755 --- a/upload-artifact +++ b/upload-artifact @@ -17,7 +17,7 @@ check() usage() { - printf "%s <artifact> [...]\n" "$0" >&2 + printf "%s [-d <directory>] <artifact> [...]\n" "$0" >&2 } login() @@ -30,37 +30,60 @@ login() "$URL/login" } +getdir() +{ + while getopts "d:" arg + do + case $arg in + d) + dir="$OPTARG";; + *) + usage + return 1 + esac + done +} + upload() { + getdir $@ + shift $((OPTIND - 1)) f="$1" + ldir="/${dir:+$dir/}" curl -X POST \ --fail-with-body \ -H 'Expect:' \ -b "$cookiejar" \ - -F dir="/" \ + -F dir="$ldir" \ -F "file=@$f;filename=$(basename -- "$f")" \ "$URL/upload" } upload_all() { + getdir $@ + shift $((OPTIND - 1)) + for f in $* do - upload "$f" || (printf "Failed to upload %s\n" "$f"; exit 1) - share "$f" || (printf "Failed to share %s\n" "$f"; exit 1) + upload -d "$dir" "$f" || (printf "Failed to upload %s\n" "$f"; exit 1) + share -d "$dir" "$f" || (printf "Failed to share %s\n" "$f"; exit 1) done } share() { + getdir $@ + shift $((OPTIND - 1)) f="$1" resp="$(mktemp)" + name="/${dir:+$dir/}$f" curl -s -X POST \ --fail-with-body \ -b "$cookiejar" \ - --data-urlencode "name=/$f" \ + --data-urlencode "name=$name" \ "$URL/share" > "$resp" pub=$(grep -Poe '/public/[a-f0-9]+' "$resp") |
