From 6227fd1a5401fcab0ba8e388507137b0ff6c19cf Mon Sep 17 00:00:00 2001 From: Alphaeus Mote Date: Mon, 28 Apr 2025 20:36:49 -0400 Subject: [PATCH] Add scripts for building and installing from release --- Module/PSProxmox.psd1 | 4 +- Scripts/Install-PSProxmoxFromRelease.ps1 | 48 ++++++++++++++++++++ Scripts/build-release-only.ps1 | 58 ++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 Scripts/Install-PSProxmoxFromRelease.ps1 create mode 100644 Scripts/build-release-only.ps1 diff --git a/Module/PSProxmox.psd1 b/Module/PSProxmox.psd1 index 7f1dd9d..83cd836 100644 --- a/Module/PSProxmox.psd1 +++ b/Module/PSProxmox.psd1 @@ -1,7 +1,7 @@ @{ RootModule = 'PSProxmox.psm1' NestedModules = @('bin\PSProxmox.dll') - ModuleVersion = '2025.04.28.2032' + ModuleVersion = '2025.04.28.2035' GUID = 'd24f0894-3d0c-4ef1-a41e-b273c3db86ad' Author = 'PSProxmox Team' CompanyName = 'PSProxmox' @@ -96,3 +96,5 @@ + + diff --git a/Scripts/Install-PSProxmoxFromRelease.ps1 b/Scripts/Install-PSProxmoxFromRelease.ps1 new file mode 100644 index 0000000..1244df8 --- /dev/null +++ b/Scripts/Install-PSProxmoxFromRelease.ps1 @@ -0,0 +1,48 @@ +# Install-PSProxmoxFromRelease.ps1 +# This script installs the PSProxmox module from the latest release to the user's PowerShell modules directory + +# Set script root path for relative paths +$scriptRoot = $PSScriptRoot +$rootPath = Split-Path -Parent $scriptRoot + +# Define the module name +$moduleName = "PSProxmox" + +# Define the destination path +$modulePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\$moduleName" +if ($PSVersionTable.PSEdition -eq "Core") { + $modulePath = "$env:USERPROFILE\Documents\PowerShell\Modules\$moduleName" +} + +# Get the latest release +$releaseBaseDir = "$rootPath\Release" +$latestRelease = Get-ChildItem -Path $releaseBaseDir -Directory | Sort-Object Name -Descending | Select-Object -First 1 +if (-not $latestRelease) { + Write-Error "No release found in $releaseBaseDir" + exit 1 +} +$releaseDir = $latestRelease.FullName +Write-Host "Installing from release: $($latestRelease.Name)" + +# Create the module directory if it doesn't exist +if (-not (Test-Path -Path $modulePath)) { + New-Item -Path $modulePath -ItemType Directory -Force | Out-Null + Write-Host "Created module directory: $modulePath" +} + +# Create the bin directory if it doesn't exist +if (-not (Test-Path -Path "$modulePath\bin")) { + New-Item -Path "$modulePath\bin" -ItemType Directory -Force | Out-Null + Write-Host "Created bin directory: $modulePath\bin" +} + +# Copy the module files +Copy-Item -Path "$releaseDir\PSProxmox.psd1" -Destination $modulePath -Force +Copy-Item -Path "$releaseDir\PSProxmox.psm1" -Destination $modulePath -Force +Copy-Item -Path "$releaseDir\bin\PSProxmox.dll" -Destination "$modulePath\bin" -Force +Copy-Item -Path "$releaseDir\bin\Newtonsoft.Json.dll" -Destination "$modulePath\bin" -Force +Copy-Item -Path "$rootPath\LICENSE" -Destination $modulePath -Force +Copy-Item -Path "$rootPath\README.md" -Destination $modulePath -Force + +Write-Host "PSProxmox module has been installed to $modulePath" +Write-Host "You can now import the module using: Import-Module $moduleName" diff --git a/Scripts/build-release-only.ps1 b/Scripts/build-release-only.ps1 new file mode 100644 index 0000000..d2501f7 --- /dev/null +++ b/Scripts/build-release-only.ps1 @@ -0,0 +1,58 @@ +# build-release-only.ps1 +# This script builds the PSProxmox module and creates a release package without updating the Module folder + +# Set script root path for relative paths +$scriptRoot = $PSScriptRoot +$rootPath = Split-Path -Parent $scriptRoot + +# Set the version based on the current date and time +$version = Get-Date -Format "yyyy.MM.dd.HHmm" +Write-Host "Building PSProxmox version $version" + +# Update the module version in the PSD1 file +$psd1Path = "$rootPath\Module\PSProxmox.psd1" +$psd1Content = Get-Content -Path $psd1Path -Raw +$psd1Content = $psd1Content -replace "ModuleVersion = '.*'", "ModuleVersion = '$version'" +Set-Content -Path $psd1Path -Value $psd1Content + +# Create the release directory structure +$releaseBaseDir = "$rootPath\Release" +$releaseVersionDir = "$releaseBaseDir\$version" +$releaseBinDir = "$releaseVersionDir\bin" + +# Create directories if they don't exist +if (-not (Test-Path -Path $releaseBaseDir)) { + New-Item -Path $releaseBaseDir -ItemType Directory -Force | Out-Null +} +if (-not (Test-Path -Path $releaseVersionDir)) { + New-Item -Path $releaseVersionDir -ItemType Directory -Force | Out-Null + Write-Host "Created release directory: $releaseVersionDir" +} +if (-not (Test-Path -Path $releaseBinDir)) { + New-Item -Path $releaseBinDir -ItemType Directory -Force | Out-Null + Write-Host "Created bin directory: $releaseBinDir" +} + +# Build the solution directly to the release bin directory +Write-Host "Building solution..." +dotnet build "$rootPath\PSProxmox\PSProxmox.Main.csproj" -c Release -o $releaseBinDir + +# Copy the module files to the release directory +Copy-Item -Path "$rootPath\Module\PSProxmox.psd1" -Destination $releaseVersionDir -Force +Copy-Item -Path "$rootPath\Module\PSProxmox.psm1" -Destination $releaseVersionDir -Force +Copy-Item -Path "$rootPath\LICENSE" -Destination $releaseVersionDir -Force +Copy-Item -Path "$rootPath\README.md" -Destination $releaseVersionDir -Force +Copy-Item -Path "$scriptRoot\Install-PSProxmox.ps1" -Destination $releaseVersionDir -Force + +# Make sure the bin directory exists in the release directory +if (-not (Test-Path -Path "$releaseVersionDir\bin")) { + New-Item -Path "$releaseVersionDir\bin" -ItemType Directory -Force | Out-Null + Write-Host "Created bin directory in release: $releaseVersionDir\bin" +} + +# Create a ZIP file of the release +$zipPath = "$releaseBaseDir\PSProxmox-$version.zip" +Compress-Archive -Path "$releaseVersionDir\*" -DestinationPath $zipPath -Force +Write-Host "Created release package: $zipPath" + +Write-Host "Build completed successfully!"