Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CreateRelease.WPF.ps1 « build - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9521bea18239f7988e25019f98d4eb41aa560e05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# When using System.IO.Compression.ZipFile.CreateFromDirectory in PowerShell, it still uses backslashes in the zip paths
# despite this https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-ziparchiveentry-fullname-path-separator

# Based upon post by Seth Jackson https://sethjackson.github.io/2016/12/17/path-separators/

#
# PowerShell 5 (WMF5) & 6
# Using class Keyword https://msdn.microsoft.com/powershell/reference/5.1/Microsoft.PowerShell.Core/about/about_Classes
#
# https://gist.github.com/lantrix/738ebfa616d5222a8b1db947793bc3fc
#

####################################
###        Fix Zip slash         ###
####################################
Add-Type -AssemblyName System.Text.Encoding
Add-Type -AssemblyName System.IO.Compression.FileSystem

class FixedEncoder : System.Text.UTF8Encoding {
    FixedEncoder() : base($true) { }

    [byte[]] GetBytes([string] $s)
    {
        $s = $s.Replace("\", "/");
        return ([System.Text.UTF8Encoding]$this).GetBytes($s);
    }
}

# Script working directory
Set-Location $PSScriptRoot\..

####################################
###         Configuration        ###
####################################
$enableMSI = $true
#$buildOnly = 'linux-x64'
#$buildOnly = 'win-x64'
# Profilling
$stopWatch = New-Object -TypeName System.Diagnostics.Stopwatch 
$deployStopWatch = New-Object -TypeName System.Diagnostics.Stopwatch
$stopWatch.Start()


# Variables
$software = "UVtools"
$project = "UVtools.WPF"
$buildWith = "Release"
$netFolder = "net5.0"
$releaseFolder = "$project\bin\$buildWith\$netFolder"
$objFolder = "$project\obj\$buildWith\$netFolder"
$publishFolder = "publish"
$platformsFolder = "UVtools.Platforms"

# Not supported yet! No fuse on WSL
$appImageFile = 'appimagetool-x86_64.AppImage'
$appImageFilePath = "$platformsFolder/AppImage/$appImageFile"
$appImageUrl = "https://github.com/AppImage/AppImageKit/releases/download/continuous/$appImageFile"

$macIcns = "UVtools.CAD/UVtools.icns"

#$version = (Get-Command "$releaseFolder\UVtools.dll").FileVersionInfo.ProductVersion
$projectXml = [Xml] (Get-Content "$project\$project.csproj")
$version = "$($projectXml.Project.PropertyGroup.Version)".Trim();
if([string]::IsNullOrWhiteSpace($version)){
    Write-Error "Can not detect the UVtools version, does $project\$project.csproj exists?"
    exit
}

# MSI Variables
$installers = @("UVtools.InstallerMM", "UVtools.Installer")
$msiSourceFile = "UVtools.Installer\bin\Release\UVtools.msi"
$msbuild = "`"${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe`" /t:Build /p:Configuration=$buildWith /p:MSIProductVersion=$version"

Write-Output "
####################################
###  UVtools builder & deployer  ###
####################################
Version: $version [$buildWith]
"

####################################
###   Clean up previous publish  ###
####################################
# Clean up previous publish
Remove-Item $publishFolder -Recurse -ErrorAction Ignore # Clean

####################################
###    Self-contained runtimes   ###
####################################
$runtimes = 
@{
    "win-x64" = @{
        "extraCmd" = "-p:PublishReadyToRun=true"
        "exclude" = @("UVtools.sh")
        "include" = @()
    }
    "linux-x64" = @{
        "extraCmd" = "-p:PublishReadyToRun=true"
        "exclude" = @()
        "include" = @("libcvextern.so")
    }
    "arch-x64" = @{
        "extraCmd" = "-p:PublishReadyToRun=true"
        "exclude" = @()
        "include" = @("libcvextern.so")
    }
    "rhel-x64" = @{
        "extraCmd" = "-p:PublishReadyToRun=true"
        "exclude" = @()
        "include" = @("libcvextern.so")
    }
    #"linux-arm64" = @{
    #    "extraCmd" = "-p:PublishReadyToRun=true"
    #    "exclude" = @()
    #    "include" = @("libcvextern.so")
    #}
    #"unix-x64" = @{
    #    "extraCmd" = "-p:PublishReadyToRun=true"
    #    "exclude" = @("x86", "x64", "libcvextern.dylib")
    #}
    "osx-x64" = @{
        "extraCmd" = "-p:PublishReadyToRun=true"
        "exclude" = @()
        "include" = @("libcvextern.dylib")
    }
}


# https://github.com/AppImage/AppImageKit/wiki/Bundling-.NET-Core-apps
#Invoke-WebRequest -Uri $appImageUrl -OutFile $appImageFilePath
#wsl chmod a+x $appImageFilePath

foreach ($obj in $runtimes.GetEnumerator()) {
    if(![string]::IsNullOrWhiteSpace($buildOnly) -and !$buildOnly.Equals($obj.Name)) {continue}
    # Configuration
    $deployStopWatch.Restart()
    $runtime = $obj.Name;       # runtime name
    $extraCmd = $obj.extraCmd;  # extra cmd to run with dotnet
    $targetZip = "$publishFolder/${software}_${runtime}_v$version.zip"  # Target zip filename
    
    # Deploy
    Write-Output "################################
Building: $runtime"
    dotnet publish $project -o "$publishFolder/$runtime" -c $buildWith -r $runtime $extraCmd
    if(!$runtime.Equals('win-x64'))
    {
        # Fix permissions
        wsl chmod +x "$publishFolder/$runtime/UVtools" `|`| :
        wsl chmod +x "$publishFolder/$runtime/UVtools.sh" `|`| :
    }
    
    # Cleanup
    Remove-Item "$releaseFolder\$runtime" -Recurse -ErrorAction Ignore
    Remove-Item "$objFolder\$runtime" -Recurse -ErrorAction Ignore
    Write-Output "$releaseFolder\$runtime"
    
    foreach ($excludeObj in $obj.Value.exclude) {
        Write-Output "Excluding: $excludeObj"
        Remove-Item "$publishFolder\$runtime\$excludeObj" -Recurse -ErrorAction Ignore
    }

    foreach ($includeObj in $obj.Value.include) {
        Write-Output "Including: $includeObj"
        Copy-Item "$platformsFolder\$runtime\$includeObj" -Destination "$publishFolder\$runtime"  -Recurse -ErrorAction Ignore
    }

    #if($runtime.Equals('linux-x64')){
    #    $appDirDest = "$publishFolder/AppImage.$runtime/AppDir"
    #    Copy-Item "$platformsFolder/AppImage/AppDir" $appDirDest -Force -Recurse
    #    wsl chmod 755 "$appDirDest/AppRun"
    #    wsl cp -a "$publishFolder/$runtime/." "$appDirDest/usr/bin"
    #    wsl $appImageFilePath $appDirDest
    #}
    if($runtime.Equals('osx-x64')){
        $macAppFolder = "${software}.app"
        $macPublishFolder = "$publishFolder/${macAppFolder}"
        $macInfoplist = "$platformsFolder/$runtime/Info.plist"
        $macOutputInfoplist = "$macPublishFolder/Contents"
        $macTargetZipLegacy = "$publishFolder/${software}_${runtime}-legacy_v$version.zip"

        New-Item -ItemType directory -Path "$macPublishFolder"
        New-Item -ItemType directory -Path "$macPublishFolder/Contents"
        New-Item -ItemType directory -Path "$macPublishFolder/Contents/MacOS"
        New-Item -ItemType directory -Path "$macPublishFolder/Contents/Resources"

        
        Copy-Item "$macIcns" -Destination "$macPublishFolder/Contents/Resources"
        ((Get-Content -Path "$macInfoplist") -replace '#VERSION',"$version") | Set-Content -Path "$macOutputInfoplist/Info.plist"
        wsl cp -a "$publishFolder/$runtime/." "$macPublishFolder/Contents/MacOS"

        wsl cd "$publishFolder/" `&`& pwd `&`& zip -r "../$targetZip" "$macAppFolder/*"
        wsl cd "$publishFolder/$runtime" `&`& pwd `&`& zip -r "../../$macTargetZipLegacy" .
        
    }
    else {
        Write-Output "Compressing $runtime to: $targetZip"
        Write-Output $targetZip "$publishFolder/$runtime"
        wsl cd "$publishFolder/$runtime" `&`& pwd `&`& zip -r "../../$targetZip" .
    }

    # Zip
    #Write-Output "Compressing $runtime to: $targetZip"
    #Write-Output $targetZip "$publishFolder/$runtime"
    #[System.IO.Compression.ZipFile]::CreateFromDirectory("$publishFolder\$runtime", $targetZip, [System.IO.Compression.CompressionLevel]::Optimal, $false, [FixedEncoder]::new())
	#wsl cd "$publishFolder/$runtime" `&`& pwd `&`& chmod +x -f "./$software" `|`| : `&`& zip -r "../../$targetZip" "."
    $deployStopWatch.Stop()
    Write-Output "Took: $($deployStopWatch.Elapsed)
################################
"
}

# Universal package
<#
$deployStopWatch.Restart()
$runtime = "universal-x86-x64"
$targetZip = "$publishFolder\${software}_${runtime}_v$version.zip"

Write-Output "################################
Building: $runtime"
dotnet build $project -c $buildWith

Write-Output "Compressing $runtime to: $targetZip"
[System.IO.Compression.ZipFile]::CreateFromDirectory($releaseFolder, $targetZip, [System.IO.Compression.CompressionLevel]::Optimal, $false, [FixedEncoder]::new())
Write-Output "Took: $($deployStopWatch.Elapsed)
################################
"
$stopWatch.Stop()
#>

# MSI Installer for Windows
if($enableMSI)
{
    $deployStopWatch.Restart()
    $runtime = 'win-x64'
    $msiTargetFile = "$publishFolder\${software}_${runtime}_v$version.msi"
    Write-Output "################################
    Building: $runtime MSI Installer"

    foreach($installer in $installers)
    {
        # Clean and build MSI
        Remove-Item "$installer\obj" -Recurse -ErrorAction Ignore
        Remove-Item "$installer\bin" -Recurse -ErrorAction Ignore
        Invoke-Expression "& $msbuild $installer\$installer.wixproj"
    }

    Write-Output "Coping $runtime MSI to: $msiTargetFile"
    Copy-Item $msiSourceFile $msiTargetFile

    Write-Output "Took: $($deployStopWatch.Elapsed)
    ################################
    "
}


Write-Output "
####################################
###           Completed          ###
####################################
In: $($stopWatch.Elapsed)"