|
| 1 | + |
| 2 | +<# |
| 3 | +
|
| 4 | +Script that releases mpv.net on GitHub. |
| 5 | +
|
| 6 | +Needs 2 positional CLI arguments: |
| 7 | + 1. Directory where the mpv.net source code is located. |
| 8 | + 2. Directory of the output files, for instance the desktop dir. |
| 9 | +
|
| 10 | +Dependencies: |
| 11 | + 7zip installation found at: 'C:\Program Files\7-Zip\7z.exe'. |
| 12 | + Inno Setup compiler installation found at: 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe'. |
| 13 | + GitHub CLI https://cli.github.com |
| 14 | +
|
| 15 | +#> |
| 16 | + |
| 17 | +# Stop when the first error occurs |
| 18 | +$ErrorActionPreference = 'Stop' |
| 19 | + |
| 20 | +function DeleteDir($path) { |
| 21 | + if (Test-Path $path) { |
| 22 | + Remove-Item $path -Recurse |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +# Throw error if the file/dir don't exist |
| 27 | +function Test($path) { |
| 28 | + if (-not (Test-Path $path)) { |
| 29 | + throw $path |
| 30 | + } |
| 31 | + return $path |
| 32 | +} |
| 33 | + |
| 34 | +# Variables |
| 35 | +$SourceDir = Test $args[0] |
| 36 | +$OutputRootDir = Test $args[1] |
| 37 | + |
| 38 | +Test (Join-Path $SourceDir 'MpvNet.sln') |
| 39 | + |
| 40 | +$7zFile = Test 'C:\Program Files\7-Zip\7z.exe' |
| 41 | +$InnoSetupCompiler = Test 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe' |
| 42 | + |
| 43 | +$ReleaseNotes = "- [.NET Desktop Runtime 6.0](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)`n- [Changelog](https://github.com/mpvnet-player/mpv.net/blob/main/docs/changelog.md)" |
| 44 | +$Repo = 'github.com/mpvnet-player/mpv.net' |
| 45 | + |
| 46 | +# Dotnet Publish |
| 47 | +$PublishDir64 = Join-Path $SourceDir 'MpvNet.Windows\bin\Debug\win-x64\publish\' |
| 48 | +$PublishDirARM64 = Join-Path $SourceDir 'MpvNet.Windows\bin\Debug\win-arm64\publish\' |
| 49 | +$ProjectFile = Test (Join-Path $SourceDir 'MpvNet.Windows\MpvNet.Windows.csproj') |
| 50 | +dotnet publish $ProjectFile --self-contained false --configuration Debug --runtime win-x64 |
| 51 | +dotnet publish $ProjectFile --self-contained false --configuration Debug --runtime win-arm64 |
| 52 | +$PublishedExeFile64 = Test ($PublishDir64 + 'mpvnet.exe') |
| 53 | + |
| 54 | +# Create OutputName |
| 55 | +$VersionInfo = [Diagnostics.FileVersionInfo]::GetVersionInfo($PublishedExeFile64) |
| 56 | +$IsBeta = $VersionInfo.FilePrivatePart -ne 0 |
| 57 | +$BetaString = if ($IsBeta) { '-beta' } else { '' } |
| 58 | +$VersionName = $VersionInfo.FileVersion |
| 59 | +$OutputName64 = 'mpv.net-v' + $VersionName + $BetaString + '-portable-x64' |
| 60 | +$OutputNameARM64 = 'mpv.net-v' + $VersionName + $BetaString + '-portable-ARM64' |
| 61 | + |
| 62 | +# Create OutputFolder |
| 63 | +$OutputDir64 = Join-Path $OutputRootDir ($OutputName64 + '\') |
| 64 | +$OutputDirARM64 = Join-Path $OutputRootDir ($OutputNameARM64 + '\') |
| 65 | +DeleteDir $OutputDir64 |
| 66 | +DeleteDir $OutputDirARM64 |
| 67 | +mkdir $OutputDir64 |
| 68 | +mkdir $OutputDirARM64 |
| 69 | + |
| 70 | +# Copy Files |
| 71 | +Copy-Item ($PublishDir64 + '*') $OutputDir64 |
| 72 | +Copy-Item ($PublishDirARM64 + '*') $OutputDirARM64 |
| 73 | +$BinDirX64 = Test (Join-Path $SourceDir 'MpvNet.Windows\bin\Debug\') |
| 74 | +$BinDirARM64 = Test (Join-Path $SourceDir 'MpvNet.Windows\bin\Debug\win-arm64\') |
| 75 | +$ExtraFiles = 'mpvnet.com', 'libmpv-2.dll', 'MediaInfo.dll' |
| 76 | +$ExtraFiles | ForEach-Object { Copy-Item ($BinDirX64 + $_) ($OutputDir64 + $_) } |
| 77 | +$ExtraFiles | ForEach-Object { Copy-Item ($BinDirARM64 + $_) ($OutputDirARM64 + $_) } |
| 78 | +$LocaleDir = Test (Join-Path $SourceDir 'MpvNet.Windows\bin\Debug\Locale\') |
| 79 | +Copy-Item $LocaleDir ($OutputDir64 + 'Locale') -Recurse |
| 80 | +Copy-Item $LocaleDir ($OutputDirARM64 + 'Locale') -Recurse |
| 81 | + |
| 82 | +# Pack |
| 83 | +$ZipOutputFile64 = Join-Path $OutputRootDir ($OutputName64 + '.zip') |
| 84 | +$ZipOutputFileARM64 = Join-Path $OutputRootDir ($OutputNameARM64 + '.zip') |
| 85 | +& $7zFile a -tzip -mx9 $ZipOutputFile64 -r ($OutputDir64 + '*') |
| 86 | +if ($LastExitCode) { throw $LastExitCode } |
| 87 | +& $7zFile a -tzip -mx9 $ZipOutputFileARM64 -r ($OutputDirARM64 + '*') |
| 88 | +if ($LastExitCode) { throw $LastExitCode } |
| 89 | +Test $ZipOutputFile64 |
| 90 | +Test $ZipOutputFileARM64 |
| 91 | + |
| 92 | +# Inno Setup |
| 93 | +''; '' |
| 94 | +$InnoSetupScript = Test (Join-Path $SourceDir 'Setup\Inno\inno-setup.iss') |
| 95 | +& $InnoSetupCompiler $InnoSetupScript |
| 96 | +if ($LastExitCode) { throw $LastExitCode } |
| 97 | +$SetupFile = Test (Join-Path $OutputRootDir "mpv.net-v$VersionName-setup-x64.exe") |
| 98 | + |
| 99 | +if ($IsBeta) { |
| 100 | + $NewSetupFile = Join-Path $OutputRootDir "mpv.net-v$VersionName-beta-setup-x64.exe" |
| 101 | + Move-Item $SetupFile $NewSetupFile |
| 102 | + $SetupFile = $NewSetupFile |
| 103 | +} |
| 104 | + |
| 105 | +# Release |
| 106 | +$Title = 'v' + $VersionName + $BetaString |
| 107 | + |
| 108 | +if ($BetaString) { |
| 109 | + gh release create $Title -t $Title -n $ReleaseNotes --repo $Repo --prerelease $ZipOutputFile64 $ZipOutputFileARM64 $SetupFile |
| 110 | +} else { |
| 111 | + gh release create $Title -t $Title -n $ReleaseNotes --repo $Repo $ZipOutputFile64 $ZipOutputFileARM64 $SetupFile |
| 112 | +} |
| 113 | + |
| 114 | +if ($LastExitCode) { throw $LastExitCode } |
0 commit comments