multiple files support
This commit is contained in:
43
action.yml
43
action.yml
@@ -5,7 +5,7 @@ inputs:
|
||||
description: 'Gitea Token'
|
||||
required: true
|
||||
files:
|
||||
description: 'Path to the file to upload'
|
||||
description: 'File path(s) to upload: glob (e.g. dist/*.whl) or whitespace-separated paths/patterns'
|
||||
required: true
|
||||
tag:
|
||||
description: 'Tag name'
|
||||
@@ -19,9 +19,12 @@ runs:
|
||||
shell: bash
|
||||
env:
|
||||
GITEA_TOKEN: ${{ inputs.token }}
|
||||
FILE_PATH: ${{ inputs.files }}
|
||||
FILES_SPEC: ${{ inputs.files }}
|
||||
TAG_NAME: ${{ inputs.tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
API_URL="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"
|
||||
|
||||
# 1. Создаем релиз
|
||||
@@ -43,16 +46,32 @@ runs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. Загружаем файл
|
||||
UPLOAD_STATUS=$(curl -s -o upload_resp.json -w "%{http_code}" -X 'POST' \
|
||||
"$API_URL/$RELEASE_ID/assets" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-F "attachment=@$FILE_PATH")
|
||||
# 3. Собираем список файлов (glob и несколько паттернов через пробел)
|
||||
UPLOAD_FILES=()
|
||||
for arg in $FILES_SPEC; do
|
||||
for f in $arg; do
|
||||
[ -f "$f" ] && UPLOAD_FILES+=("$f")
|
||||
done
|
||||
done
|
||||
readarray -t UPLOAD_FILES < <(printf '%s\n' "${UPLOAD_FILES[@]}" | sort -u)
|
||||
|
||||
if [ "$UPLOAD_STATUS" != "201" ]; then
|
||||
echo "Upload failed with status $UPLOAD_STATUS"
|
||||
cat upload_resp.json
|
||||
if [ ${#UPLOAD_FILES[@]} -eq 0 ]; then
|
||||
echo "Error: No files matched: $FILES_SPEC"
|
||||
exit 1
|
||||
fi
|
||||
echo "Successfully uploaded $FILE_PATH to release $TAG_NAME"
|
||||
|
||||
# 4. Загружаем каждый файл
|
||||
for asset in "${UPLOAD_FILES[@]}"; do
|
||||
UPLOAD_STATUS=$(curl -s -o upload_resp.json -w "%{http_code}" -X 'POST' \
|
||||
"$API_URL/$RELEASE_ID/assets" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-F "attachment=@${asset}")
|
||||
|
||||
if [ "$UPLOAD_STATUS" != "201" ]; then
|
||||
echo "Upload failed for $asset with status $UPLOAD_STATUS"
|
||||
cat upload_resp.json
|
||||
exit 1
|
||||
fi
|
||||
echo "Successfully uploaded $asset to release $TAG_NAME"
|
||||
done
|
||||
Reference in New Issue
Block a user