|
| 1 | +# ------------------------------------------------------------------------------ |
| 2 | +# This source file is a part of Name-Based Grid. |
| 3 | +# |
| 4 | +# Copyright (c) 2024 Florian Haag |
| 5 | +# |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files (the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions: |
| 12 | +# |
| 13 | +# The above copyright notice and this permission notice shall be |
| 14 | +# included in all copies or substantial portions of the Software. |
| 15 | +# |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | +# THE SOFTWARE. |
| 23 | +# ------------------------------------------------------------------------------ |
| 24 | + |
| 25 | +Param( |
| 26 | + [Parameter(Mandatory=$true)][String]$version |
| 27 | +) |
| 28 | + |
| 29 | +# check version format |
| 30 | +if (-not ($version -match '^[0-9]+\.[0-9]+\.[0-9]+$')) { |
| 31 | + Write-Host -ForegroundColor Red "$version is not a basic three-component version in major.minor.patch format." |
| 32 | + exit 5 |
| 33 | +} |
| 34 | + |
| 35 | +# basic folders |
| 36 | +$scriptDir = $PSScriptRoot |
| 37 | +$rootDir = [System.IO.Path]::Combine($scriptDir, '..') |
| 38 | + |
| 39 | +# retrieve Git revision |
| 40 | +$rev = &git rev-parse HEAD |
| 41 | + |
| 42 | +# check external tools locations |
| 43 | +$inkscapePath = $Env:INKSCAPE_PATH |
| 44 | +if (-not $inkscapePath) { |
| 45 | + Write-Host -ForegroundColor Red 'Inkscape path not set.' |
| 46 | + exit 8 |
| 47 | +} |
| 48 | + |
| 49 | +$sevenZipPath = $Env:SEVENZIP_PATH |
| 50 | +if (-not $sevenZipPath) { |
| 51 | + Write-Host -ForegroundColor Red '7zip path not set.' |
| 52 | + exit 9 |
| 53 | +} |
| 54 | + |
| 55 | +# create temp directory |
| 56 | +$tempDir = [System.IO.Path]::Combine($rootDir, 'pubinfo', '_tmp') |
| 57 | +if (Test-Path "$tempDir") { |
| 58 | + Remove-Item -LiteralPath "$tempDir" -Force -Recurse |
| 59 | +} |
| 60 | + |
| 61 | +[System.IO.Directory]::CreateDirectory("$tempDir") | Out-Null |
| 62 | + |
| 63 | +# rasterize logo |
| 64 | +$logoPath = [System.IO.Path]::Combine($rootDir, 'pubinfo', 'logo.svg') |
| 65 | +$logoDestPath = [System.IO.Path]::Combine($tempDir, 'logo128.png') |
| 66 | +&"$inkscapePath" --export-type="png" --export-width=128 -o "$logoDestPath" "$logoPath" |
| 67 | +Write-Host -ForegroundColor Cyan 'Logo PNG generated.' |
| 68 | + |
| 69 | +# adapt readme file |
| 70 | +$readmePath = [System.IO.Path]::Combine($rootDir, 'pubinfo', 'readme.txt') |
| 71 | +$destReadmePath = [System.IO.Path]::Combine($tempDir, 'readme.txt') |
| 72 | +$readme = Get-Content -Path "$readmePath" -Raw |
| 73 | +$readme = $readme -replace '%DATE%', [System.DateTime]::UtcNow.ToString('yyyy-MM-dd') |
| 74 | +$readme = $readme -replace '%VERSION%', "$version" |
| 75 | +$readme = $readme -replace '%REV%', "$rev" |
| 76 | +$readme | Out-File -FilePath "$destReadmePath" |
| 77 | +Write-Host -ForegroundColor Cyan 'Readme file adapted.' |
| 78 | + |
| 79 | +# retrieve previous assembly file version |
| 80 | +$dllOutputPath = [System.IO.Path]::Combine($rootDir, 'bin', 'Release', 'net8.0-windows', 'NameBasedGrid.dll') # any compiled file will do, no matter which target |
| 81 | +. '.\buildVersionHelper.ps1' |
| 82 | +$previousBuild = getFileBuildVersion -path "$dllOutputPath" |
| 83 | +if ($previousBuild -ne $null) { |
| 84 | + $previousBuild = $previousBuild + 1 |
| 85 | +} else { |
| 86 | + Write-Host -ForegroundColor Yellow "A previous file version could not be retrieved from $dllOutputPath. Build counting will start at 0." |
| 87 | + Write-Host -ForegroundColor Yellow 'If this is the first build of the project, you can safely ignore this message. However, it might also mean that a previously built file is not present on the current machine, or that the script is not looking in the right location.' |
| 88 | + |
| 89 | + $previousBuild = 0 |
| 90 | +} |
| 91 | +$newFileVer = "$version.$previousBuild" |
| 92 | +Write-Host -ForegroundColor Cyan "New build version: $newFileVer" |
| 93 | + |
| 94 | +# build and pack project |
| 95 | +$slnDir = [System.IO.Path]::Combine($rootDir, 'src') |
| 96 | +$slnPath = [System.IO.Path]::Combine($slnDir, 'NameBasedGrid.sln') |
| 97 | +$pjPath = [System.IO.Path]::Combine($slnDir, 'NameBasedGrid', 'NameBasedGrid.csproj') |
| 98 | + |
| 99 | +&dotnet build -p "Version=$version" -p "FileVersion=$newFileVer" -c Release "$slnPath" |
| 100 | +Write-Host -ForegroundColor Cyan 'Code compiled.' |
| 101 | + |
| 102 | +&dotnet pack "$pjPath" --no-build --no-restore -o "$tempDir" -p "Version=$version" |
| 103 | +Write-Host -ForegroundColor Cyan 'NuGet package packed.' |
| 104 | + |
| 105 | +# create custom packages |
| 106 | +$srcTarPath = [System.IO.Path]::Combine($tempDir, "NameBasedGrid-$version-src.tar") |
| 107 | +&"$sevenZipPath" a "-xr!.vs" "-xr!bin" "-xr!obj" "-i!$destReadmePath" -ttar "$srcTarPath" "$([System.IO.Path]::Combine($rootDir, 'src'))" |
| 108 | +Write-Host -ForegroundColor Cyan 'Sources release package tarred ...' |
| 109 | +&"$sevenZipPath" a -tgzip "$($srcTarPath).gz" "$srcTarPath" |
| 110 | +Write-Host -ForegroundColor Cyan '... and gzipped.' |
| 111 | + |
| 112 | +$binTarPath = [System.IO.Path]::Combine($tempDir, "NameBasedGrid-$version-bin.tar") |
| 113 | +&"$sevenZipPath" a "-i!$destReadmePath" -ttar "$binTarPath" "$([System.IO.Path]::Combine($rootDir, 'bin', 'Release', '*'))" |
| 114 | +Write-Host -ForegroundColor Cyan 'Binaries release package tarred ...' |
| 115 | +&"$sevenZipPath" a -tgzip "$($binTarPath).gz" "$binTarPath" |
| 116 | +Write-Host -ForegroundColor Cyan '... and gzipped.' |
0 commit comments