87 lines
3.2 KiB
Bash
87 lines
3.2 KiB
Bash
|
|
#!/bin/bash
|
|||
|
|
set -e
|
|||
|
|
|
|||
|
|
# Sürüm notlarını git tag'lerinden üretir:
|
|||
|
|
# api/src/Sozsoft.Platform.HttpApi.Host/release-notes.json
|
|||
|
|
#
|
|||
|
|
# Bu dosya API imajına gömülür; uygulama açılışında ReleaseNoteStartupService onu
|
|||
|
|
# `Sas_H_ReleaseNote` tablosuna senkronize eder (yeni tag eklenir, mesajı değişen
|
|||
|
|
# tag güncellenir). Yani YENİ SÜRÜM İÇİN DbMigrator ÇALIŞTIRMAK GEREKMEZ; API'yi
|
|||
|
|
# deploy etmek yeterlidir. İstemci sürüm numarasını ve changelog'u
|
|||
|
|
# application-configuration yanıtındaki `extraProperties.changeLogs` alanından okur.
|
|||
|
|
#
|
|||
|
|
# Deploy akışında build/api.sh tarafından otomatik çağrılır; elle de
|
|||
|
|
# çalıştırılabilir. Git deposu gerektiği için imajın içinde değil, imaj
|
|||
|
|
# oluşturulmadan ÖNCE build sunucusunda koşar.
|
|||
|
|
#
|
|||
|
|
# Dış bağımlılığı yoktur (jq/node gerekmez): JSON kaçışları sed ile yapılır.
|
|||
|
|
|
|||
|
|
cd "$(dirname "$0")/.."
|
|||
|
|
OUTPUT="src/Sozsoft.Platform.HttpApi.Host/release-notes.json"
|
|||
|
|
|
|||
|
|
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"
|