-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
294 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<# | ||
.SYNOPSIS | ||
Updates the latest version entry in the CHANGELOG.md file. | ||
.DESCRIPTION | ||
This script updates the latest version entry in the CHANGELOG.md file. | ||
It takes a -Version parameter, replacing the current version in the first version entry. | ||
For example, if the provided version is '1.10', the latest version entry will be updated to '## Version 1.10'. | ||
.PARAMETER Version | ||
The new version number to set as the latest version entry. | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string]$Version | ||
) | ||
|
||
# Path to CHANGELOG.md | ||
$changelogPath = Join-Path -Path $PSScriptRoot\.. -ChildPath "CHANGELOG.md" | ||
|
||
# Ensure the changelog file exists | ||
if (-not (Test-Path -Path $changelogPath)) { | ||
Write-Error "CHANGELOG.md not found at path: $changelogPath" | ||
return | ||
} | ||
|
||
# Read the changelog file | ||
$changelogContent = Get-Content -Path $changelogPath -Raw | ||
|
||
# Normalize line endings to Unix style | ||
$changelogContent = $changelogContent -replace "`r`n", "`n" | ||
|
||
# Regex to match the latest version entry | ||
$hits = [regex]::Match($changelogContent, "(## Version .+?)(?=`n## Version |$)", 'Singleline') | ||
if ($hits.Success -and $hits.Groups.Count -gt 1) { | ||
$latestVersionTitle = ($hits.Groups[1].Value -split "`n")[0] | ||
Write-Host "latestVersionTitle: $latestVersionTitle" | ||
$newVersionTitle = "## Version $Version" | ||
|
||
# Replace the old version entry with the new version entry in the content | ||
$updatedContent = $changelogContent -replace [regex]::Escape($latestVersionTitle), $newVersionTitle | ||
|
||
# Write the updated content back to CHANGELOG.md | ||
Set-Content -Path $changelogPath -Value $updatedContent.TrimEnd() | ||
|
||
Write-Host "Successfully updated CHANGELOG.md to Version $Version." | ||
} else { | ||
Write-Error "Failed to find the latest version entry in CHANGELOG.md." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string]$NewVersion, | ||
[Parameter(Mandatory = $false)] | ||
[switch]$Force | ||
) | ||
|
||
# Stop on error | ||
$ErrorActionPreference = "Stop" | ||
|
||
# Uncomment this to enable Write-Debug output | ||
# $DebugPreference = "Continue" | ||
|
||
function updateModuleVersion { | ||
|
||
# Path to the PSD1 file | ||
$moduleFile = "$PSScriptRoot\..\RubrikSecurityCloud\RubrikSecurityCloud.PowerShell\RubrikSecurityCloud.psd1" | ||
|
||
# Read the existing psd1 file as text | ||
$psd1Content = Get-Content -Path $ModuleFile -Raw | ||
|
||
# Use regex to find and replace the ModuleVersion value | ||
$updatedContent = $psd1Content -replace 'ModuleVersion\s*=\s*''([^'']+)''', "ModuleVersion = '$NewVersion'" | ||
|
||
# Trim any extra newlines to prevent adding a new line | ||
$updatedContent = $updatedContent.TrimEnd() | ||
|
||
# Save the updated content back to the psd1 file | ||
Set-Content -Path $ModuleFile -Value $updatedContent | ||
|
||
Write-Host "Updated ModuleVersion to $NewVersion in $ModuleFile" | ||
} | ||
|
||
$mainSdkVersion = & "$PSScriptRoot\Test-RscSdkRelease.ps1" | ||
|
||
if ($NewVersion -eq $mainSdkVersion -and -not $Force) { | ||
Write-Host "Error: The new version $NewVersion is the same as the main branch version." -ForegroundColor Red | ||
throw "New version is the same as the main branch version" | ||
} | ||
|
||
# Update PSD file | ||
updateModuleVersion | ||
|
||
# Update CHANGELOG.md | ||
& "$PSScriptRoot\Set-RscSdkLatestChangelog.ps1" -Version $NewVersion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<# | ||
.SYNOPSIS | ||
ADMIN USE ONLY. Test if the SDK is released correctly. (No-op if run as non-admin.) | ||
.DESCRIPTION | ||
ADMIN USE ONLY. (No-op if run as non-admin.) | ||
This script tests if the SDK is released correctly. | ||
The latest published version on The PowerShell Gallery must match: | ||
- The SDK module version on the main branch. | ||
- The latest version tag in the CHANGELOG.md file on the main branch. | ||
- The latest release tag on the GitHub repository. | ||
.OUTPUTS | ||
The published SDK version as a string (example: "1.9") if all | ||
checks pass successfully. Otherwise, an empty string is returned. | ||
#> | ||
[CmdletBinding()] | ||
param() | ||
|
||
# Change to the root of the repository | ||
$originalCwd = $PWD | ||
Set-Location $PSScriptRoot\.. | ||
|
||
# Stop on error | ||
$ErrorActionPreference = "Stop" | ||
|
||
# Uncomment this to enable Write-Debug output | ||
# $DebugPreference = "Continue" | ||
|
||
# Private function to retrieve information from the 'main' branch | ||
function RetrieveMainBranchInfo { | ||
# Store the initial branch to always return to it | ||
$initialBranch = git rev-parse --abbrev-ref HEAD | ||
$mainSdkVersion = "" | ||
try { | ||
# Switch to the main branch | ||
if ( $initialBranch -ne "main" ) { | ||
git checkout main | Out-Null | ||
if ($LASTEXITCODE -ne 0) { | ||
Write-Host "Error: Failed to switch to the 'main' branch." -ForegroundColor Red | ||
throw "Failed to switch to main branch" | ||
} | ||
} | ||
git pull --rebase | Out-Null | ||
if ($LASTEXITCODE -ne 0) { | ||
Write-Host "Error: Failed to pull and rebase on the 'main' branch." -ForegroundColor Red | ||
throw "Failed to pull and rebase" | ||
} | ||
|
||
# Get the SDK version on the main branch | ||
$mainSdkVersion = .\Utils\Get-RscSdkVersion.ps1 | ||
Write-Host "SDK Version on main branch: $mainSdkVersion" -ForegroundColor Blue | ||
|
||
# Get the latest changelog version | ||
$mainChangelogLatestVersionTag = (.\Utils\Get-RscSdkLatestChangelog.ps1).latestVersionTag | ||
Write-Host "Latest version tag from changelog on main branch: $mainChangelogLatestVersionTag" -ForegroundColor Blue | ||
|
||
|
||
# Ensure the changelog version matches the SDK version | ||
$expectedTag = "Version_$mainSdkVersion" | ||
if ($mainChangelogLatestVersionTag -ne $expectedTag) { | ||
Write-Host "Error: Changelog version tag mismatch on main branch." -ForegroundColor Red | ||
Write-Host "Expected: $expectedTag, Found: $mainChangelogLatestVersionTag" -ForegroundColor Red | ||
throw "Changelog version mismatch on main branch" | ||
} | ||
} | ||
finally { | ||
# Switch back to the devel branch, regardless of success or failure | ||
$currentBranch = git rev-parse --abbrev-ref HEAD | ||
if ($currentBranch -ne $initialBranch) { | ||
Write-Host "Switching back to the ' $initialBranch' branch..." | ||
git checkout $initialBranch | Out-Null | ||
if ($LASTEXITCODE -ne 0) { | ||
Write-Host "Error: Failed to switch back to the ' $initialBranch' branch." -ForegroundColor Red | ||
} | ||
} | ||
} | ||
return $mainSdkVersion | ||
} | ||
|
||
function Test-RscSdkRelease { | ||
try { | ||
$statusOutput = git status --porcelain | ||
if ($statusOutput) { | ||
Write-Host "Error: Your working directory has pending changes." -ForegroundColor Red | ||
Write-Host "Please commit, stash, or discard changes before proceeding." -ForegroundColor Red | ||
throw "Pending changes in working directory" | ||
} | ||
|
||
# Get the latest released version from the PowerShell Gallery | ||
Write-Host "Checking latest release from the PowerShell Gallery..." | ||
$moduleInfo = Find-Module -Name RubrikSecurityCloud -Repository PSGallery | ||
if ($moduleInfo) { | ||
$latestGalleryRelease = $moduleInfo.Version | ||
Write-Host "Latest release version from the PowerShell Gallery: $latestGalleryRelease" -ForegroundColor Blue | ||
} | ||
else { | ||
Write-Host "Error: Failed to fetch the latest release from the PowerShell Gallery." -ForegroundColor Red | ||
throw "PowerShell Gallery release fetch failed" | ||
} | ||
|
||
# Get the latest released version from GitHub | ||
Write-Host "Checking latest release from GitHub repository..." | ||
$latestGitHubRelease = gh release view --json tagName --jq '.tagName' | ||
if ($LASTEXITCODE -ne 0) { | ||
Write-Host "Error: Failed to fetch the latest release from GitHub." -ForegroundColor Red | ||
throw "GitHub release fetch failed" | ||
} | ||
Write-Host "Latest release version from GitHub: $latestGitHubRelease" -ForegroundColor Blue | ||
|
||
# Get the SDK version on the main branch | ||
$mainSdkVersion = RetrieveMainBranchInfo | ||
|
||
# Ensure the GitHub latest release matches the main branch SDK version | ||
if ($latestGitHubRelease -ne "Version_$mainSdkVersion") { | ||
Write-Host "Error: Latest GitHub release version does not match the main branch's SDK version." -ForegroundColor Red | ||
Write-Host "Expected: Version_$mainSdkVersion, Found: $latestGitHubRelease" -ForegroundColor Red | ||
throw "GitHub release version mismatch" | ||
} | ||
|
||
# Ensure the PowerShell Gallery latest release matches the main branch SDK version | ||
if ($latestGalleryRelease -ne $mainSdkVersion) { | ||
Write-Host "Error: Latest PowerShell Gallery release version does not match the main branch's SDK version." -ForegroundColor Red | ||
Write-Host "Expected: $mainSdkVersion, Found: $latestGalleryRelease" -ForegroundColor Red | ||
throw "PowerShell Gallery release version mismatch" | ||
} | ||
|
||
} | ||
catch { | ||
Write-Host "An error occurred: $_" -ForegroundColor Red | ||
return "" | ||
} | ||
Write-Host "All checks passed successfully." -ForegroundColor Green | ||
return $mainSdkVersion | ||
} | ||
|
||
# Call the function | ||
Test-RscSdkRelease | ||
|
||
# Return to the original directory | ||
Set-Location $originalCwd |
Oops, something went wrong.