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 ba92ca1 commit 54eb553
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 22 deletions.
71 changes: 58 additions & 13 deletions Utils/admin/HOWTO_MAKE_A_RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,85 @@ branch is what's on GitHub and also what's on the PowerShell gallery.

The release candidate is the `devel` branch.

We want to make sure the package version is newer than what is currently
released, and that it matches the latest entry in `CHANGELOG.md`.
#### 2.1. Curate the changelog

```powershell
.\Utils\admin\Test-RscSdkCandidate.ps1
The top entry in `CHANGELOG.md` should say `TBD` :

```markdown
# Changelog

## Version TBD

... changes ...
```

If the version is not set on the package, or if it is not the same as the
latest entry in `CHANGELOG.md`, you need push a new commit to the `devel`
branch with the updated version:
At this point leave the "TBD" as is, we will update it later. Make sure
the content of the last entry is correct. In particular, make sure PR
links are included and that the PRs are closed.

#### 2.2. bump the version

```powershell
.\Utils\admin\Set-RscSdkVersion.ps1 <maj>.<min>
```

Then run `Test-RscSdkCandidate.ps1` again to verify.

Verify also that the latest entry in `CHANGELOG.md` is correct.
and push it to the branch:

```powershell
git commit -a -m "Bump version to <maj>.<min>"
git push
```

#### 2.3. Test the release candidate

We're not running SDK tests here, we are only testing if the package
is well formed.

```powershell
PS > .\Utils\admin\Test-RscSdkCandidate.ps1
version in RubrikSecurityCloud.psd1: 1.11
version in CHANGELOG.md: 1.11
Published on GitHub repo: False
This branch is a candidate for a release.
semanticVersion isPublished versionTag versionEntry
--------------- ----------- ---------- ------------
1.11 False Version_1.11 Version 1.11…
```

### 3. Create a new release

First do a dry run to see what will be released:
We first do a dry run to see if any error occurs during build, tests, packaging,
and commiting to the `main` branch.

```powershell
.\Utils\admin\New-RscSdkRelease.ps1
PS> .\Utils\admin\New-RscSdkRelease.ps1
...
Dry run completed. Local changes were not pushed to the remote repository.
```

If everything looks good, run the script again with the `-NotDryRun` switch:
If no error occured, run the script again with the `-NotDry` switch:

```powershell
.\Utils\admin\New-RscSdkRelease.ps1 -NotDry
```

## Troubleshoting

```powershell
Exception:
Line |
| Remove-Item:
| ..\Utils\Clean-RscSdk.ps1:15 Line
| -Recurse -Force .\Output.Release -ErrorAction Stop
| Access to the path
| '..\Output.Release\...'
| is denied.
```

Part of the release process is to clean up build and output directories,
if you're on Windows and you get this error, it's likely because you have
a PowerShell session or an IDE holding files that the script is
trying to clean up. Close everything and start a new `pwsh.exe` session.
14 changes: 11 additions & 3 deletions Utils/admin/New-RscSdkRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ if ($script:NotDry) {
.\Utils\admin\Publish-RscSdk.ps1
}

# Clean up published artifacts
Remove-Item -Recurse .\Output.Publish\ -Force -ErrorAction SilentlyContinue
git restore .

# Pop back
git checkout $sourceBranch

# Prepare devel branch for further development
Expand All @@ -94,6 +99,9 @@ RunIfNotDry {
}
}

Write-Host "Done." -ForegroundColor Green
Write-Host "git status:"
git status
if ($script:NotDry) {
$DoneMessage = "GitHub Release $versionTag created and published to the PowerShell Gallery."
} else {
$DoneMessage = "Dry run completed. Local changes were not pushed to the remote repository."
}
Write-Host $DoneMessage -ForegroundColor Green
19 changes: 13 additions & 6 deletions Utils/admin/Test-RscSdkCandidate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ if ($versionTag -notmatch "^Version_\d+\.\d+.*$") {
# Check if the version tag matches the module version
$psd1SemanticVersion = (& "$SdkRoot\Utils\Get-RscSdkVersion.ps1")

Write-Host "Version in RubrikSecurityCloud.psd1: " -NoNewline
Write-Host $psd1SemanticVersion -ForegroundColor Cyan
Write-Host "Version in CHANGELOG.md: " -NoNewLine
Write-Host $changelogSemanticVersion -ForegroundColor Cyan

if ( $changelogSemanticVersion -ne $psd1SemanticVersion ) {
Write-Host @"
Expand Down Expand Up @@ -64,22 +69,24 @@ $psd1SemanticVersion
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)) {
$isPublished = -not [string]::IsNullOrEmpty($existingTag)
Write-Host "Published on GitHub repo: " -NoNewline
Write-Host $isPublished -ForegroundColor Cyan
if ( $isPublished ) {
throw "Version tag $versionTag already exists in the GitHub repository."
}

Write-Host "`nThis branch is a candidate for a release." -ForegroundColor Green

[PSCustomObject]@{
semanticVersion = $psd1SemanticVersion
isPublished = $isPublished
versionTag = $versionTag
versionEntry = $versionEntry
semanticVersion = $psd1SemanticVersion
}
2 changes: 2 additions & 0 deletions Utils/admin/Update-RscSdkMainBranch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ try {
}
}
catch {
git reset --hard HEAD
git checkout $sourceBranch
throw "Failed to build the SDK: $($_ | Out-String)"
}

Expand Down

0 comments on commit 54eb553

Please sign in to comment.