diff --git a/B4A/_git_tag.ps1 b/B4A/_git_tag.ps1 index 89e7105..95c3a75 100644 --- a/B4A/_git_tag.ps1 +++ b/B4A/_git_tag.ps1 @@ -1,110 +1,126 @@ -# --- SCRIPT DE AUTODESCUBRIMIENTO CON GUI MEJORADA --- +# --- SCRIPT DE COMMIT Y TAG (MODO IDE B4A) --- -# Cargar librería visual +# 0. CONFIGURACIÓN +$HacerPush = $false # Cambia a $true para que suba los cambios a GitHub + +# Cargar librería visual para el MessageBox (por si se necesita en el Push) Add-Type -AssemblyName System.Windows.Forms -Add-Type -AssemblyName System.Drawing # 1. AUTODESCUBRIMIENTO $projectPath = $PSScriptRoot -Write-Host "Ruta: $projectPath" +Write-Host "Ruta del proyecto: $projectPath" $b4aFileItem = Get-ChildItem -Path $projectPath -Filter "*.b4a" | Select-Object -First 1 if (-Not $b4aFileItem) { - [System.Windows.Forms.MessageBox]::Show("No hay archivo .b4a en esta carpeta.", "Error", "OK", "Error") + Write-Host "ERROR: No hay archivo .b4a en esta carpeta." return } -$b4aFile = $b4aFileItem.FullName $projectName = $b4aFileItem.BaseName -Write-Host "Proyecto: $projectName" +Write-Host "Proyecto detectado: $projectName" -# 2. LIMPIEZA -# $objectsPath = Join-Path $projectPath "Objects" -# if (Test-Path $objectsPath) { - # Write-Host "Limpiando Objects..." - # Remove-Item -Path "$objectsPath\*" -Recurse -Force -ErrorAction SilentlyContinue -# } - -# 3. LEER VERSIÓN -$versionLine = Get-Content $b4aFile | Select-String "#VersionName:" -if (-Not $versionLine) { Write-Error "Falta #VersionName"; return } +# 2. LEER VERSIÓN +$versionLine = Get-Content $b4aFileItem.FullName | Select-String "#VersionName:" +if (-Not $versionLine) { + Write-Host "ERROR: Falta #VersionName en el archivo .b4a" + return +} $version = ($versionLine -split ":")[1].Trim() $tagName = "v$version" Set-Location $projectPath -# 4. COMMIT -$oldCommit = git rev-parse HEAD +# 3. COMMIT CON TORTOISEGIT +$oldCommit = git rev-parse HEAD 2>$null Write-Host "----------------------------------------" -Write-Host "Versión: $version" -Write-Host "Abriendo TortoiseGit..." +Write-Host "Version a etiquetar: $version" +Write-Host "Abriendo ventana de TortoiseGit..." -# Argumentos limpios $pathArg = '/path:"{0}"' -f $projectPath $msgArg = '/logmsg:"VERSION {0}"' -f $version $cmdArg = "/command:commit" -$process = Start-Process "TortoiseGitProc.exe" -ArgumentList $cmdArg, $pathArg, $msgArg -Wait -PassThru +Start-Process "TortoiseGitProc.exe" -ArgumentList $cmdArg, $pathArg, $msgArg -$newCommit = git rev-parse HEAD +Write-Host "Esperando a que termines el commit en TortoiseGit..." +# El freno de mano: espera a que cierres la ventana +while (Get-Process "TortoiseGitProc" -ErrorAction SilentlyContinue) { + Start-Sleep -Seconds 1 +} -# 5. VALIDACIÓN +$newCommit = git rev-parse HEAD 2>$null + +# 4. VALIDACIÓN if ($oldCommit -eq $newCommit) { - Write-Warning "Commit cancelado." - git tag -d $tagName 2>$null # Borra tag local previo si existe para actualizarlo al nuevo commit + Write-Host "WARNING: Commit cancelado o sin cambios detectados." return } -Write-Host ">> Commit detectado." +Write-Host "Commit registrado exitosamente: $newCommit" -# 6. GESTIÓN DE TAGS (VISUAL TOPMOST) -Write-Host "git ls-remote --tags origin $tagName" -$remoteTagInfo = git ls-remote --tags origin $tagName +# 5. GESTIÓN DE TAGS +$tagGenerado = $false -if ($remoteTagInfo) { - # --- TRUCO PARA QUE LA VENTANA SALGA AL FRENTE --- - # Creamos un formulario invisible que esté "Siempre Visible" (TopMost) - Write-Host "Recibimos remoteTagInfo" - $topForm = New-Object System.Windows.Forms.Form - $topForm.TopMost = $true - $topForm.Opacity = 0 # Invisible - $topForm.ShowInTaskbar = $false - $topForm.StartPosition = "CenterScreen" - $topForm.Show() - $topForm.Activate() - - [System.Console]::Beep(1000, 200) - [System.Console]::Beep(1000, 200) - - $msgBody = "El tag '$tagName' YA EXISTE en GitHub.`n`nDeseas SOBRESCRIBIRLO?`n`nSi = Borrar anterior y actualizar (Force Push).`nNo = Subir solo codigo (mantener tag viejo)." - $msgTitle = "⚠️ Conflicto de Versiones - $projectName" - - # El mensaje ahora es "hijo" del formulario invisible, heredando su propiedad TopMost - Write-Host "Preguntamos que hacer con el tag" - $respuesta = [System.Windows.Forms.MessageBox]::Show($topForm, $msgBody, $msgTitle, "YesNo", "Warning") - - $topForm.Dispose() # Limpiamos el formulario invisible - - if ($respuesta -eq "Yes") { - Write-Host "Sobrescribiendo..." - git tag -d $tagName 2>$null - git tag -a $tagName -m "Release version $version (Updated)" - - git push origin - git push origin $tagName --force - Write-Host ">> Tag actualizado (Force Push)." - } else { - Write-Host "Conservando tag anterior..." - git push origin - Write-Host ">> Código subido." - } -} else { - # Tag Nuevo - git tag -a $tagName -m "Release version $version" - git push origin --follow-tags - Write-Host ">> Versión publicada." +# Revisamos si el tag ya existe localmente y lo borramos para recrearlo con el nuevo commit +if (git tag -l $tagName) { + git tag -d $tagName 2>$null | Out-Null } -Write-Host "----------------------------------------" \ No newline at end of file +# Creamos el tag nuevo apuntando al commit que acabamos de hacer +git tag -a $tagName -m "Release version $version" +if ($?) { $tagGenerado = $true } + +# 6. LÓGICA DE PUSH +if ($HacerPush) { + Write-Host "Conectando con GitHub..." + $remoteTagInfo = git ls-remote --tags origin $tagName + + if ($remoteTagInfo) { + # Conflicto: Ya existe en remoto + $topForm = New-Object System.Windows.Forms.Form + $topForm.TopMost = $true + $topForm.Opacity = 0 + $topForm.ShowInTaskbar = $false + $topForm.StartPosition = "CenterScreen" + $topForm.Show() + $topForm.Activate() + + [System.Console]::Beep(1000, 200) + + $msgBody = "El tag '$tagName' YA EXISTE en GitHub.`n`nDeseas SOBRESCRIBIRLO?`n`nSi = Borrar anterior y actualizar (Force Push).`nNo = Subir solo codigo (mantener tag viejo)." + $msgTitle = "Conflicto de Versiones - $projectName" + + $respuesta = [System.Windows.Forms.MessageBox]::Show($topForm, $msgBody, $msgTitle, "YesNo", "Warning") + $topForm.Dispose() + + if ($respuesta -eq "Yes") { + Write-Host "Sobrescribiendo tag en GitHub (Force Push)..." + git push origin + git push origin $tagName --force + } else { + Write-Host "Conservando tag anterior en GitHub..." + git push origin + } + } else { + # Tag Nuevo + Write-Host "Subiendo codigo y tag nuevo a GitHub..." + git push origin --follow-tags + } +} else { + Write-Host "Push OMITIDO (Switch de control apagado)." +} + +# 7. REPORTE FINAL PARA EL IDE +$EstadoPush = if($HacerPush) { "SI" } else { "NO (Modo de prueba local)" } +$EstadoTag = if($tagGenerado) { "SI ($tagName)" } else { "NO (Error al generar)" } + +Write-Host "" +Write-Host "========================================" +Write-Host " REPORTE DE VERSION " +Write-Host "========================================" +Write-Host " PROYECTO : $projectName" +Write-Host " TAG CREADO : $EstadoTag" +Write-Host " PUSH GITHUB: $EstadoPush" +Write-Host "========================================" \ No newline at end of file