158 lines
4.1 KiB
PowerShell
158 lines
4.1 KiB
PowerShell
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
$rootDir = Join-Path $scriptDir ".."
|
|
$releaseScript = Join-Path $scriptDir "release.ps1"
|
|
$packageJsonPath = Join-Path $rootDir "package.json"
|
|
|
|
# Path to BUILD_NUMBER file, assuming root is one level up from scripts
|
|
$buildNumberFile = Join-Path $scriptDir "..\BUILD_NUMBER"
|
|
$envFile = Join-Path $rootDir ".env"
|
|
|
|
if (Test-Path $envFile) {
|
|
Write-Host "Loading environment variables from $envFile"
|
|
Get-Content $envFile | ForEach-Object {
|
|
if ($_ -match "^\s*([^#][^=]*)=(.*)$") {
|
|
$name = $matches[1].Trim()
|
|
$value = $matches[2].Trim()
|
|
[System.Environment]::SetEnvironmentVariable($name, $value)
|
|
}
|
|
}
|
|
} else {
|
|
Write-Host ".env file not found at $envFile"
|
|
}
|
|
|
|
if (-not $env:BUILD_NAME) {
|
|
Write-Warning "BUILD_NAME environment variable is not set. Please make sure you have entered the correct info the env"
|
|
exit 1
|
|
}
|
|
|
|
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 (-not (Test-Path $buildNumberFile)) {
|
|
$initialBuildValue = "1-$($env:BUILD_NAME)"
|
|
Write-Host "BUILD_NUMBER file not found. Creating with value: $initialBuildValue"
|
|
Set-Content -Path $buildNumberFile -Value $initialBuildValue
|
|
} else {
|
|
Write-Host "BUILD_NUMBER file exists at $buildNumberFile, and will not be created"
|
|
}
|
|
|
|
function Update-BuildNumber {
|
|
if (-not (Test-Path $buildNumberFile)) {
|
|
Write-Warning "BUILD_NUMBER file not found at $buildNumberFile"
|
|
return $null
|
|
}
|
|
|
|
$current = Get-Content $buildNumberFile -Raw
|
|
$current = $current.Trim()
|
|
|
|
if ($current -match '^(\d+)-(.*)$') {
|
|
$number = [int]$matches[1]
|
|
$name = $matches[2]
|
|
|
|
$newNumber = $number + 1
|
|
$newBuildNumber = "$newNumber-$name"
|
|
|
|
Set-Content -Path $buildNumberFile -Value $newBuildNumber
|
|
|
|
Write-Host "Build number updated from $current to $newBuildNumber"
|
|
|
|
return $newBuildNumber
|
|
} else {
|
|
Write-Warning "BUILD_NUMBER file content '$current' is not in the expected 'number-name' format."
|
|
return $null
|
|
}
|
|
}
|
|
|
|
|
|
Push-Location $rootDir/backend
|
|
Write-Host "Building the app"
|
|
go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_backend.exe ./main.go
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Warning "Backend build failed!"
|
|
Pop-Location
|
|
break
|
|
}
|
|
|
|
Write-Host "Backend build finished successfully."
|
|
|
|
Pop-Location
|
|
|
|
Push-Location $rootDir/frontend
|
|
Write-Host "Building the frontend."
|
|
npm run build
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Warning "Fronend build failed!"
|
|
Pop-Location
|
|
break
|
|
}
|
|
|
|
Write-Host "Fronend build finished successfully."
|
|
Pop-Location
|
|
|
|
Write-Host "Building wrapper"
|
|
Push-Location $rootDir/LstWrapper
|
|
dotnet publish -c Release -o ./publish
|
|
|
|
Pop-Location
|
|
|
|
try {
|
|
Update-BuildNumber
|
|
|
|
Write-Host "Zipping up the release"
|
|
npm run createZip
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to create release zip"
|
|
}
|
|
|
|
$choice = Read-Host "Are we going to create a release? y/N"
|
|
if ($choice -eq "y" -or $choice -eq "Y") {
|
|
Write-Host "Creating release..."
|
|
|
|
# This will:
|
|
# 1. Update version in package.json
|
|
# 2. Generate changelog
|
|
# 3. Create git tag
|
|
# 4. Push to remote
|
|
# 5. Create Gitea release via our script
|
|
|
|
npm run release
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to create Gitea release"
|
|
}
|
|
|
|
}
|
|
} catch {
|
|
Write-Warning "Release process failed: $_"
|
|
exit 1
|
|
}
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|