commit bca0ff6db5f392a035bd136a6ba4feec718589d7 Author: ange Date: Thu Jan 2 03:26:57 2025 +0000 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb10c96 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# upload-artifact@v1 diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..9241f54 --- /dev/null +++ b/action.yaml @@ -0,0 +1,21 @@ +name: Upload a Build Artifact +description: Upload a build artifact that can be used by subsequent workflow steps + +inputs: + name: + description: Artifact name + default: artifact + path: + description: A file, directory or wildcard pattern that describes what to upload + required: true + retention-days: + description: > + Duration after which artifact will expire in days. + Minimum 1 day. + Maximum 90 days unless changed from the repository settings page. + +runs: + using: composite + steps: + - name: Upload + run: ${{ gitea.action_path }}/entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..3abdbe8 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,28 @@ +#!/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