Files
logistics_support_tool/scripts/release.ps1

80 lines
2.2 KiB
PowerShell

$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$rootDir = Join-Path $scriptDir ".."
$packageJsonPath = Join-Path $rootDir "package.json"
$env:GOOS = "windows"
$env:GOARCH = "amd64"
$keepReleases = 10
function Get-PackageVersion {
param (
[string]$packageJsonPath
)
if (-not (Test-Path $packageJsonPath)) {
Write-Warning "package.json not found at $packageJsonPath"
return $null
}
$jsonContent = Get-Content $packageJsonPath -Raw
try {
$json = $jsonContent | ConvertFrom-Json
return $json.version
}
catch {
Write-Warning "Failed to parse package.json: $_"
return $null
}
}
$version = Get-PackageVersion -packageJsonPath $packageJsonPath
Write-Host "Project version from package.json is: $version"
$buildNumberFile = Join-Path $rootDir "BUILD_NUMBER"
if (Test-Path $buildNumberFile) {
$buildNumber = Get-Content $buildNumberFile -Raw
$buildNumber = $buildNumber.Trim()
Write-Host "Current build number: $buildNumber"
} else {
Write-Warning "BUILD_NUMBER file not found at $buildNumberFile"
}
$releaseFolder = Join-Path $rootDir "releases"
$zipName = "release-v$version-$buildNumber.zip"
$zipPath = Join-Path $releaseFolder $zipName
if (-not (Test-Path $releaseFolder)) {
New-Item -ItemType Directory -Path $releaseFolder | Out-Null
}
# Remove zip if it already exists
if (Test-Path $zipPath) {
Write-Host "Removing existing zip: $zipPath"
Remove-Item $zipPath -Force
}
# Clean up older release files (keep only newest X)
$existingZips = Get-ChildItem -Path $releaseFolder -Filter "release-*.zip" | Sort-Object LastWriteTime -Descending
if ($existingZips.Count -gt $keepReleases) {
$toRemove = $existingZips | Select-Object -Skip $keepReleases
foreach ($file in $toRemove) {
Write-Host "Deleting old release: $($file.Name)"
Remove-Item $file.FullName -Force
}
}
Write-Host "`nPackaging release: $($zipName)"
$filesToInclude = @(
"backend\lst_backend.exe",
"frontend\.nitro",
"frontend\.tanstack",
"frontend\.output",
"frontend\public",
"package.json"
)
Compress-Archive -Path $filesToInclude -DestinationPath $zipPath
Write-Host "`nRelease package created at: $($zipPath)"