From 2ddaeadd4f11551fd7a711153e2067bad7600a01 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Mon, 13 Jan 2025 17:02:44 +0100 Subject: 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. --- upload-artifact | 33 ++++++++++++++++++++++++++++----- 1 file 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 [...]\n" "$0" >&2 + printf "%s [-d ] [...]\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") -- cgit v1.2.3