name: 'Gitea Release Bash' description: 'Create release and upload asset using curl' inputs: token: description: 'Gitea Token' required: true files: description: 'File path(s) to upload: glob (e.g. dist/*.whl) or whitespace-separated paths/patterns' required: true tag: description: 'Tag name' required: false default: ${{ gitea.ref_name }} runs: using: "composite" steps: - name: Run Release Script shell: bash env: GITEA_TOKEN: ${{ inputs.token }} 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. Создаем релиз HTTP_STATUS=$(curl -s -o release_resp.json -w "%{http_code}" -X 'POST' \ "$API_URL" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"$TAG_NAME\",\"name\":\"Release $TAG_NAME\",\"target_commitish\":\"${{ gitea.sha }}\"}") # 2. Ищем ID (если 201 — новый, если 409 — берем существующий) RELEASE_ID=$(jq '.id' release_resp.json) if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then RELEASE_ID=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API_URL" | \ jq ".[] | select(.tag_name==\"$TAG_NAME\") | .id") fi if [ "$RELEASE_ID" == "null" ] || [ -z "$RELEASE_ID" ]; then echo "Error: Could not find or create release ID" exit 1 fi # 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_FILES[@]} -eq 0 ]; then echo "Error: No files matched: $FILES_SPEC" exit 1 fi # 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