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 bffdad7 commit 5c7948d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 73 deletions.
82 changes: 13 additions & 69 deletions Utils/admin/New-RscSdkRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This script will:
7. Create a new GitHub release
.EXAMPLE
.\Utils\New-RscSdkRelease.ps1
.\Utils\admin\New-RscSdkRelease.ps1
#>
param(
[switch]$NotDry = $false
Expand Down Expand Up @@ -48,75 +48,19 @@ function RunIfNotDry {
}
}

# Change to the root of the repository
Set-Location $PSScriptRoot\..

# bail out if on the main branch
$sourceBranch = git rev-parse --abbrev-ref HEAD
if ($sourceBranch -eq 'main') {
throw "You are on the 'main' branch. Start from the source branch."
}

# Get the latest changelog entry
$changelogScriptPath = ".\Utils\Get-RscSdkLatestChangelog.ps1"
$changelogLatest = & $changelogScriptPath
if ( -Not $changelogLatest ) {
throw "Failed to get the latest changelog entry."
}
$versionTag = $changelogLatest.latestVersionTag
$versionEntry = $changelogLatest.latestVersionEntry

# $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>'."
}

# extract the module version from $versionTag
$changelogSemanticVersion = $versionTag -replace 'Version_', ''

# Check if the version tag matches the module version
$psd1SemanticVersion = (Import-PowerShellDataFile .\RubrikSecurityCloud\RubrikSecurityCloud.PowerShell\RubrikSecurityCloud.psd1).ModuleVersion

