Skip to content

Commit

Permalink
split Update-RscMainBranch to New-RscSdkRelease
Browse files Browse the repository at this point in the history
  • Loading branch information
guirava committed Mar 22, 2024
1 parent 9837138 commit e36288a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 62 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## Version 0.28

New Features:

- Added pipe support for SLA Cmdlets
[From PR 57](https://github.com/rubrikinc/rubrik-powershell-sdk/pull/57)

Fixes:

- Updated help texts
[From PR 53](https://github.com/rubrikinc/rubrik-powershell-sdk/pull/53)
- Fixed build and tests for PowerShell 5.1

## Version 0.27

Fixes:
Expand Down
88 changes: 88 additions & 0 deletions Utils/New-RscSdkRelease.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<#
.SYNOPSIS
ADMIN USE ONLY. Update the GitHub repo's main branch and create a new release.
.DESCRIPTION
ADMIN USE ONLY: this script updates the GitHub repo and needs to be run by an admin.
Running it as a non-admin will not alter the repository and
will only show what would have been done.
NOTE: This script runs in dry mode by default unless -NotDry is given.
You can safely run New-RscSdkRelease.ps1
to see what would have been done without actually doing it.
This script will:
1. Get the latest changelog entry
2. Run Update-RscSdkMainBranch.ps1 to update the main branch
5. Commit the changes with the latest version entry as the commit message
6. Push the changes to the main branch
7. Create a new GitHub release
.EXAMPLE
.\Utils\New-RscSdkRelease.ps1
#>
param(
[switch]$NotDry = $false
)

function RunIfNotDry {
param(
[ScriptBlock]$CodeBlock
)

# Check if the global variable $NotDry is set and not false
if ($script:NotDry) {
Write-Output "Run: $($CodeBlock.ToString())"
try {
# Execute the script block
& $CodeBlock
}
catch {
throw "Failed to execute $($CodeBlock.ToString()): $_"
}
}
else {
# Print the script block without executing
Write-Output "Dry run: $($CodeBlock.ToString())"
}
}

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

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

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

# Update main branch
$CommitMessage = ""
RunIfNotDry {
$script:CommitMessage = $versionEntry
}
.\Utils\Update-RscSdkMainBranch.ps1 -CommitMessage "$CommitMessage"

# Create a new GitHub release
RunIfNotDry {
gh release create $versionTag -t $versionTag -n "$versionEntry"
}

# Prepare devel branch for further development
RunIfNotDry {
git checkout devel
Set-Location $PSScriptRoot\..
.\Utils\New-RscSdkChangeLogEntry.ps1 -Commit
git push origin devel
}

Write-Host "Done." -ForegroundColor Green
Write-Host "git status:"
git status
76 changes: 14 additions & 62 deletions Utils/Update-RscSdkMainBranch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,23 @@ You can safely run: .\Utils\Update-RscSdkMainBranch.ps1 -SkipBuild
to see what would have been done without actually doing it.
This script will:
1. Check out the main branch
2. Merge the devel branch into main without committing
3. Build the SDK (unless -SkipBuild is given)
4. Get the latest changelog entry
5. Commit the changes with the latest version entry as the commit message
6. Push the changes to the main branch
7. Create a new GitHub release
1. Check out the main branch;
2. Merge the devel branch into main without committing;
3. Build the SDK (unless -SkipBuild is given);
4. If a commit message is given, commit and push the changes to the main branch.
.PARAMETER CommitMessage
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
#>
param(
[switch]$SkipBuild = $false,
[switch]$NotDry = $false
[string]$CommitMessage = ""
)

function RunIfNotDry {
param(
[ScriptBlock]$CodeBlock
)

# Check if the global variable $NotDry is set and not false
if ($script:NotDry) {
Write-Output "Run: $($CodeBlock.ToString())"
try {
# Execute the script block
& $CodeBlock
}
catch {
throw "Failed to execute $($CodeBlock.ToString()): $_"
}
}
else {
# Print the script block without executing
Write-Output "Dry run: $($CodeBlock.ToString())"
}
}

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

Expand Down Expand Up @@ -89,50 +68,23 @@ catch {
throw "Failed to merge 'devel' into 'main'."
}

# Build the SDK
# Build the SDK on the main branch
try {
if (-not $SkipBuild) {
.\Utils\Build-RscSdk.ps1
.\Utils\Build-RscSdk.ps1 -Release
}
}
catch {
throw "Failed to build the SDK."
}

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

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

# Commit changes with the latest version entry as the commit message
git commit -a -m "$versionEntry"

# Push the changes to the main branch
RunIfNotDry {
# Commit and push the changes to the main branch
if ($CommitMessage) {
git commit -a -m "$CommitMessage"
git push origin main
}

# Create a new GitHub release
RunIfNotDry {
gh release create $versionTag -t $versionTag -n "$versionEntry"
}

# Prepare devel branch for further development
RunIfNotDry {
git checkout devel
Set-Location $PSScriptRoot\..
.\Utils\New-RscSdkChangeLogEntry.ps1 -Commit
git push origin devel
}

Write-Host "Done." -ForegroundColor Green
Write-Host "git status:"
git status

0 comments on commit e36288a

Please sign in to comment.