From ad693cedcd6063ecd01d92fbc504fd1e05da506f Mon Sep 17 00:00:00 2001 From: GraceSolutions Date: Mon, 14 Apr 2025 23:36:50 -0400 Subject: [PATCH] Add script to create releases and clean up old zip files --- scripts/Create-Release.ps1 | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 scripts/Create-Release.ps1 diff --git a/scripts/Create-Release.ps1 b/scripts/Create-Release.ps1 new file mode 100644 index 0000000..8f1271f --- /dev/null +++ b/scripts/Create-Release.ps1 @@ -0,0 +1,92 @@ +# Create-Release.ps1 +# This script creates a new release of the PSOPNSenseAPI module + +# Get the current date and time in the format yyyy.MM.dd.HHmm +$version = Get-Date -Format "yyyy.MM.dd.HHmm" + +# Update the version in the project file +$projectFile = "src\PSOPNSenseAPI\PSOPNSenseAPI.csproj" +$projectContent = Get-Content $projectFile +$projectContent = $projectContent -replace ".*", "$version" +Set-Content $projectFile $projectContent + +# Update the version in the module manifest files +$sourcePsd1 = "src\PSOPNSenseAPI\PSOPNSenseAPI.psd1" +$sourcePsd1Content = Get-Content $sourcePsd1 +$sourcePsd1Content = $sourcePsd1Content -replace "ModuleVersion = '.*'", "ModuleVersion = '$version'" +Set-Content $sourcePsd1 $sourcePsd1Content + +$outputPsd1 = "output\PSOPNSenseAPI\PSOPNSenseAPI.psd1" +$outputPsd1Content = Get-Content $outputPsd1 +$outputPsd1Content = $outputPsd1Content -replace "ModuleVersion = '.*'", "ModuleVersion = '$version'" +Set-Content $outputPsd1 $outputPsd1Content + +# Build the project +dotnet build -c Release + +# Copy the DLLs to the output folder +$libPath = "output\PSOPNSenseAPI\lib-new" +New-Item -Path $libPath -ItemType Directory -Force | Out-Null +Copy-Item -Path "src\PSOPNSenseAPI\bin\Release\net472\*.dll" -Destination $libPath +Remove-Item -Path "output\PSOPNSenseAPI\lib" -Recurse -Force -ErrorAction SilentlyContinue +Rename-Item -Path $libPath -NewName "lib" + +# Create a release archive +$zipFile = "output\PSOPNSenseAPI-$version.zip" +Compress-Archive -Path "output\PSOPNSenseAPI\*" -DestinationPath $zipFile -Force + +# Clean up old zip files +Get-ChildItem -Path "output" -Filter "*.zip" | + Where-Object { $_.Name -ne "PSOPNSenseAPI-$version.zip" } | + Remove-Item -Force + +# Commit the changes +git add . +git commit -m "Update version to $version" +git push origin main + +# Create a GitHub release +Write-Host "To create a GitHub release, go to https://github.com/freedbygrace/PSOPNSenseAPI/releases/new" +Write-Host "Tag version: v$version" +Write-Host "Release title: v$version" +Write-Host "Description: See CHANGELOG.md for details" +Write-Host "Attach the file: $zipFile" + +# Create a release note file +$releaseNotes = @" +# Release v$version + +## What's New + +See [CHANGELOG.md](CHANGELOG.md) for details. + +## Installation + +1. Download the release from the GitHub releases page: https://github.com/freedbygrace/PSOPNSenseAPI/releases/tag/v$version +2. Extract the zip file to a folder in your PowerShell module path +3. Import the module: `Import-Module PSOPNSenseAPI` + +## Usage + +```powershell +# Connect to the OPNSense firewall +Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck + +# Get the interfaces +Get-OPNSenseInterface + +# Disconnect from the firewall +Disconnect-OPNSense +``` + +For more examples, see the documentation in the `docs` folder. +"@ + +Set-Content -Path "RELEASE.md" -Value $releaseNotes + +# Commit the release notes +git add RELEASE.md +git commit -m "Add release notes for v$version" +git push origin main + +Write-Host "Release created successfully!"