if ( $changelogSemanticVersion -ne $psd1SemanticVersion ) {
Write-Host @"
Version mismatch between
$SdkRoot = Join-Path -Path $PSScriptRoot -ChildPath '..\..' -Resolve

./CHANGELOG.md
and
./RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/RubrikSecurityCloud.psd1
The latest entry in ./CHANGELOG.md must have the format "Version M.m",
where "M.m" is the ModuleVersion field in
./RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/RubrikSecurityCloud.psd1 .
./CHANGELOG.md shows:
$changelogSemanticVersion
./RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/RubrikSecurityCloud.psd1 shows:
$psd1SemanticVersion
"@ -ForegroundColor Yellow
throw "Version mismatch. CHANGELOG: $changelogSemanticVersion, psd1: $psd1SemanticVersion."
$candidate = & "$SdkRoot\Utils\admin\Test-RscSdkCandidate.ps1"
if (-Not $candidate) {
throw "Could not gather info about current branch."
}
$versionEntry = $candidate.VersionEntry
$versionTag = $candidate.VersionTag

Write-Host "Latest version tag: " -NoNewline
Write-Host $versionTag -ForegroundColor Cyan
Write-Host "Latest version entry:"
Write-Host $versionEntry -ForegroundColor Cyan
# Change to the root of the repository
Set-Location $SdkRoot

# Make sure this version tag is not already published:
$existingTag = gh release list --json tagName --jq ".[] | select(.tagName == `"$versionTag`")"
if ($null -ne $existingTag) {
$existingTag = $existingTag.Trim()
}
if ( -not [string]::IsNullOrEmpty($existingTag)) {
throw "Version tag $versionTag already exists in the GitHub repository."
}
$sourceBranch = git rev-parse --abbrev-ref HEAD

# Update main branch
$CommitMessage = ""
Expand All @@ -125,7 +69,7 @@ RunIfNotDry {
}

# Passing an empty CommitMessage makes it a dry run
.\Utils\Update-RscSdkMainBranch.ps1 -CommitMessage "$CommitMessage" -StayOnMain
.\Utils\admin\Update-RscSdkMainBranch.ps1 -CommitMessage "$CommitMessage" -StayOnMain

# Create a new GitHub release
RunIfNotDry {
Expand All @@ -144,8 +88,8 @@ git checkout $sourceBranch
# Prepare devel branch for further development
RunIfNotDry {
if ($sourceBranch -eq 'devel') {
Set-Location $PSScriptRoot\..
.\Utils\New-RscSdkChangeLogEntry.ps1 -Commit
Set-Location $PSScriptRoot\..\..
.\Utils\admin\New-RscSdkChangeLogEntry.ps1 -Commit
git push origin devel
}
}
Expand Down
4 changes: 2 additions & 2 deletions Utils/admin/Set-RscSdkVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function updateModuleVersion {
# 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"
$mainSdkVersion = & "$SdkRoot\Utils\admin\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 All @@ -48,4 +48,4 @@ if ($NewVersion -eq $mainSdkVersion -and -not $Force) {
updateModuleVersion

# Update CHANGELOG.md
& "$PSScriptRoot\Set-RscSdkLatestChangelog.ps1" -Version $NewVersion
& "$SdkRoot\Utils\admin\Set-RscSdkLatestChangelog.ps1" -Version $NewVersion
85 changes: 85 additions & 0 deletions Utils/admin/Test-RscSdkCandidate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<#
.SYNOPSIS
Test if the current branch could be a candidate for a release.
.DESCRIPTION
Checks that:
- The current branch is not the 'main' branch.
- The latest version tag in the CHANGELOG.md file matches the module version in the psd1 file.
- The version tag is not already published on the GitHub repository.
- The version tag has the format "Version_<integer>.<integer>[<anything>]".
#>

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

# bail out if on the main branch
$sourceBranch = git rev-parse --abbrev-ref HEAD
if ($sourceBranch -eq 'main') {
throw "You are on the 'main' branch. Start from the source branch."
}

# Get the latest changelog entry
$changelogLatest = & "$SdkRoot\Utils\admin\Get-RscSdkLatestChangelog.ps1"
if ( -Not $changelogLatest ) {
throw "Failed to get the latest changelog entry."
}
$versionTag = $changelogLatest.latestVersionTag
$versionEntry = $changelogLatest.latestVersionEntry

# extract the module version from $versionTag
$changelogSemanticVersion = $versionTag -replace 'Version_', ''

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

# Check if the version tag matches the module version
$psd1SemanticVersion = (& "$SdkRoot\Utils\Get-RscSdkVersion.ps1")

if ( $changelogSemanticVersion -ne $psd1SemanticVersion ) {
Write-Host @"
Version mismatch between
./CHANGELOG.md
and
./RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/RubrikSecurityCloud.psd1
The latest entry in ./CHANGELOG.md must have the format "Version M.m",
where "M.m" is the ModuleVersion field in
./RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/RubrikSecurityCloud.psd1 .
./CHANGELOG.md shows:
$changelogSemanticVersion
./RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/RubrikSecurityCloud.psd1 shows:
$psd1SemanticVersion
"@ -ForegroundColor Yellow
throw "Version mismatch. CHANGELOG: $changelogSemanticVersion, psd1: $psd1SemanticVersion."
}

Write-Host "Latest version tag: " -NoNewline
Write-Host $versionTag -ForegroundColor Cyan
Write-Host "Latest version entry:"
Write-Host $versionEntry -ForegroundColor Cyan

# Make sure this version tag is not already published:
$existingTag = gh release list --json tagName --jq ".[] | select(.tagName == `"$versionTag`")"
if ($null -ne $existingTag) {
$existingTag = $existingTag.Trim()
}
if ( -not [string]::IsNullOrEmpty($existingTag)) {
throw "Version tag $versionTag already exists in the GitHub repository."
}

[PSCustomObject]@{
versionTag = $versionTag
versionEntry = $versionEntry
semanticVersion = $psd1SemanticVersion
}
4 changes: 2 additions & 2 deletions Utils/admin/Update-RscSdkMainBranch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If not given, the script will not commit or push the changes to the main branch,
so it is effectively a dry run.
.EXAMPLE
.\Utils\Update-RscSdkMainBranch.ps1 -SkipBuild
.\Utils\admin\Update-RscSdkMainBranch.ps1 -SkipBuild
#>
param(
[switch]$SkipBuild = $false,
Expand All @@ -30,7 +30,7 @@ param(
)

# Change to the root of the repository
Set-Location $PSScriptRoot\..
Set-Location $PSScriptRoot\..\..

# Check for a clean repo
$gitStatus = git status --porcelain
Expand Down

0 comments on commit 5c7948d

Please sign in to comment.