Files
Leonid PershinandClaude Opus 5 99724e7791
build / build (push) Successful in 18s
docs: реальные адреса вместо gitea.example.com
origin — gitea.hsrv.site/mrleo1nid/ipcheck-domains, он и проставлен в README
и в BASE_URL по умолчанию внутри update-geosite.sh. Раз дефолты теперь верные,
примеры cron и ручного запуска сократились до одного RESTART_CMD.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 14:26:20 +03:00

51 lines
2.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Создаёт (или обновляет) релиз в Gitea и заливает в него файлы.
#
# GITEA_URL=https://gitea.hsrv.site GITEA_REPO=mrleo1nid/ipcheck-domains GITEA_TOKEN=… \
# ./tools/gitea-release.sh <тег> <файл-с-описанием> <файл> [файл …]
#
# Имя ассета — путь относительно dist/ с заменой "/" на "-", чтобы
# sing-box/ipcheck.json и json/ipcheck.json не конфликтовали.
set -eu
[ $# -ge 3 ] || { echo "использование: $0 <тег> <notes.md> <файл...>" >&2; exit 1; }
TAG="$1"; NOTES="$2"; shift 2
: "${GITEA_URL:?не задан GITEA_URL}"
: "${GITEA_REPO:?не задан GITEA_REPO}"
: "${GITEA_TOKEN:?не задан GITEA_TOKEN}"
API="$GITEA_URL/api/v1/repos/$GITEA_REPO/releases"
auth="Authorization: token $GITEA_TOKEN"
json_field() { python3 -c 'import json,sys; print(json.load(sys.stdin).get(sys.argv[1],""))' "$1"; }
payload=$(NOTES_FILE="$NOTES" TAG="$TAG" python3 -c '
import json, os
print(json.dumps({
"tag_name": os.environ["TAG"],
"name": os.environ["TAG"],
"body": open(os.environ["NOTES_FILE"], encoding="utf-8").read(),
"draft": False,
"prerelease": False,
}))')
# Релиз с таким тегом мог остаться от прошлого прогона — тогда переиспользуем его.
id=$(curl -fsS -X POST "$API" -H "$auth" -H 'Content-Type: application/json' \
-d "$payload" 2>/dev/null | json_field id || true)
if [ -z "$id" ]; then
id=$(curl -fsS "$API/tags/$TAG" -H "$auth" | json_field id) ||
{ echo "не удалось ни создать, ни найти релиз $TAG" >&2; exit 1; }
echo "релиз $TAG уже существует (id $id), дозаливаем ассеты"
fi
echo "релиз $TAG: id $id"
for file in "$@"; do
[ -f "$file" ] || { echo "нет файла: $file" >&2; exit 1; }
name=$(printf '%s' "${file#dist/}" | tr '/' '-')
curl -fsS -X POST "$API/$id/assets?name=$name" -H "$auth" \
-F "attachment=@$file" >/dev/null
echo " + $name"
done