115 lines
4.5 KiB
Bash
115 lines
4.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
APP="/var/www/dhv2.korexlabs.com"
|
|
KEY="/root/.ssh/dhv2_github"
|
|
DEPLOY_REF="${DHV2_DEPLOY_REF:-deploy}"
|
|
LOG="$(mktemp /tmp/dhv2-android-discovery.XXXXXX.log)"
|
|
STATUS="$(mktemp /tmp/dhv2-android-discovery-status.XXXXXX)"
|
|
|
|
cd "$APP"
|
|
export GIT_SSH_COMMAND="ssh -i $KEY -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new"
|
|
exec > >(tee -a "$LOG") 2>&1
|
|
|
|
publish_status() {
|
|
local rc="${1:-1}"
|
|
set +e
|
|
local outcome="failure"
|
|
[ "$rc" -eq 0 ] && outcome="success"
|
|
local current target status_blob log_blob tree commit
|
|
current="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
|
|
target="$(git rev-parse origin/$DEPLOY_REF 2>/dev/null || echo unknown)"
|
|
{
|
|
echo "status=$outcome"
|
|
echo "exit_code=$rc"
|
|
echo "phase=android-source-discovery"
|
|
echo "timestamp=$(date --iso-8601=seconds)"
|
|
echo "deploy_ref=$DEPLOY_REF"
|
|
echo "target_sha=$target"
|
|
echo "current_sha=$current"
|
|
echo "app_touched=0"
|
|
echo "backup=not-required-read-only"
|
|
} > "$STATUS"
|
|
status_blob="$(git hash-object -w "$STATUS" 2>/dev/null || true)"
|
|
log_blob="$(git hash-object -w "$LOG" 2>/dev/null || true)"
|
|
if [ -n "$status_blob" ] && [ -n "$log_blob" ]; then
|
|
tree="$(printf '100644 blob %s\tdeploy.log\n100644 blob %s\tstatus.txt\n' "$log_blob" "$status_blob" | git mktree 2>/dev/null || true)"
|
|
if [ -n "$tree" ]; then
|
|
commit="$(printf 'deploy-status: %s · android-source-discovery\n' "$outcome" | git -c user.name='DH V2 Deploy Bot' -c user.email='deploy@dhv2.local' commit-tree "$tree" 2>/dev/null || true)"
|
|
[ -z "$commit" ] || git push --force origin "$commit:refs/heads/deploy-status" >/dev/null 2>&1 || true
|
|
fi
|
|
fi
|
|
rm -f "$STATUS" "$LOG"
|
|
}
|
|
trap 'rc=$?; trap - EXIT; publish_status "$rc"; exit "$rc"' EXIT
|
|
|
|
echo "============================================================"
|
|
echo " DH V2 · ANDROID SOURCE DISCOVERY · SOLO LECTURA"
|
|
echo "============================================================"
|
|
|
|
git fetch origin "$DEPLOY_REF"
|
|
TARGET="$(git rev-parse "origin/$DEPLOY_REF")"
|
|
CURRENT="$(git rev-parse HEAD)"
|
|
echo "Current: $CURRENT"
|
|
echo "Target: $TARGET"
|
|
git merge-base --is-ancestor "$CURRENT" "$TARGET"
|
|
|
|
echo
|
|
echo "========== PROYECTOS GRADLE / ANDROID =========="
|
|
for root in /root /var/www /home /tmp; do
|
|
[ -d "$root" ] || continue
|
|
find "$root" -maxdepth 9 -type f \
|
|
\( -name gradlew -o -name settings.gradle -o -name settings.gradle.kts -o -name build.gradle -o -name build.gradle.kts \) \
|
|
-printf '%TY-%Tm-%Td %TH:%TM %10s %p\n' 2>/dev/null || true
|
|
done | sort -r | head -300
|
|
|
|
echo
|
|
echo "========== ZIP / APK / AAB RELACIONADOS =========="
|
|
for root in /root /var/www /home /tmp; do
|
|
[ -d "$root" ] || continue
|
|
find "$root" -maxdepth 10 -type f \
|
|
\( -iname '*android*.zip' -o -iname '*inspeccion*.zip' -o -iname '*dh*.apk' -o -iname '*inspeccion*.apk' -o -iname '*.aab' -o -iname '*E1.1*' -o -iname '*E1_1*' -o -iname '*E1.2*' -o -iname '*E1_2*' -o -iname '*F2.2*' -o -iname '*F2_2*' \) \
|
|
-printf '%TY-%Tm-%Td %TH:%TM %10s %p\n' 2>/dev/null || true
|
|
done | sort -r | head -300
|
|
|
|
echo
|
|
echo "========== VERSIONES ANDROID =========="
|
|
for root in /root /var/www /home /tmp; do
|
|
[ -d "$root" ] || continue
|
|
find "$root" -maxdepth 10 -type f \( -name build.gradle -o -name build.gradle.kts \) -print0 2>/dev/null || true
|
|
done | while IFS= read -r -d '' f; do
|
|
if grep -Eq 'applicationId|versionCode|versionName|namespace' "$f" 2>/dev/null; then
|
|
echo "----- $f -----"
|
|
grep -nE 'applicationId|namespace|versionCode|versionName' "$f" 2>/dev/null | head -30 || true
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "========== GIT REPOS CON GRADLE =========="
|
|
for root in /root /var/www /home /tmp; do
|
|
[ -d "$root" ] || continue
|
|
find "$root" -maxdepth 9 -type d -name .git -print 2>/dev/null || true
|
|
done | while read -r gitdir; do
|
|
dir="${gitdir%/.git}"
|
|
if find "$dir" -maxdepth 3 \( -name gradlew -o -name settings.gradle -o -name settings.gradle.kts \) -print -quit 2>/dev/null | grep -q .; then
|
|
echo "----- $dir -----"
|
|
git -C "$dir" status --short --branch 2>/dev/null || true
|
|
git -C "$dir" log -8 --oneline 2>/dev/null || true
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "========== HUELLA KOTLIN / COMPOSE =========="
|
|
for root in /root /var/www /home /tmp; do
|
|
[ -d "$root" ] || continue
|
|
find "$root" -maxdepth 10 -type f -name '*.kt' -printf '%h\n' 2>/dev/null || true
|
|
done | grep -Ei 'dh|inspe|android|mobile|app' | sort -u | head -300
|
|
|
|
echo
|
|
echo "DISCOVERY_OK"
|
|
|
|
echo
|
|
echo "========== REGISTRAR COMMIT DIAGNÓSTICO =========="
|
|
git merge --ff-only "origin/$DEPLOY_REF"
|
|
echo "Diagnostic commit registrado localmente: $(git rev-parse HEAD)"
|