sozsoft-platform/api/scripts/generate-release-notes.sh
2026-08-13 00:52:49 +03:00

91 lines
3.4 KiB
Bash
Raw 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/bash
set -e
# Sürüm notlarını git tag'lerinden üretir:
# api/release-notes/release-notes.json
#
# Bu dosya API konteynerine /etc/api/release-notes altına MOUNT edilir (imaja
# GÖMÜLMEZ). Uygulama açılışında ReleaseNoteStartupService onu `Sas_H_ReleaseNote`
# tablosuyla eşitler. Yani yeni bir sürüm tag'i için ne DbMigrator ne de imaj
# derlemesi gerekir; deploy sırasında bu script koşar ve konteyner yeniden
# başlar. İstemci sürüm numarasını ve changelog'u application-configuration
# yanıtındaki `extraProperties.changeLogs` alanından okur.
#
# Kaynak ağacının DIŞINDA bir klasöre yazılmasının sebebi Docker katman cache'i:
# dosya `src/` altında olsaydı Dockerfile'daki `COPY . .` her tag'de geçersizleşip
# tüm `dotnet publish` adımını yeniden çalıştırırdı.
#
# Deploy akışında deploy/app.sh tarafından otomatik çağrılır; elle de
# çalıştırılabilir. Çıktı git'e commit EDİLMEZ (.gitignore).
#
# Dış bağımlılığı yoktur (jq/node gerekmez): JSON kaçışları sed ile yapılır.
cd "$(dirname "$0")/.."
OUTPUT="release-notes/release-notes.json"
mkdir -p "$(dirname "$OUTPUT")"
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "> git deposu yok, ${OUTPUT} güncellenmedi." >&2
exit 0
fi
echo "> release-notes.json oluşturuluyor..."
# origin'de olmayan yerel tag'ler sürüm sırasını bozar; temizle. `--force` şart:
# yerel bir tag origin'dekinden farklı commit'e bakıyorsa git onu "would clobber
# existing tag" diyerek reddediyor ve YENİ tag'ler de alınmamış oluyor.
git fetch --prune --prune-tags --tags --force origin >/dev/null 2>&1 || true
# Sıra tag adına göre (creatordate değil): 1.1.10 > 1.1.09.
TAGS=$(git tag --list --sort=-v:refname)
if [ -z "$TAGS" ]; then
echo "> Tag bulunamadı, mevcut dosya korundu." >&2
exit 0
fi
# JSON string kaçışı: önce ters bölü, sonra tırnak, sonra sekme/CR.
escape_json() {
printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/\t/\\t/g' -e 's/\r//g'
}
TMP=$(mktemp)
printf '{\n "ReleaseNotes": [\n' > "$TMP"
FIRST_TAG=true
for TAG in $TAGS; do
VERSION=${TAG#v}
RELEASE_DATE=$(git log -1 --format=%ad --date=short "$TAG")
COMMIT=$(git rev-list -n 1 "$TAG")
if [ "$FIRST_TAG" = true ]; then FIRST_TAG=false; else printf ',\n' >> "$TMP"; fi
printf ' {\n' >> "$TMP"
printf ' "version": "%s",\n' "$(escape_json "$VERSION")" >> "$TMP"
printf ' "releaseDate": "%s",\n' "$RELEASE_DATE" >> "$TMP"
printf ' "commit": "%s",\n' "$COMMIT" >> "$TMP"
printf ' "notes": [' >> "$TMP"
# Annotated tag mesajı; her satır bir madde. Boş satırlar ve baştaki "-" / "*"
# işaretleri temizlenir. Lightweight tag'de mesaj boştur → notes: [].
FIRST_NOTE=true
while IFS= read -r LINE; do
[ -z "$LINE" ] && continue
if [ "$FIRST_NOTE" = true ]; then FIRST_NOTE=false; printf '\n' >> "$TMP"; else printf ',\n' >> "$TMP"; fi
printf ' "%s"' "$(escape_json "$LINE")" >> "$TMP"
done < <(git tag -l --format='%(contents)' "$TAG" \
| sed -e 's/\r//' -e 's/^[[:space:]]*[-*][[:space:]]*//' -e 's/[[:space:]]*$//' \
| grep -v '^$' || true)
if [ "$FIRST_NOTE" = true ]; then
printf ']\n' >> "$TMP"
else
printf '\n ]\n' >> "$TMP"
fi
printf ' }' >> "$TMP"
done
printf '\n ]\n}\n' >> "$TMP"
mv "$TMP" "$OUTPUT"
echo "> ${OUTPUT}: $(grep -c '"version":' "$OUTPUT") sürüm"