upload-artifact/entrypoint.sh

28 lines
1.0 KiB
Bash
Executable File

#!/bin/bash -e
API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts?api-version=6.0-preview"
CURL=(curl --fail -v -D/dev/stdout
--header "Authorization: Bearer $INPUT_TOKEN"
--data '{"Type":"actions_storage","Name":"'"$INPUT_NAME"'"}'
)
"${CURL[@]}" -XPOST "$API" -oresp0.json
cat resp0.json
UPLOAD_URL=$(jq -r '.fileContainerResourceUrl' resp0.json)
rm -f resp0.json
#shellcheck disable=SC1083
for artifact in $INPUT_PATH; do
content_length=$(stat -c '%s' "$artifact")
md5=$(cksum -amd5 --base64 --untagged "$artifact" | awk '{print $1}')
"${CURL[@]}" -XPUT -o resp1.json \
--header "x-actions-results-md5: $md5" \
--header "x-tfs-filelength: $content_length" \
--header "content-range: bytes 0-$((content_length - 1))/$content_length" \
"$UPLOAD_URL?retentionDays=$INPUT_RETENTION_DAYS&itemPath=$INPUT_NAME%2F$artifact"
cat resp1.json
"${CURL[@]}" -XPATCH -oresp2.json "$API&artifactName=$INPUT_NAME"
cat resp2.json
rm -f resp1.json resp2.json
done