upload-artifact/entrypoint.sh
2025-10-22 05:39:03 +00:00

31 lines
1,007 B
Bash
Executable file

#!/bin/bash -e
# https://codeberg.org/forgejo/forgejo/src/commit/bf80842b4f14a075c6840b6fe37d59b5ac3fac44/routers/api/actions/artifacts.go
CURL=(curl -H "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN")
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
SIZE=$(stat -c '%s' "$artifact")
MD5=$(openssl md5 -binary "$artifact" | base64)
"${CURL[@]}" -XPUT \
-H "x-tfs-filelength: $SIZE" \
-H "x-actions-results-md5: $MD5" \
-H "content-range: bytes 0-$((SIZE - 1))/$SIZE" \
--data-binary "@$artifact" \
"$UPLOAD_URL"
"${CURL[@]}" -XPATCH "$API&artifactName=$INPUT_NAME"
done