LD-Uninstaller/release.ps1

312 lines
12 KiB
PowerShell

param(
[ValidateSet("major", "minor", "patch", "current")]
[string]$Type = "current",
[string]$Message = ""
)
$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
if (-not $root) { $root = (Get-Location).Path }
$versionFile = Join-Path $root "version.json"
$propsFile = Join-Path $root "Directory.Build.props"
if (-not (Test-Path $versionFile)) {
@{ major = 2; minor = 5; patch = 0; version = "2.5.0" } | ConvertTo-Json | Set-Content $versionFile
}
$vData = Get-Content $versionFile -Raw | ConvertFrom-Json
$major = [int]$vData.major
$minor = [int]$vData.minor
$patch = [int]$vData.patch
switch ($Type.ToLowerInvariant()) {
"major" {
$major += 1
$minor = 0
$patch = 0
}
"minor" {
$minor += 1
$patch = 0
}
"patch" {
$patch += 1
}
"current" {
# Keep existing version
}
}
$newVersion = "$major.$minor.$patch"
$vData.major = $major
$vData.minor = $minor
$vData.patch = $patch
$vData.version = $newVersion
$vData | ConvertTo-Json | Set-Content $versionFile -Encoding UTF8
# Update Directory.Build.props
$propsContent = @"
<Project>
<PropertyGroup>
<Version>$newVersion</Version>
<AssemblyVersion>$newVersion.0</AssemblyVersion>
<FileVersion>$newVersion.0</FileVersion>
<Product>LD Uninstaller</Product>
<Company>LD Software</Company>
<Authors>LD Software</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
</Project>
"@
Set-Content -Path $propsFile -Value $propsContent -Encoding UTF8
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host " LD UNINSTALLER SURUM YAYINLAMA: v$newVersion" -ForegroundColor Yellow
Write-Host "==========================================" -ForegroundColor Cyan
# 1. Ana klasorde eski surumleri temizle
$oldFolders = Get-ChildItem -Path $root -Directory -Filter "LD Uninstaller v*"
foreach ($old in $oldFolders) {
Write-Host "Eski surum klasoru temizleniyor: $($old.Name)..." -ForegroundColor Gray
try {
Remove-Item -Path $old.FullName -Recurse -Force -ErrorAction SilentlyContinue
} catch { }
}
# Eski kurulum exe ve zip dosyalarini temizle
Get-ChildItem -Path $root -File -Filter "LD-Uninstaller-Setup-v*.exe" | Remove-Item -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path $root -File -Filter "LD-Uninstaller-v*.zip" | Remove-Item -Force -ErrorAction SilentlyContinue
$targetFolderName = "LD Uninstaller v$newVersion"
$targetDir = Join-Path $root $targetFolderName
Write-Host "Yeni surum klasoru olusturuluyor: $targetFolderName..." -ForegroundColor Green
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
# 2. Projeleri Release modunda derle ve yayinla
Write-Host "Projeler derleniyor ve yayinlaniyor..." -ForegroundColor Cyan
$projects = @(
"src/LDUninstaller.UI/LDUninstaller.UI.csproj",
"src/LDUninstaller.CLI/LDUninstaller.CLI.csproj",
"src/LDUninstaller.Automatizer/LDUninstaller.Automatizer.csproj",
"src/LDUninstaller.Launcher/LDUninstaller.Launcher.csproj"
)
foreach ($proj in $projects) {
$projPath = Join-Path $root $proj
Write-Host " -> Yayinlaniyor: $proj" -ForegroundColor Gray
dotnet publish $projPath -c Release -o $targetDir --nologo -v q
}
# 3. Gereksiz pdb ve log dosyalarini temizle
Get-ChildItem -Path $targetDir -Filter "*.pdb" | Remove-Item -Force -ErrorAction SilentlyContinue
# 4. Eski publish ve dist klasorlerini de temizle
try { Remove-Item -Path (Join-Path $root "publish") -Recurse -Force -ErrorAction SilentlyContinue } catch { }
try { Remove-Item -Path (Join-Path $root "dist") -Recurse -Force -ErrorAction SilentlyContinue } catch { }
# 5. Windows Kurulum Sihirbazi (Setup.exe) ve ZIP Arsivini Olustur
Copy-Item (Join-Path $root "app.ico") (Join-Path $targetDir "app.ico") -Force
# Inno Setup ile Setup.exe derle
$isccCandidates = @(
"C:\Users\lildosto\AppData\Local\Programs\Inno Setup 6\ISCC.exe",
"C:\Program Files (x86)\Inno Setup 6\ISCC.exe",
"C:\Program Files\Inno Setup 6\ISCC.exe"
)
$isccPath = $null
foreach ($cand in $isccCandidates) {
if (Test-Path $cand) { $isccPath = $cand; break }
}
$setupName = "LD-Uninstaller-Setup-v$newVersion.exe"
$setupPath = Join-Path $root $setupName
if ($isccPath -and (Test-Path (Join-Path $root "installer.iss"))) {
Write-Host "Windows Kurulum Sihirbazi derleniyor: $setupName..." -ForegroundColor Cyan
& $isccPath /Q "/DMyAppVersion=$newVersion" "/DSourceDir=$targetDir" (Join-Path $root "installer.iss")
if (Test-Path $setupPath) {
Write-Host "Kurulum dosyasi basariyla olusturuldu: $setupName" -ForegroundColor Green
}
}
# Portable ZIP arsivi
$zipName = "LD-Uninstaller-v$newVersion.zip"
$zipPath = Join-Path $root $zipName
Write-Host "Surum zip arsivi olusturuluyor: $zipName..." -ForegroundColor Cyan
Compress-Archive -Path "$targetDir\*" -DestinationPath $zipPath -Force
# 6. Git Islemleri ve GitHub Push
if (Test-Path (Join-Path $root ".git")) {
Write-Host "`nGit degisiklikleri isleniyor ve GitHub'a aktariliyor..." -ForegroundColor Cyan
try {
if ([string]::IsNullOrWhiteSpace($Message)) {
$Message = "Release v${newVersion}: Standart Windows Kurulum Sihirbazi ve Otomasyon"
}
git add .
git commit -m $Message
git tag -a "v$newVersion" -m "LD Uninstaller v$newVersion - $Message" -f
$remote = git remote get-url origin 2>$null
if ($remote) {
Write-Host "GitHub'a gonderiliyor (origin master --tags)..." -ForegroundColor Yellow
git push origin master --tags -u -f
}
} catch {
Write-Host "Git islemi uyarisi: $_" -ForegroundColor Yellow
}
}
# 7. GitHub Releases API Uzerinde Surum ve Notlari Yayinla
try {
Write-Host "`nGitHub Releases API uzerinden surum ve notlar yayinlaniyor..." -ForegroundColor Cyan
$code = @"
using System;
using System.Runtime.InteropServices;
using System.Text;
public class GitCredsEngine2
{
[DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CredRead(string target, int type, int reservedFlag, out IntPtr credentialPtr);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CREDENTIAL
{
public int Flags;
public int Type;
public string TargetName;
public string Comment;
public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;
public int CredentialBlobSize;
public IntPtr CredentialBlob;
public int Persist;
public int AttributeCount;
public IntPtr Attributes;
public string TargetAlias;
public string UserName;
}
public static string GetToken()
{
IntPtr credPtr;
if (CredRead("git:https://github.com", 1, 0, out credPtr))
{
var cred = (CREDENTIAL)Marshal.PtrToStructure(credPtr, typeof(CREDENTIAL));
byte[] bytes = new byte[cred.CredentialBlobSize];
Marshal.Copy(cred.CredentialBlob, bytes, 0, cred.CredentialBlobSize);
return Encoding.Unicode.GetString(bytes).Trim('\0', ' ', '\r', '\n');
}
return null;
}
}
"@
if (-not ([System.Management.Automation.PSTypeName]'GitCredsEngine2').Type) {
Add-Type -TypeDefinition $code -Language CSharp
}
$token = [GitCredsEngine2]::GetToken()
if ($env:GITHUB_TOKEN) { $token = $env:GITHUB_TOKEN }
if ($env:GH_TOKEN) { $token = $env:GH_TOKEN }
if (-not $token) {
Write-Host "Uyari: GitHub kimlik belirteci bulunamadi. Release API atlaniyor." -ForegroundColor Yellow
} else {
$apiHeaders = @{
"Authorization" = "Bearer $token"
"User-Agent" = "LDUninstaller-ReleaseScript"
"Accept" = "application/vnd.github+json"
}
$repoOwner = "LilDosto"
$repoName = "LD-Unistaller"
# Changelog / Surum Notlari (Sablon dosyasindan UTF-8 olarak okunur)
$templatePath = Join-Path $root "release_notes_template.md"
$releaseNotes = ""
if (Test-Path $templatePath) {
$releaseNotes = [System.IO.File]::ReadAllText($templatePath, [System.Text.Encoding]::UTF8)
$releaseNotes = $releaseNotes.Replace("{VERSION}", $newVersion)
} else {
$releaseNotes = "LD Uninstaller v$newVersion guncellemesi."
}
$releaseTitle = if (![string]::IsNullOrWhiteSpace($Message)) { $Message } else { "LDUninstaller-v$newVersion - Setup" }
$releasePayload = @{
tag_name = "v$newVersion"
name = $releaseTitle
body = $releaseNotes
draft = $false
prerelease = $false
} | ConvertTo-Json -Depth 5
$jsonBytes = [System.Text.Encoding]::UTF8.GetBytes($releasePayload)
$releaseUrl = "https://api.github.com/repos/$repoOwner/$repoName/releases/tags/v$newVersion"
$ghRelease = $null
try {
$ghRelease = Invoke-RestMethod -Uri $releaseUrl -Headers $apiHeaders -Method Get -ErrorAction Stop
} catch { }
if ($ghRelease) {
Write-Host "Mevcut release guncelleniyor (ID: $($ghRelease.id))..." -ForegroundColor Yellow
$patchUrl = "https://api.github.com/repos/$repoOwner/$repoName/releases/$($ghRelease.id)"
$ghRelease = Invoke-RestMethod -Uri $patchUrl -Headers $apiHeaders -Method Patch -Body $jsonBytes -ContentType "application/json; charset=utf-8"
} else {
Write-Host "Yeni release olusturuluyor..." -ForegroundColor Green
$postUrl = "https://api.github.com/repos/$repoOwner/$repoName/releases"
$ghRelease = Invoke-RestMethod -Uri $postUrl -Headers $apiHeaders -Method Post -Body $jsonBytes -ContentType "application/json; charset=utf-8"
}
# Dosyalari release asset olarak yukle (Setup.exe ve zip)
$filesToUpload = @($setupPath, $zipPath) | Where-Object { Test-Path $_ }
foreach ($fPath in $filesToUpload) {
$fName = Split-Path $fPath -Leaf
Write-Host "Release varligi yukleniyor: $fName..." -ForegroundColor Cyan
if ($ghRelease.assets) {
foreach ($asset in $ghRelease.assets) {
if ($asset.name -eq $fName) {
try {
Invoke-RestMethod -Uri "https://api.github.com/repos/$repoOwner/$repoName/releases/assets/$($asset.id)" -Headers $apiHeaders -Method Delete | Out-Null
} catch { }
}
}
}
$uploadUri = $ghRelease.upload_url -replace '\{\?name,label\}', "?name=$fName"
$contentType = if ($fName.EndsWith(".exe")) { "application/vnd.microsoft.portable-executable" } else { "application/zip" }
$uploadHeaders = @{
"Authorization" = "Bearer $token"
"User-Agent" = "LDUninstaller-ReleaseScript"
"Accept" = "application/vnd.github+json"
}
$fileBytes = [System.IO.File]::ReadAllBytes($fPath)
$uploadResult = Invoke-RestMethod -Uri $uploadUri -Headers $uploadHeaders -Method Post -Body $fileBytes -ContentType $contentType
Write-Host "Yuklendi: $($uploadResult.browser_download_url)" -ForegroundColor Green
}
Write-Host "`nGitHub Release yayinda:" -ForegroundColor Yellow
Write-Host " -> https://github.com/$repoOwner/$repoName/releases/tag/v$newVersion" -ForegroundColor White
}
} catch {
Write-Host "GitHub Releases API islemi uyarisi: $_" -ForegroundColor Yellow
}
Write-Host "`n[+] Basariyla Tamamlandi!" -ForegroundColor Green
Write-Host "Ana dizinde olusturulan son guncel surum klasoru:" -ForegroundColor Yellow
Write-Host " -> $targetFolderName" -ForegroundColor White
Write-Host "Standart Kurulum Paketi (Setup.exe):" -ForegroundColor Cyan
Write-Host " -> $setupName" -ForegroundColor White
Write-Host "GitHub Release hazir paketi:" -ForegroundColor White
Write-Host " -> $zipName" -ForegroundColor Cyan
Write-Host "Kullanima hazir yurutulebilir dosyalar:" -ForegroundColor Gray
Write-Host " - LDUninstaller.Launcher.exe (Yonetici yetkili baslatici)"
Write-Host " - LDUninstaller.UI.exe (Modern Fluent Arayuz)"
Write-Host " - LDUninstaller.CLI.exe (Konsol araci)"
Write-Host " - LDUninstaller.Automatizer.exe (Otomasyon ajani)`n"