release: support stored Forgejo password
ober
70f781b8e05a1d9ef84fb9c6d0f43545e37fda99
--- a/support/forgejo-release-upload.sh +++ b/support/forgejo-release-upload.sh @@ -6,7 +6,7 @@ umask 077 usage() { echo "Usage: $0 VERSION OWNER REPO FILE..." >&2 - echo " requires FORGEJO_TOKEN with repository write permission" >&2 + echo " requires FORGEJO_TOKEN or FORGEJO_PASSWORD with repository write permission" >&2 } [ "${1:-}" ] || { usage; exit 2; } @@ -19,8 +19,8 @@ repo=$3 shift 3 [ "$#" -gt 0 ] || { usage; exit 2; } -[ -n "${FORGEJO_TOKEN:-}" ] || { - echo "ERROR: FORGEJO_TOKEN is required" >&2 +[ -n "${FORGEJO_TOKEN:-}" ] || [ -n "${FORGEJO_PASSWORD:-}" ] || { + echo "ERROR: FORGEJO_TOKEN or FORGEJO_PASSWORD is required" >&2 exit 1 } printf '%s\n' "$version" | grep -Eq '^v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' || { @@ -61,12 +61,21 @@ request() { url=$2 output=$3 shift 3 - curl --silent --show-error --location \ - --request "$method" \ - --header "Authorization: token $FORGEJO_TOKEN" \ - --output "$output" \ - --write-out '%{http_code}' \ - "$@" "$url" + if [ -n "${FORGEJO_TOKEN:-}" ]; then + curl --silent --show-error --location \ + --request "$method" \ + --header "Authorization: token $FORGEJO_TOKEN" \ + --output "$output" \ + --write-out '%{http_code}' \ + "$@" "$url" + else + curl --silent --show-error --location \ + --request "$method" \ + --user "$owner:$FORGEJO_PASSWORD" \ + --output "$output" \ + --write-out '%{http_code}' \ + "$@" "$url" + fi } release_json="$tmp/release.json"