feat: binary
This commit is contained in:
parent
4309ef3db7
commit
144f873cb9
89
entrypoint.sh
Executable file → Normal file
89
entrypoint.sh
Executable file → Normal file
@ -1,67 +1,24 @@
|
||||
#!/bin/bash -ex
|
||||
#!/bin/bash -e
|
||||
|
||||
#API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts"
|
||||
#[ -n "$INPUT_RETENTION_DAYS" ] && RETENTION="retentionDays=$INPUT_RETENTION_DAYS"
|
||||
#CURL=(curl --fail
|
||||
# --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN"
|
||||
# --data '{"Type":"actions_storage","Name":"'"$INPUT_NAME"'"}'
|
||||
#)
|
||||
#
|
||||
#"${CURL[@]}" "$API" -oresp0.json
|
||||
#cat resp0.json
|
||||
#UPLOAD_URL=$(jq -r '.fileContainerResourceUrl' resp0.json)
|
||||
#rm -f resp0.json
|
||||
#
|
||||
#for artifact in $INPUT_PATH; do
|
||||
# content_length=$(stat -c '%s' "$artifact")
|
||||
# md5="$(openssl md5 -binary "$artifact" | base64)"
|
||||
# "${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?$RETENTION&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
|
||||
|
||||
|
||||
[ -n "$INPUT_RETENTION_DAYS" ] && RETENTION=", \"retention_days\": $INPUT_RETENTION_DAYS"
|
||||
IFS=: read -r _ WORKFLOWRUNID WORKFLOWJOBRUNID \
|
||||
< <(jq -Rr 'split(".")[1] | @base64d | fromjson | .scp' <<< "$ACTIONS_RUNTIME_TOKEN")
|
||||
|
||||
|
||||
|
||||
|
||||
# Get the size of the artifact in bytes
|
||||
ARTIFACT_SIZE="$(stat -c '%s' "$INPUT_PATH")"
|
||||
|
||||
# Step 1: Create the artifact
|
||||
CREATE_ARTIFACT_RESPONSE=$(curl -s -X POST -H "Authorization: token $ACTIONS_RUNTIME_TOKEN" \
|
||||
-d "{\"name\": \"$INPUT_NAME\", \"size_in_bytes\": $ARTIFACT_SIZE$RETENTION}" \
|
||||
"https://$GITHUB_SERVER_URL/api/repos/$GITHUB_REPOSITORY/actions/runs/$WORKFLOWRUNID/artifacts")
|
||||
|
||||
# Extract the upload URL from the response
|
||||
UPLOAD_URL=$(echo "$CREATE_ARTIFACT_RESPONSE" | jq -r '.upload_url' | sed 's/{?name,label}//')
|
||||
|
||||
if [[ "$UPLOAD_URL" == "null" ]]; then
|
||||
echo "Error: Failed to create artifact. Response: $CREATE_ARTIFACT_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Artifact upload URL: $UPLOAD_URL"
|
||||
|
||||
# Step 2: Upload the artifact file
|
||||
UPLOAD_RESPONSE=$(curl -s -X POST -H "Authorization: token $ACTIONS_RUNTIME_TOKEN" \
|
||||
-H "Content-Type: application/zip" \
|
||||
--data-binary @"$INPUT_PATH" \
|
||||
"$UPLOAD_URL?name=$INPUT_NAME")
|
||||
|
||||
# Check if upload was successful
|
||||
if echo "$UPLOAD_RESPONSE" | grep -q '"id"'; then
|
||||
echo "Artifact uploaded successfully!"
|
||||
else
|
||||
echo "Error uploading artifact. Response: $UPLOAD_RESPONSE"
|
||||
exit 1
|
||||
fi
|
||||
curl --fail -v -D /dev/stdout -o resp0.json --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" \
|
||||
-X POST --data "{\"Type\":\"actions_storage\",\"Name\":\"$INPUTS_NAME\"}" \
|
||||
"$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts?api-version=6.0-preview"
|
||||
cat resp0.json
|
||||
UPLOAD_URL=$(jq -r '.fileContainerResourceUrl' resp0.json)
|
||||
for artifact in $INPUTS_PATH; do
|
||||
content_length=$(ls -l "$artifact" | awk '{print $5}')
|
||||
md5=$(openssl md5 -binary "$artifact" | base64)
|
||||
curl --fail -v -D /dev/stdout -o resp1.json --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" \
|
||||
--header "x-actions-results-md5: $md5" \
|
||||
--header "x-tfs-filelength: ${content_length}" \
|
||||
--header "content-range: bytes 0-$((content_length-1))/${content_length}" \
|
||||
-X PUT --data-binary "@$artifact" \
|
||||
"${UPLOAD_URL}?retentionDays=$INPUTS_RETENTION_DAYS&itemPath=$INPUTS_NAME%2F$artifact"
|
||||
cat resp1.json
|
||||
curl --fail -v -D /dev/stdout -o resp2.json --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" \
|
||||
-X PATCH \
|
||||
"$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts?api-version=6.0-preview&artifactName=$INPUTS_NAME"
|
||||
cat resp2.json
|
||||
rm resp1.json resp2.json
|
||||
done
|
||||
rm resp0.json
|
||||
|
Loading…
Reference in New Issue
Block a user