58 lines
2.0 KiB
YAML
58 lines
2.0 KiB
YAML
name: 'Gitea Release Bash'
|
|
description: 'Create release and upload asset using curl'
|
|
inputs:
|
|
token:
|
|
description: 'Gitea Token'
|
|
required: true
|
|
files:
|
|
description: 'Path to the file to upload'
|
|
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 }}
|
|
FILE_PATH: ${{ inputs.files }}
|
|
TAG_NAME: ${{ inputs.tag }}
|
|
run: |
|
|
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. Загружаем файл
|
|
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")
|
|
|
|
if [ "$UPLOAD_STATUS" != "201" ]; then
|
|
echo "Upload failed with status $UPLOAD_STATUS"
|
|
cat upload_resp.json
|
|
exit 1
|
|
fi
|
|
echo "Successfully uploaded $FILE_PATH to release $TAG_NAME" |