From 3ad9f2af3a897b352f3ff614b84204f49aab30e9 Mon Sep 17 00:00:00 2001 From: Henrik Lau Eriksson Date: Sun, 30 Jun 2024 15:48:33 +0200 Subject: [PATCH] :runner: --- src/GEmojiSharp.PowerToysRun/deploy.bat | 7 -- src/GEmojiSharp.PowerToysRun/deploy.ps1 | 67 +++++++++++++++++ src/GEmojiSharp.PowerToysRun/pack.bat | 7 -- src/GEmojiSharp.PowerToysRun/pack.ps1 | 68 ++++++++++++++++++ src/GEmojiSharp.PowerToysRun/release.ps1 | 91 ++++++++++++++++++++++++ 5 files changed, 226 insertions(+), 14 deletions(-) delete mode 100644 src/GEmojiSharp.PowerToysRun/deploy.bat create mode 100644 src/GEmojiSharp.PowerToysRun/deploy.ps1 delete mode 100644 src/GEmojiSharp.PowerToysRun/pack.bat create mode 100644 src/GEmojiSharp.PowerToysRun/pack.ps1 create mode 100644 src/GEmojiSharp.PowerToysRun/release.ps1 diff --git a/src/GEmojiSharp.PowerToysRun/deploy.bat b/src/GEmojiSharp.PowerToysRun/deploy.bat deleted file mode 100644 index df8ad4e..0000000 --- a/src/GEmojiSharp.PowerToysRun/deploy.bat +++ /dev/null @@ -1,7 +0,0 @@ -call pack.bat - -taskkill /f /im PowerToys.exe /t - -xcopy /s /y .\bin\Release\GEmojiSharp\ "%LocalAppData%\Microsoft\PowerToys\PowerToys Run\Plugins\GEmojiSharp\" - -start "" "C:\Program Files\PowerToys\PowerToys.exe" diff --git a/src/GEmojiSharp.PowerToysRun/deploy.ps1 b/src/GEmojiSharp.PowerToysRun/deploy.ps1 new file mode 100644 index 0000000..bff33c7 --- /dev/null +++ b/src/GEmojiSharp.PowerToysRun/deploy.ps1 @@ -0,0 +1,67 @@ +<#PSScriptInfo +.VERSION 0.0.0 +.GUID 04ee4032-b6da-48fa-a89f-553b6dd0b611 +.AUTHOR Henrik Lau Eriksson +.COMPANYNAME +.COPYRIGHT +.TAGS PowerToys Run Plugins Deploy +.LICENSEURI +.PROJECTURI https://github.com/hlaueriksson/GEmojiSharp +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES +#> + +<# + .Synopsis + Deploys the plugin to PowerToys Run. + + .Description + Copies the plugin to the PowerToys Run Plugins folder: + - %LocalAppData%\Microsoft\PowerToys\PowerToys Run\Plugins + + .Parameter Platform + Platform: ARM64 | x64 + + .Example + .\deploy.ps1 + + .Link + https://github.com/hlaueriksson/GEmojiSharp +#> +param ( + [ValidateSet("ARM64", "x64")] + [string]$platform = "x64" +) + +#Requires -RunAsAdministrator + +Stop-Process -Name "PowerToys" -Force -ErrorAction SilentlyContinue + +dotnet build -c Release /p:TF_BUILD=true /p:Platform=$platform + +Write-Output "Platform: $platform" + +$libs = Get-ChildItem -Path .\libs -File -Recurse + +$name = ((Split-Path -Path $PWD -Leaf).Split(".")[0]) # -1 last + +Write-Output "Deploy: $name" + +Remove-Item -LiteralPath "$env:LOCALAPPDATA\Microsoft\PowerToys\PowerToys Run\Plugins\$name" -Recurse -Force -ErrorAction SilentlyContinue +Copy-Item -Path ".\bin\$platform\Release\net8.0-windows" -Destination "$env:LOCALAPPDATA\Microsoft\PowerToys\PowerToys Run\Plugins\$name" -Recurse -Force -Exclude $libs + +$machinePath = "C:\Program Files\PowerToys\PowerToys.exe" +$userPath = "$env:LOCALAPPDATA\PowerToys\PowerToys.exe" + +if (Test-Path $machinePath) { + Start-Process -FilePath $machinePath +} +elseif (Test-Path $userPath) { + Start-Process -FilePath $userPath +} +else { + Write-Error "Unable to start PowerToys" +} diff --git a/src/GEmojiSharp.PowerToysRun/pack.bat b/src/GEmojiSharp.PowerToysRun/pack.bat deleted file mode 100644 index df06269..0000000 --- a/src/GEmojiSharp.PowerToysRun/pack.bat +++ /dev/null @@ -1,7 +0,0 @@ -dotnet build -c Release /p:TF_BUILD=true - -xcopy /y .\bin\Release\net8.0-windows\Images\ .\bin\Release\GEmojiSharp\Images\ -xcopy /y .\bin\Release\net8.0-windows\GEmojiSharp.* .\bin\Release\GEmojiSharp\ -xcopy /y .\bin\Release\net8.0-windows\plugin.json .\bin\Release\GEmojiSharp\ - -:: Zip '.\bin\Release\GEmojiSharp\' into 'GEmojiSharp.PowerToysRun.3.1.3.zip' diff --git a/src/GEmojiSharp.PowerToysRun/pack.ps1 b/src/GEmojiSharp.PowerToysRun/pack.ps1 new file mode 100644 index 0000000..cf17a38 --- /dev/null +++ b/src/GEmojiSharp.PowerToysRun/pack.ps1 @@ -0,0 +1,68 @@ +<#PSScriptInfo +.VERSION 0.0.0 +.GUID a5a44179-e1e5-4ddd-9e0a-d6653eb69d9f +.AUTHOR Henrik Lau Eriksson +.COMPANYNAME +.COPYRIGHT +.TAGS PowerToys Run Plugins Pack +.LICENSEURI +.PROJECTURI https://github.com/hlaueriksson/GEmojiSharp +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES +#> + +<# + .Synopsis + Packs the plugin into release archive. + + .Description + Builds the project in Release configuration, + copies the output files into plugin folder, + packs the plugin folder into release archive. + + .Example + .\pack.ps1 + + .Link + https://github.com/hlaueriksson/GEmojiSharp +#> + +# Clean +Get-ChildItem -Path "." -Directory -Include "bin", "obj" -Recurse | Remove-Item -Recurse -Force + +# Version +[xml]$props = Get-Content -Path "*.csproj" +$version = "$($props.Project.PropertyGroup.Version)".Trim() +Write-Output "Version: $version" + +# Platforms +$platforms = "$($props.Project.PropertyGroup.Platforms)".Trim() -split ";" + +$libs = Get-ChildItem -Path .\libs -File -Recurse + +foreach ($platform in $platforms) +{ + Write-Output "Platform: $platform" + + # Build + dotnet build -c Release /p:TF_BUILD=true /p:Platform=$platform + + if (!$?) { + # Build FAILED. + Exit $LastExitCode + } + + $name = ((Split-Path -Path $PWD -Leaf).Split(".")[0]) # -1 last + + Write-Output "Pack: $name" + + $output = ".\bin\$platform\Release\net8.0-windows\" + $destination = ".\bin\$platform\$name" + $zip = ".\bin\$platform\$name-$version-$($platform.ToLower()).zip" + + Copy-Item -Path $output -Destination $destination -Recurse -Exclude $libs + Compress-Archive -Path $destination -DestinationPath $zip +} diff --git a/src/GEmojiSharp.PowerToysRun/release.ps1 b/src/GEmojiSharp.PowerToysRun/release.ps1 new file mode 100644 index 0000000..ef79f75 --- /dev/null +++ b/src/GEmojiSharp.PowerToysRun/release.ps1 @@ -0,0 +1,91 @@ +<#PSScriptInfo +.VERSION 0.0.0 +.GUID 01b1a89c-3a39-40e5-ae5b-d85bce48815f +.AUTHOR Henrik Lau Eriksson +.COMPANYNAME +.COPYRIGHT +.TAGS PowerToys Run Plugins Release +.LICENSEURI +.PROJECTURI https://github.com/hlaueriksson/GEmojiSharp +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES +#> + +<# + .Synopsis + Generate release notes snippets for the plugin. + + .Description + Gathers information about the plugin and generates a markdown file with release notes snippets. + + .Example + .\release.ps1 + + .Link + https://github.com/hlaueriksson/GEmojiSharp +#> + +# Version +[xml]$props = Get-Content -Path "*.csproj" +$version = "$($props.Project.PropertyGroup.Version)".Trim() + +# Platforms +$platforms = "$($props.Project.PropertyGroup.Platforms)".Trim() -split ";" + +# Output +$result = "release-$version.md" + +$projectUri = "https://github.com/hlaueriksson/GEmojiSharp" +$name = ((Split-Path -Path $PWD -Leaf).Split(".")[0]) # -1 last +$files = Get-ChildItem -Path . -File -Include "$name-$version*.zip" -Recurse + +function Write-Line { + param ( + [string]$line + ) + + $line | Add-Content -Path $result +} + +function Get-Platform { + param ( + [string]$filename + ) + + if ($filename -Match $platforms[0]) { + $platforms[0] + } + else { + $platforms[1] + } +} + +Set-Content -Path $result -Value "" + +Write-Line "## $name" +Write-Line "" +Write-Line "| Platform | Filename | Downloads" +Write-Line "| --- | --- | ---" +foreach ($file in $files) { + $zip = $file.Name + $platform = Get-Platform $zip + $url = "$projectUri/releases/download/v$version/$zip" + $badge = "https://img.shields.io/github/downloads/$($projectUri.Replace('https://github.com/', ''))/v$version/$zip" + + Write-Line "| ``$platform`` | [$zip]($url) | [![$zip]($badge)]($url)" +} +Write-Line "" + +Write-Line "## Installer Hashes" +Write-Line "" +Write-Line "| Filename | SHA256 Hash" +Write-Line "| --- | ---" +foreach ($file in $files) { + $zip = $file.Name + $hash = Get-FileHash $file -Algorithm SHA256 | Select-Object -ExpandProperty Hash + + Write-Line "| ``$zip`` | ``$hash``" +}