#!/bin/bash -e API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts" CURL=(curl -H "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN") UPLOAD_URL="$("${CURL[@]}" --data "{\"Type\":\"actions_storage\",\"Name\":\"$INPUT_NAME\"}" "$API" | jq -r '.fileContainerResourceUrl')" for artifact in $INPUT_PATH; do content_length=$(stat -c '%s' "$artifact") md5=$(openssl md5 -binary "$artifact" | base64) "${CURL[@]}" -XPUT \ -H "x-actions-results-md5: $md5" \ -H "x-tfs-filelength: ${content_length}" \ -H "content-range: bytes 0-$((content_length-1))/${content_length}" \ --data-binary "@$artifact" \ "$UPLOAD_URL?retentionDays=$INPUT_RETENTION_DAYS&itemPath=$INPUT_NAME%2F$artifact" "${CURL[@]}" -XPATCH \ "$API&artifactName=$INPUT_NAME" done