sozsoft-platform/ui/scripts/generate-version.sh
2026-08-12 22:08:14 +03:00

50 lines
1.9 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
# public/version.json üretir (deploy öncesi, HOST üzerinde).
#
# Asıl uygulama scripts/generate-version.js dosyasıdır; node varsa o çalışır.
# Aşağıdaki bash karşılığı yalnızca node bulunmayan sunucular içindir ve
# js sürümüyle aynı çıktıyı üretmelidir.
cd "$(dirname "$0")/.."
echo "> version.json oluşturuluyor..."
if command -v node >/dev/null 2>&1; then
node scripts/generate-version.js
exit 0
fi
# origin'de olmayan yerel tag'ler sürüm numarasını bozar; temizle.
git fetch --prune --prune-tags --tags origin >/dev/null 2>&1 || true
# Sürüm sırası tag adına göre (creatordate değil); 1.1.10 > 1.1.09.
VERSIONS=$(git tag --sort=-v:refname)
ROOT_COMMIT=$(git rev-parse --short HEAD)
BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
BUILD_DATE=$(date -u +%Y-%m-%d)
# Her deploy'da değişir; uygulamanın yeni sürüm algılaması buna bakar.
BUILD_ID="${ROOT_COMMIT}.$(date -u +%s)"
RELEASES=""
FIRST=true
for TAG in $VERSIONS; do
VER=$(echo "$TAG" | sed 's/^v//')
DATE=$(git log -1 --format=%ad --date=short "$TAG")
COMMIT=$(git rev-list -n 1 "$TAG")
MESSAGE=$(git tag -l --format="%(contents)" "$TAG" | grep -v '^$' | sed 's/^[[:space:]]*-[[:space:]]*//' | jq -R . | jq -s .)
if [ "$FIRST" = true ]; then FIRST=false; else RELEASES+=","; fi
RELEASES+="{\"version\":\"$VER\",\"buildDate\":\"$DATE\",\"commit\":\"$COMMIT\",\"changeLog\":$MESSAGE}"
done
# Sürüm = en son tag. Tag'siz commit'ler için sahte sürüm üretilmez; deploy
# algılaması sürüm numarasına değil, her derlemede değişen buildId'ye bakar.
LAST_TAG=$(echo "$VERSIONS" | head -n1 | sed 's/^v//')
VERSION=${LAST_TAG:-$(jq -r .version package.json)}
printf '{"buildId":"%s","buildTime":"%s","buildDate":"%s","commit":"%s","version":"%s","releases":[%s]}' \
"$BUILD_ID" "$BUILD_TIME" "$BUILD_DATE" "$ROOT_COMMIT" "$VERSION" "$RELEASES" | jq . > public/version.json
echo "> version.json: v${VERSION} (${BUILD_ID})"