Skip to content

Commit 5c6fb7e

Browse files
authored
Merge pull request #2 from fhaag/support-net-core
Support net core and improve build automation
2 parents 959fdea + 96f617e commit 5c6fb7e

File tree

24 files changed

+402
-849
lines changed

24 files changed

+402
-849
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ buildtmp
66
/doc/*.xml
77
/doc/Help
88
/doc/*.shfbproj_*
9-
/release
9+
/release
10+
11+
*.backup

COPYING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name-Based Grid is made available under the terms of the MIT License.
22

3-
Copyright (c) 2015 Florian Haag
3+
Copyright (c) 2015, 2024 Florian Haag
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2015 Florian Haag
3+
Copyright (c) 2015, 2024 Florian Haag
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

build/build.ps1

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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.'

build/buildVersionHelper.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
function getFileBuildVersion {
26+
param(
27+
[Parameter(Mandatory=$true)][string]$path,
28+
$silent = $true
29+
)
30+
31+
if (-not $silent) {
32+
Write-Host -ForegroundColor Cyan "Retrieving version of $path ..."
33+
}
34+
35+
if (Test-Path "$path") {
36+
$previousVerInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("$dllOutputPath")
37+
if ($previousVerInfo.FileVersion) {
38+
if (-not $silent) {
39+
Write-Host -ForegroundColor Red $previousVerInfo.FileVersion
40+
}
41+
42+
[System.Version]$previousVer = $null
43+
if ([System.Version]::TryParse($previousVerInfo.FileVersion, [ref]$previousVer)) {
44+
if (-not $silent) {
45+
Write-Host -ForegroundColor Yellow $previousVer
46+
}
47+
48+
return $previousVer.Revision
49+
}
50+
}
51+
}
52+
53+
return $null
54+
}

build/publish.ps1

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
# paths
36+
37+
$scriptDir = $PSScriptRoot
38+
$tmpDir = [System.IO.Path]::Combine("$scriptDir", '..', 'pubinfo', '_tmp')
39+
40+
# check files to release
41+
42+
$srcPath = Join-Path "$tmpDir" "NameBasedGrid-$version-src.tar.gz"
43+
$binPath = Join-Path "$tmpDir" "NameBasedGrid-$version-bin.tar.gz"
44+
$nupkgPath = Join-Path "$tmpDir" "NameBasedGrid.$version.nupkg"
45+
46+
foreach ($fn in @($srcPath, $binPath, $nupkgPath)) {
47+
if (-not (Test-Path "$fn")) {
48+
Write-Host -ForegroundColor Red "File not found: $fn"
49+
exit 10
50+
}
51+
}
52+
53+
# retrieve Git revision
54+
$rev = &git rev-parse HEAD
55+
56+
# Github
57+
58+
Write-Host -ForegroundColor Cyan 'Publishing GitHub release ...'
59+
60+
$gitHubSettings = @{
61+
Owner = 'fhaag';
62+
Project = 'namebasedgrid';
63+
ReleaseName = "v$version";
64+
}
65+
66+
Import-Module PowerShellForGitHub
67+
68+
Write-Host -ForegroundColor DarkYellow "Checking release number $($gitHubSettings.ReleaseName) ..."
69+
$existingReleases = Get-GitHubRelease -OwnerName "$($gitHubSettings.Owner)" -RepositoryName "$($gitHubSettings.Project)" -Tag "$($gitHubSettings.ReleaseName)" -ErrorAction:Ignore
70+
71+
if ($existingReleases.Count -ge 1) {
72+
Write-Host -ForegroundColor Red "Release $($gitHubSettings.ReleaseName) already exists on Github."
73+
exit 20
74+
}
75+
76+
Write-Host -ForegroundColor DarkGreen 'Release number is unique.'
77+
78+
Write-Host -ForegroundColor DarkYellow 'Creating release ...'
79+
80+
$newRel = New-GitHubRelease -OwnerName "$($gitHubSettings.Owner)" -RepositoryName "$($gitHubSettings.Project)" -Tag "$($gitHubSettings.ReleaseName)" -Name "$($gitHubSettings.ReleaseName)" -Body 'Test release to check new publication script.' -Draft
81+
82+
Write-Host -ForegroundColor DarkGreen "New release $($gitHubSettings.ReleaseName) created with ID $($newRel.ID)."
83+
84+
Write-Host -ForegroundColor DarkYellow 'Uploading release assets ...'
85+
86+
New-GitHubReleaseAsset -OwnerName "$($gitHubSettings.Owner)" -RepositoryName "$($gitHubSettings.Project)" -Release $newRel.ID -Label 'Source code (.tar.gz)' -Path "$srcPath" -ContentType 'application/gzip'
87+
New-GitHubReleaseAsset -OwnerName "$($gitHubSettings.Owner)" -RepositoryName "$($gitHubSettings.Project)" -Release $newRel.ID -Label 'Binaries (.tar.gz)' -Path "$binPath" -ContentType 'application/gzip'
88+
89+
Write-Host -ForegroundColor Green 'Done.'
90+
91+
# NuGet
92+
93+
Write-Host -ForegroundColor Cyan 'Publishing NuGet package ...'
94+
95+
& nuget push "$nupkgPath"
96+
97+
Write-Host -ForegroundColor Green 'Done.'

doc/NameBasedGrid.shfbproj

Lines changed: 0 additions & 78 deletions
This file was deleted.

doc/additional/AttachedPropertiesDoc.xml

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)