From 9748cdd067a2247456cdfbb11f782de3c09557f8 Mon Sep 17 00:00:00 2001 From: Filias Heidt Date: Wed, 19 Feb 2025 09:52:24 +0100 Subject: [PATCH] add upload action --- action.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..4472393 --- /dev/null +++ b/action.yml @@ -0,0 +1,50 @@ +name: "Artifacts upload" +author: "rps" +description: "Action to upload cicd artifacts" +inputs: + name: + description: artifact name + required: true + default: 'artifact' + path: + description: list of paths to upload as artifacts + required: true + retention-days: + description: > + Duration after which artifact will expire in days. 0 means using default retention. + + Minimum 1 day. + Maximum 90 days unless changed from the repository settings page. + default: 30 + token: + description: token to authenticate to gitea + required: true + default: ${{ github.token }} +runs: + using: "composite" + steps: + - name: upload artifacts + shell: sh + run: | + curl --fail -v -D /dev/stdout -o resp0.json --header "Authorization: Bearer ${{ inputs.token }}" \ + -X POST --data '{"Type":"actions_storage","Name":"${{ inputs.name }}"}' \ + "${{ gitea.server_url }}/api/actions_pipeline/_apis/pipelines/workflows/${{ gitea.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=$(cksum -a md5 --base64 --untagged "$artifact" | awk '{print $1}') + curl --fail -v -D /dev/stdout -o resp1.json --header "Authorization: Bearer ${{ inputs.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 ${{ inputs.token }}" \ + -X PATCH \ + "${{ gitea.server_url }}/api/actions_pipeline/_apis/pipelines/workflows/${{ gitea.run_id }}/artifacts?api-version=6.0-preview&artifactName=${{ inputs.name }}" + cat resp2.json + rm resp1.json resp2.json + done + rm resp0.json