feat: test curl

This commit is contained in:
ange 2025-02-01 12:07:18 +00:00
parent 89ba4edd83
commit 96e513bd1b
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D

View File

@ -1,111 +1,77 @@
#!/bin/bash -e #!/bin/bash -e
API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts" #API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts"
[ -n "$INPUT_RETENTION_DAYS" ] && RETENTION="retentionDays=$INPUT_RETENTION_DAYS" #[ -n "$INPUT_RETENTION_DAYS" ] && RETENTION="retentionDays=$INPUT_RETENTION_DAYS"
CURL=(curl --fail -v -D/dev/stdout #CURL=(curl --fail
--header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" # --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN"
--data '{"Type":"actions_storage","Name":"'"$INPUT_NAME"'"}' # --data '{"Type":"actions_storage","Name":"'"$INPUT_NAME"'"}'
) #)
#
"${CURL[@]}" "$API" -oresp0.json #"${CURL[@]}" "$API" -oresp0.json
cat resp0.json #cat resp0.json
UPLOAD_URL=$(jq -r '.fileContainerResourceUrl' resp0.json) #UPLOAD_URL=$(jq -r '.fileContainerResourceUrl' resp0.json)
rm -f resp0.json #rm -f resp0.json
#
for artifact in $INPUT_PATH; do #for artifact in $INPUT_PATH; do
content_length=$(stat -c '%s' "$artifact") # content_length=$(stat -c '%s' "$artifact")
md5="$(openssl md5 -binary "$artifact" | base64)" # md5="$(openssl md5 -binary "$artifact" | base64)"
"${CURL[@]}" -XPUT -o resp1.json \ # "${CURL[@]}" -XPUT -o resp1.json \
--header "x-actions-results-md5: $md5" \ # --header "x-actions-results-md5: $md5" \
--header "x-tfs-filelength: $content_length" \ # --header "x-tfs-filelength: $content_length" \
--header "content-range: bytes 0-$((content_length - 1))/$content_length" \ # --header "content-range: bytes 0-$((content_length - 1))/$content_length" \
"$UPLOAD_URL?$RETENTION&itemPath=$INPUT_NAME%2F$artifact" # "$UPLOAD_URL?$RETENTION&itemPath=$INPUT_NAME%2F$artifact"
cat resp1.json # cat resp1.json
"${CURL[@]}" -XPATCH -oresp2.json "$API&artifactName=$INPUT_NAME" # "${CURL[@]}" -XPATCH -oresp2.json "$API&artifactName=$INPUT_NAME"
cat resp2.json # cat resp2.json
rm -f resp1.json resp2.json # rm -f resp1.json resp2.json
done #done
#function get_ids_from_token() { function get_ids_from_token() {
# local ids local ids
#
# mapfile -t ids \ mapfile -t ids \
# < <(jq -Rr 'split(".")[1] | @base64d | fromjson | .scp | split(":")' <<< "$ACTIONS_RUNTIME_TOKEN") < <(jq -Rr 'split(".")[1] | @base64d | fromjson | .scp | split(":")' <<< "$ACTIONS_RUNTIME_TOKEN")
#
# WORKFLOWRUNID="${ids[1]}" WORKFLOWRUNID="${ids[1]}"
# WORKFLOWJOBRUNID="${ids[2]}" WORKFLOWJOBRUNID="${ids[2]}"
#} }
#
#get_ids_from_token [ -n "$INPUT_RETENTION_DAYS" ] && RETENTION=", \"retention_days\": $INPUT_RETENTION_DAYS"
# get_ids_from_token
# const artifactClient = internalArtifactTwirpClient()
#
# const createArtifactReq: CreateArtifactRequest = {
# "$WORKFLOWRUNID"
# "$WORKFLOWJOBRUNID" # Get the size of the artifact in bytes
# name, ARTIFACT_SIZE="$(stat -c '%s' "$INPUT_PATH")"
# version: 4
# } # Step 1: Create the artifact
# CREATE_ARTIFACT_RESPONSE=$(curl -s -X POST -H "Authorization: token $ACTIONS_RUNTIME_TOKEN" \
# // if there is a retention period, add it to the request -H "Accept: application/vnd.github.v3+json" \
# const expiresAt = getExpiration(options?.retentionDays) -d "{\"name\": \"$INPUT_NAME\", \"size_in_bytes\": $ARTIFACT_SIZE$RETENTION}" \
# if (expiresAt) { "https://api.github.com/repos/OWNER/REPO/actions/runs/$WORKFLOWRUNID/artifacts")
# createArtifactReq.expiresAt = expiresAt
# } # Extract the upload URL from the response
# UPLOAD_URL=$(echo "$CREATE_ARTIFACT_RESPONSE" | jq -r '.upload_url' | sed 's/{?name,label}//')
# const createArtifactResp =
# await artifactClient.CreateArtifact(createArtifactReq) if [[ "$UPLOAD_URL" == "null" ]]; then
# if (!createArtifactResp.ok) { echo "Error: Failed to create artifact. Response: $CREATE_ARTIFACT_RESPONSE"
# throw new InvalidResponseError( exit 1
# 'CreateArtifact: response from backend was not ok' fi
# )
# } echo "Artifact upload URL: $UPLOAD_URL"
#
# const zipUploadStream = await createZipUploadStream( # Step 2: Upload the artifact file
# zipSpecification, UPLOAD_RESPONSE=$(curl -s -X POST -H "Authorization: token $ACTIONS_RUNTIME_TOKEN" \
# options?.compressionLevel -H "Content-Type: application/zip" \
# ) --data-binary @"$INPUT_PATH" \
# "$UPLOAD_URL?name=$INPUT_NAME")
# // Upload zip to blob storage
# const uploadResult = await uploadZipToBlobStorage( # Check if upload was successful
# createArtifactResp.signedUploadUrl, if echo "$UPLOAD_RESPONSE" | grep -q '"id"'; then
# zipUploadStream echo "Artifact uploaded successfully!"
# ) else
# echo "Error uploading artifact. Response: $UPLOAD_RESPONSE"
# // finalize the artifact exit 1
# const finalizeArtifactReq: FinalizeArtifactRequest = { fi
# workflowRunBackendId: backendIds.workflowRunBackendId,
# workflowJobRunBackendId: backendIds.workflowJobRunBackendId,
# name,
# size: uploadResult.uploadSize ? uploadResult.uploadSize.toString() : '0'
# }
#
# if (uploadResult.sha256Hash) {
# finalizeArtifactReq.hash = StringValue.create({
# value: `sha256:${uploadResult.sha256Hash}`
# })
# }
#
# core.info(`Finalizing artifact upload`)
#
# const finalizeArtifactResp =
# await artifactClient.FinalizeArtifact(finalizeArtifactReq)
# if (!finalizeArtifactResp.ok) {
# throw new InvalidResponseError(
# 'FinalizeArtifact: response from backend was not ok'
# )
# }
#
# const artifactId = BigInt(finalizeArtifactResp.artifactId)
# core.info(
# `Artifact ${name}.zip successfully finalized. Artifact ID ${artifactId}`
# )
#
# return {
# size: uploadResult.uploadSize,
# digest: uploadResult.sha256Hash,
# id: Number(artifactId)
# }
#}
#