first commit

This commit is contained in:
ange 2025-01-02 03:26:57 +00:00
commit bca0ff6db5
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
3 changed files with 50 additions and 0 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
# upload-artifact@v1

21
action.yaml Normal file
View File

@ -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

28
entrypoint.sh Executable file
View File

@ -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