upload-artifact/entrypoint.sh
2025-01-02 03:26:57 +00:00

29 lines
1.1 KiB
Bash
Executable File

#!/bin/bash -e
#shellcheck disable=SC2016
API='${{ gitea.server_url }}/api/actions_pipeline/_apis/pipelines/workflows/${{ gitea.run_id }}/artifacts?api-version=6.0-preview'
CURL=(curl --fail -v -D/dev/stdout
--header "Authorization: Bearer \${{ inputs.token }}"
--data '{"Type":"actions_storage","Name":"${{ inputs.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 \${{ inputs.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=\${{ inputs.retention-days }}&itemPath=\${{ inputs.name }}%2F$artifact"
cat resp1.json
"${CURL[@]}" -XPATCH -oresp2.json "$API&artifactName=\${{ inputs.name }}"
cat resp2.json
rm -f resp1.json resp2.json
done