docker will default to 8080 and can be adjusted via the docker compose, or passing the same env over it will change it as well.
214 lines
5.8 KiB
PowerShell
214 lines
5.8 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"
|
|
|
|
# tmp scripts to get lstv2 into this build and zipped up with everything
|
|
. (Join-Path $PSScriptRoot "lstV2Build.ps1")
|
|
|
|
# will run the lstv2 build first so we know for sure its copied over
|
|
Build-LstV2-And-Copy
|
|
|
|
# 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."
|
|
Set-Content -Path $buildNumberFile -Value "1-"$($env:BUILD_NAME)
|
|
return $null
|
|
}
|
|
}
|
|
|
|
|
|
Push-Location $rootDir/backend
|
|
|
|
Write-Host "Building the app"
|
|
go get
|
|
# swag init -o swagger -g main.go
|
|
go build -ldflags "-X main.version=$($version)-$($initialBuildValue)" -o lst_app.exe ./main.go
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Warning "app build failed!"
|
|
Pop-Location
|
|
break
|
|
}
|
|
|
|
Write-Host "app build finished successfully."
|
|
|
|
Pop-Location
|
|
|
|
Push-Location $rootDir/frontend
|
|
Write-Host "Building the frontend."
|
|
npm i
|
|
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
|
|
|
|
Write-Host "Changing the port to match the server port in the env file"
|
|
$port = $env:VITE_SERVER_PORT
|
|
if (-not $port) {
|
|
$port = "8080" # Default port if env var not set
|
|
}
|
|
|
|
$webConfigPath = "web.config"
|
|
$content = Get-Content -Path $webConfigPath -Raw
|
|
|
|
$newContent = $content -replace '(?<=Rewrite" url="http://localhost:)\d+(?=/\{R:1\}")', $port
|
|
|
|
$newContent | Set-Content -Path $webConfigPath -NoNewline
|
|
|
|
Write-Host "Updated web.config rewrite port to $port"
|
|
|
|
#remove the publish folder as we done need it
|
|
if (-not (Test-Path "publish")) {
|
|
Write-Host "The publish folder is already deleted nothing else to do"
|
|
} else {
|
|
Remove-Item -LiteralPath "publish" -Force -Recurse
|
|
}
|
|
|
|
dotnet publish -c Release -o ./publish
|
|
|
|
$webConfigPath = "web.config"
|
|
$content = Get-Content -Path $webConfigPath -Raw
|
|
|
|
$newContent = $content -replace '(?<=Rewrite" url="http://localhost:)\d+(?=/\{R:1\}")', "8080"
|
|
|
|
$newContent | Set-Content -Path $webConfigPath -NoNewline
|
|
|
|
Write-Host "Updated web.config rewrite port back to 8080"
|
|
|
|
Pop-Location
|
|
|
|
Write-Host "Building Docs"
|
|
Push-Location $rootDir/lst-docs
|
|
npm i
|
|
npm run build
|
|
|
|
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
|
|
|
|
# deleteing the temp folder so we always cleaned up
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Failed to create Gitea release"
|
|
}
|
|
|
|
}
|
|
} catch {
|
|
Write-Warning "Release process failed: $_"
|
|
|
|
# deleteing the temp folder so we always cleaned up
|
|
exit 1
|
|
}
|
|
|
|
Delete-Tmp-Folder
|
|
break
|
|
|
|
|
|
|
|
|
|
|