Skip to content

Commit

Permalink
util script update
Browse files Browse the repository at this point in the history
  • Loading branch information
guirava committed Oct 13, 2024
1 parent 665ec0a commit bffdad7
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
5 changes: 1 addition & 4 deletions Utils/Get-RscSdkVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Change to the root of the repository
Set-Location $PSScriptRoot\..

# Stop on error
$ErrorActionPreference = "Stop"

# Uncomment this to enable Write-Debug output
# $DebugPreference = "Continue"

# Path to the PSD1 file
$moduleFile = ".\RubrikSecurityCloud\RubrikSecurityCloud.PowerShell\RubrikSecurityCloud.psd1"
$moduleFile = "$PSScriptRoot\..\RubrikSecurityCloud\RubrikSecurityCloud.PowerShell\RubrikSecurityCloud.psd1"

$moduleInfo = Import-PowerShellDataFile $moduleFile
return $moduleInfo.ModuleVersion
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[CmdletBinding()]
param()

$changelogPath = Join-Path -Path $PSScriptRoot\.. -ChildPath "CHANGELOG.md"
$changelogPath = Join-Path -Path $PSScriptRoot\..\.. -ChildPath "CHANGELOG.md"
$changelogContent = Get-Content -Path $changelogPath -Raw

# Normalize line endings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ param(
[switch]$Commit = $false
)

$latestVersion = (.\Utils\Get-RscSdkLatestChangelog.ps1).latestVersion
$latestVersion = (& "$PSScriptRoot\Get-RscSdkLatestChangelog.ps1").latestVersion

if ($Version -eq $latestVersion) {
Write-Host "Error: The new version $Version is the same as the latest version." -ForegroundColor Red
throw "New version is the same as the latest version"
}

$body = "`nNew Features:`n`nFixes:`n`nBreaking Changes:`n"
$changelogPath = Join-Path -Path $PSScriptRoot\.. -ChildPath "CHANGELOG.md"
$changelogPath = Join-Path -Path $PSScriptRoot\..\.. -ChildPath "CHANGELOG.md"
$changelogContent = Get-Content -Path $changelogPath -Raw
$changelogContent = $changelogContent -replace "`r`n", "`n"
$changelogContent = $changelogContent -replace "(?<=# Changelog`n)", "`n## Version $Version`n$body"
Set-Content -Path $changelogPath -Value $changelogContent

if ($Commit) {
git add $changelogPath
git commit -m "Update changelog with new version entry"
git commit -m "Update changelog with new entry for version $Version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ if ( -Not $changelogLatest ) {
$versionTag = $changelogLatest.latestVersionTag
$versionEntry = $changelogLatest.latestVersionEntry

# $versionTag must have the format "Version_<integer>.<integer>"
if ($versionTag -notmatch "^Version_\d+\.\d+$") {
# $versionTag must have the format "Version_<integer>.<integer>[<anything>]"
if ($versionTag -notmatch "^Version_\d+\.\d+.*$") {
throw "Latest version in ./CHANGELOG.md is invalid. It must have the format 'Version_<integer>.<integer>'."
}

Expand Down
9 changes: 4 additions & 5 deletions Utils/Publish-RscSdk.ps1 → Utils/admin/Publish-RscSdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ $ErrorActionPreference = "Stop"
# Uncomment this to enable Write-Debug output
# $DebugPreference = "Continue"

# Change to the root of the repository
Set-Location $PSScriptRoot\..
$SdkRoot = Join-Path -Path $PSScriptRoot -ChildPath '..\..' -Resolve

# bail out if not on the main branch
$currentBranch = git rev-parse --abbrev-ref HEAD
if ($currentBranch -ne 'main') {
throw "You are not on the 'main' branch. Current branch is '$currentBranch'."
}

$publishDir = ".\Output.Publish"
$publishDir = "$SdkRoot\Output.Publish"
# bail out if already there
if (Test-Path $publishDir) {
throw "$publishDir already exists. Remove it first."
}

$releaseDir= ".\Output.Release"
$releaseDir= "$SdkRoot\Output.Release"
# bail out if Output.Release is missing
if (-Not (Test-Path $releaseDir)) {
throw "$releaseDir is missing. Run .\Utils\Build-RscSdk.ps1 -Release first."
Expand All @@ -68,7 +67,7 @@ if (-Not $apiKey) {
}

# Assemble the module for publishing
$sdkVersion = .\Utils\Get-RscSdkVersion.ps1
$sdkVersion = (& "$SdkRoot\Utils\Get-RscSdkVersion.ps1")
Write-Host "Publishing version $sdkVersion to the PowerShell Gallery."
New-Item -Path $publishDir -ItemType Directory
$galleryDir = Join-Path $publishDir RubrikSecurityCloud
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ param (
[string]$Version
)

$SdkRoot = Join-Path -Path $PSScriptRoot -ChildPath '..\..' -Resolve

# Path to CHANGELOG.md
$changelogPath = Join-Path -Path $PSScriptRoot\.. -ChildPath "CHANGELOG.md"
$changelogPath = "$SdkRoot\CHANGELOG.md"

# Ensure the changelog file exists
if (-not (Test-Path -Path $changelogPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ $ErrorActionPreference = "Stop"
# Uncomment this to enable Write-Debug output
# $DebugPreference = "Continue"

$SdkRoot = Join-Path -Path $PSScriptRoot -ChildPath '..\..' -Resolve

function updateModuleVersion {

# Path to the PSD1 file
$moduleFile = "$PSScriptRoot\..\RubrikSecurityCloud\RubrikSecurityCloud.PowerShell\RubrikSecurityCloud.psd1"
$moduleFile = "$SdkRoot\RubrikSecurityCloud\RubrikSecurityCloud.PowerShell\RubrikSecurityCloud.psd1"

# Read the existing psd1 file as text
$psd1Content = Get-Content -Path $ModuleFile -Raw
Expand All @@ -31,7 +33,11 @@ function updateModuleVersion {
Write-Host "Updated ModuleVersion to $NewVersion in $ModuleFile"
}

$mainSdkVersion = & "$PSScriptRoot\Test-RscSdkRelease.ps1"
# Before updating the version, check if the new version is the same as the main
# branch version.
# Also, Test-RscSdkRelease will throw an error if the current release
# is corrupted (e.g. the main branch's version is not what's on the gallery).
$mainSdkVersion = & "$SdkRoot\Utils\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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $ErrorActionPreference = "Stop"
# Uncomment this to enable Write-Debug output
# $DebugPreference = "Continue"

$SdkRoot = Join-Path -Path $PSScriptRoot -ChildPath '..\..' -Resolve

# Private function to retrieve information from the 'main' branch
function RetrieveMainBranchInfo {
# Store the initial branch to always return to it
Expand All @@ -48,11 +50,11 @@ function RetrieveMainBranchInfo {
}

# Get the SDK version on the main branch
$mainSdkVersion = .\Utils\Get-RscSdkVersion.ps1
$mainSdkVersion = ( & "$SdkRoot\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
$mainChangelogLatestVersionTag = (& "$PSScriptRoot\Get-RscSdkLatestChangelog.ps1").latestVersionTag
Write-Host "Latest version tag from changelog on main branch: $mainChangelogLatestVersionTag" -ForegroundColor Blue


Expand Down
File renamed without changes.

0 comments on commit bffdad7

Please sign in to comment.