From a32b81ed6a183fc3d223a7ed05b292301727e07a Mon Sep 17 00:00:00 2001 From: ange Date: Wed, 8 Jan 2025 06:21:32 +0000 Subject: [PATCH] fix: token --- entrypoint.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 74b4a64..6568e5d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,17 +1,16 @@ #!/bin/bash -e -API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts?api-version=6.0-preview" +API="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$GITHUB_RUN_ID/artifacts" CURL=(curl --fail -v -D/dev/stdout - --header "Authorization: Bearer $INPUT_TOKEN" + --header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN" --data '{"Type":"actions_storage","Name":"'"$INPUT_NAME"'"}' ) -"${CURL[@]}" -XPOST "$API" -oresp0.json +"${CURL[@]}" "$API" -oresp0.json cat resp0.json UPLOAD_URL=$(jq -r '.fileContainerResourceUrl' resp0.json) rm -f resp0.json -#shellcheck disable=SC1083 for artifact in $INPUT_PATH; do content_length=$(stat -c '%s' "$artifact") md5=$(cksum -amd5 --base64 --untagged "$artifact" | awk '{print $1}') @@ -25,3 +24,87 @@ for artifact in $INPUT_PATH; do cat resp2.json rm -f resp1.json resp2.json done + + +#function get_ids_from_token() { +# local ids +# +# mapfile -t ids \ +# < <(jq -Rr 'split(".")[1] | @base64d | fromjson | .scp | split(":")' <<< "$ACTIONS_RUNTIME_TOKEN") +# +# WORKFLOWRUNID="${ids[1]}" +# WORKFLOWJOBRUNID="${ids[2]}" +#} +# +#get_ids_from_token +# +# const artifactClient = internalArtifactTwirpClient() +# +# const createArtifactReq: CreateArtifactRequest = { +# "$WORKFLOWRUNID" +# "$WORKFLOWJOBRUNID" +# name, +# version: 4 +# } +# +# // if there is a retention period, add it to the request +# const expiresAt = getExpiration(options?.retentionDays) +# if (expiresAt) { +# createArtifactReq.expiresAt = expiresAt +# } +# +# const createArtifactResp = +# await artifactClient.CreateArtifact(createArtifactReq) +# if (!createArtifactResp.ok) { +# throw new InvalidResponseError( +# 'CreateArtifact: response from backend was not ok' +# ) +# } +# +# const zipUploadStream = await createZipUploadStream( +# zipSpecification, +# options?.compressionLevel +# ) +# +# // Upload zip to blob storage +# const uploadResult = await uploadZipToBlobStorage( +# createArtifactResp.signedUploadUrl, +# zipUploadStream +# ) +# +# // finalize the artifact +# const finalizeArtifactReq: FinalizeArtifactRequest = { +# 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) +# } +#} +#