This commit is contained in:
ange 2025-02-01 15:17:21 +00:00
parent c26c81971e
commit 8ff519dba1
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D

View File

@ -1,18 +1,31 @@
#!/bin/bash -e
API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts"
# https://github.com/go-gitea/gitea/blob/47bf8363102b95a240fc6a571d608567ff6b212a/routers/api/actions/artifacts.go
CURL=(curl -H "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN")
UPLOAD_URL="$("${CURL[@]}" --data "{\"Type\":\"actions_storage\",\"Name\":\"$INPUT_NAME\"}" "$API" | jq -r '.fileContainerResourceUrl')"
API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts?api-version=6.0-preview"
JSON="$(cat <<EOF
{
"Type": "actions_storage",
"Name": "$INPUT_NAME"
}
EOF
)"
UPLOAD_URL="$("${CURL[@]}" --data "$JSON" "$API" | jq -r '.fileContainerResourceUrl')"
UPLOAD_URL+="?retentionDays=$INPUT_RETENTION_DAYS"
UPLOAD_URL+="&itemPath=$INPUT_NAME%2F$artifact"
for artifact in $INPUT_PATH; do
content_length=$(stat -c '%s' "$artifact")
md5=$(openssl md5 -binary "$artifact" | base64)
SIZE=$(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}" \
-H "x-tfs-filelength: $SIZE" \
-H "x-actions-results-md5: $MD5" \
-H "content-range: bytes 0-$((SIZE - 1))/$SIZE" \
--data-binary "@$artifact" \
"$UPLOAD_URL?retentionDays=$INPUT_RETENTION_DAYS&itemPath=$INPUT_NAME%2F$artifact"
"${CURL[@]}" -XPATCH \
"$API&artifactName=$INPUT_NAME"
"$UPLOAD_URL"
"${CURL[@]}" -XPATCH "$API&artifactName=$INPUT_NAME"
done