Skip to content

Commit

Permalink
Enhancement (ci): Use single Invoke-Release.ps1 entrypoint script f…
Browse files Browse the repository at this point in the history
…or both development and CI environments
  • Loading branch information
joeltimothyoh committed May 7, 2024
1 parent fc669ea commit 30da6cb
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 138 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ git tag v1.0.12-beta.1

#### Releases

The entrypoint script [`Invoke-Release.ps1`](src/scripts/dev/Invoke-Release.ps1) can be used to create or simulate the creation of releases for GitHub repositories. Fill in all relevant values pertaining to the release, and if desired, the path to the file containing the release notes to include with it.
The entrypoint script [`Invoke-Release.ps1`](src/scripts/ci/Invoke-Release.ps1) can be used to create or simulate the creation of releases for GitHub repositories. Fill in all relevant values pertaining to the release, and if desired, the path to the file containing the release notes to include with it.

### Continuous Integration

Expand Down
113 changes: 76 additions & 37 deletions src/scripts/ci/Invoke-Release.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
[CmdletBinding()]
param()
[CmdletBinding(DefaultParameterSetName='Path')]
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Namespace
,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Repository
,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$ApiKey
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$TagName
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$Name
,
[Parameter(ParameterSetName='Path', Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
[string]$ReleaseNotesPath
,
[Parameter(ParameterSetName='Content', Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$ReleaseNotesContent
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[bool]$Draft
,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[bool]$Prerelease
,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Asset
)

$ErrorActionPreference = 'Stop'
$ErrorView = 'NormalView'
Expand All @@ -15,22 +56,20 @@ try {
$private:superProjectDir = git rev-parse --show-superproject-working-tree
if (!$private:superProjectDir) { throw "The superproject root directory cannot be determined." }
$private:createReleaseArgs = @{
Namespace = $env:RELEASE_NAMESPACE
Repository = $env:RELEASE_REPOSITORY
ApiKey = $env:GITHUB_API_TOKEN
TagName = $env:RELEASE_TAG_REF
TargetCommitish = git --git-dir "$($private:superProjectDir)/.git" rev-parse $env:RELEASE_TAG_REF
Name = if ($env:RELEASE_NAME) { $env:RELEASE_NAME } else { $env:RELEASE_TAG_REF }
Draft = if ($env:RELEASE_DRAFT) { [System.Convert]::ToBoolean($env:RELEASE_DRAFT) } else { $false }
Prerelease = if ($env:RELEASE_PRERELEASE) { [System.Convert]::ToBoolean($env:RELEASE_PRERELEASE) } else { $false }
Namespace = $Namespace
Repository = $Repository
ApiKey = $ApiKey
TagName = $TagName
TargetCommitish = git --git-dir "$($private:superProjectDir)/.git" rev-parse $TagName
Name = if ($Name) { $Name } else { $TagName }
}
if ($env:RELEASE_NOTES_PATH) {
"Sourcing from specified release notes path '$env:RELEASE_NOTES_PATH'" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesPath'] = if ([System.IO.Path]::IsPathRooted($env:RELEASE_NOTES_PATH)) { $env:RELEASE_NOTES_PATH }
else { "$private:superProjectDir/$env:RELEASE_NOTES_PATH" }
}elseif ($env:RELEASE_NOTES_CONTENT) {
if ($ReleaseNotesPath) {
"Sourcing from specified release notes path '$ReleaseNotesPath'" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesPath'] = if ([System.IO.Path]::IsPathRooted($ReleaseNotesPath)) { $ReleaseNotesPath }
else { "$private:superProjectDir/$ReleaseNotesPath" }
}elseif ($ReleaseNotesContent) {
"Using specified release notes content" | Write-Verbose
$private:createReleaseArgs['ReleaseNotesContent'] = $env:RELEASE_NOTES_CONTENT
$private:createReleaseArgs['ReleaseNotesContent'] = $ReleaseNotesContent
}else {
$private:defaultReleaseNotesPath = "$(git rev-parse --show-toplevel)/.release-notes.md"
if (Test-Path -Path $private:defaultReleaseNotesPath -PathType Leaf) {
Expand All @@ -40,32 +79,32 @@ try {
"Default release notes not found at the path '$private:defaultReleaseNotesPath'. No release notes will be included with the release." | Write-Verbose
}
}
if ($Draft) { $private:createReleaseArgs['Draft'] = $Draft } else { $false }
if ($Prerelease) { $private:createReleaseArgs['Prerelease'] = $Prerelease } else { $false }
$response = Create-GitHubRelease @private:createReleaseArgs
$responseContent = $response.Content | ConvertFrom-Json

# Upload release assets
if ($env:RELEASE_ASSETS) {
try {
$private:releaseAssetsArr = $env:RELEASE_ASSETS -Split "`n" | % { $_.Trim() } | ? { $_ }
"Release assets (Specified):" | Write-Verbose
$private:releaseAssetsArr | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
Push-Location $private:superProjectDir
$private:assets = $private:releaseAssetsArr | % { Resolve-Path -Path $_ }
if (!$private:assets) { throw "No assets of the specified release assets file pattern could be found." }
}catch {
throw
}finally {
Pop-Location
}
"Release assets (Full):" | Write-Verbose
$private:assets | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
$private:uploadReleaseAssetsArgs = @{
UploadUrl = $responseContent.upload_url
Asset = $private:assets
ApiKey = $env:GITHUB_API_TOKEN
}
Upload-GitHubReleaseAsset @private:uploadReleaseAssetsArgs
try {
$private:releaseAssetsArr = $Asset -Split "`n" | % { $_.Trim() } | ? { $_ }
"Release assets (Specified):" | Write-Verbose
$private:releaseAssetsArr | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
Push-Location $private:superProjectDir
$private:assets = $private:releaseAssetsArr | % { Resolve-Path -Path $_ }
if (!$private:assets) { throw "No assets of the specified release assets file pattern could be found." }
}catch {
throw
}finally {
Pop-Location
}
"Release assets (Full):" | Write-Verbose
$private:assets | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
$private:uploadReleaseAssetsArgs = @{
UploadUrl = $responseContent.upload_url
Asset = $private:assets
ApiKey = $ApiKey
}
Upload-GitHubReleaseAsset @private:uploadReleaseAssetsArgs

}catch {
throw
Expand Down
97 changes: 0 additions & 97 deletions src/scripts/dev/Invoke-Release.ps1

This file was deleted.

14 changes: 13 additions & 1 deletion templates/azure-pipelines/entrypoint/powershell/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ steps:
"Namespace: '$env:RELEASE_NAMESPACE'" | Write-Host
"Repository: '$env:RELEASE_REPOSITORY'" | Write-Host
"Tag ref: '$env:RELEASE_TAG_REF'" | Write-Host
$private:releaseArgs = @{
Namespace = $env:RELEASE_NAMESPACE
Repository = $env:RELEASE_REPOSITORY
ApiKey = $env:GITHUB_API_TOKEN
}
if ($env:RELEASE_TAG_REF) { $private:releaseArgs['TagName'] = $env:RELEASE_TAG_REF }
if ($env:RELEASE_NAME) { $private:releaseArgs['Name'] = $env:RELEASE_NAME }
if ($env:RELEASE_NOTES_PATH) { $private:releaseArgs['ReleaseNotesPath'] = $env:RELEASE_NOTES_PATH }
if ($env:RELEASE_NOTES_CONTENT) { $private:releaseArgs['ReleaseNotesContent'] = $env:RELEASE_NOTES_CONTENT }
if ($env:RELEASE_DRAFT) { $private:releaseArgs['Draft'] = [System.Convert]::ToBoolean($env:RELEASE_DRAFT) }
if ($env:RELEASE_PRERELEASE) { $private:releaseArgs['Prerelease'] = [System.Convert]::ToBoolean($env:RELEASE_PRERELEASE) }
if ($env:RELEASE_ASSETS) { $private:releaseArgs['Asset'] = $env:RELEASE_ASSETS }
$VerbosePreference = 'Continue'
.\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Release.ps1 > $null
.\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Release.ps1 @private:releaseArgs > $null
displayName: Create GitHub release
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
env:
Expand Down
14 changes: 13 additions & 1 deletion templates/azure-pipelines/entrypoint/pwsh/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ steps:
"Namespace: '$env:RELEASE_NAMESPACE'" | Write-Host
"Repository: '$env:RELEASE_REPOSITORY'" | Write-Host
"Tag ref: '$env:RELEASE_TAG_REF'" | Write-Host
$private:releaseArgs = @{
Namespace = $env:RELEASE_NAMESPACE
Repository = $env:RELEASE_REPOSITORY
ApiKey = $env:GITHUB_API_TOKEN
}
if ($env:RELEASE_TAG_REF) { $private:releaseArgs['TagName'] = $env:RELEASE_TAG_REF }
if ($env:RELEASE_NAME) { $private:releaseArgs['Name'] = $env:RELEASE_NAME }
if ($env:RELEASE_NOTES_PATH) { $private:releaseArgs['ReleaseNotesPath'] = $env:RELEASE_NOTES_PATH }
if ($env:RELEASE_NOTES_CONTENT) { $private:releaseArgs['ReleaseNotesContent'] = $env:RELEASE_NOTES_CONTENT }
if ($env:RELEASE_DRAFT) { $private:releaseArgs['Draft'] = [System.Convert]::ToBoolean($env:RELEASE_DRAFT) }
if ($env:RELEASE_PRERELEASE) { $private:releaseArgs['Prerelease'] = [System.Convert]::ToBoolean($env:RELEASE_PRERELEASE) }
if ($env:RELEASE_ASSETS) { $private:releaseArgs['Asset'] = $env:RELEASE_ASSETS }
$VerbosePreference = 'Continue'
.\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Release.ps1 > $null
.\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Release.ps1 @private:releaseArgs > $null
displayName: Create GitHub release
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
env:
Expand Down
14 changes: 13 additions & 1 deletion templates/azure-pipelines/entrypoint/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ steps:
"Namespace: '$env:RELEASE_NAMESPACE'" | Write-Host
"Repository: '$env:RELEASE_REPOSITORY'" | Write-Host
"Tag ref: '$env:RELEASE_TAG_REF'" | Write-Host
$private:releaseArgs = @{
Namespace = $env:RELEASE_NAMESPACE
Repository = $env:RELEASE_REPOSITORY
ApiKey = $env:GITHUB_API_TOKEN
}
if ($env:RELEASE_TAG_REF) { $private:releaseArgs['TagName'] = $env:RELEASE_TAG_REF }
if ($env:RELEASE_NAME) { $private:releaseArgs['Name'] = $env:RELEASE_NAME }
if ($env:RELEASE_NOTES_PATH) { $private:releaseArgs['ReleaseNotesPath'] = $env:RELEASE_NOTES_PATH }
if ($env:RELEASE_NOTES_CONTENT) { $private:releaseArgs['ReleaseNotesContent'] = $env:RELEASE_NOTES_CONTENT }
if ($env:RELEASE_DRAFT) { $private:releaseArgs['Draft'] = [System.Convert]::ToBoolean($env:RELEASE_DRAFT) }
if ($env:RELEASE_PRERELEASE) { $private:releaseArgs['Prerelease'] = [System.Convert]::ToBoolean($env:RELEASE_PRERELEASE) }
if ($env:RELEASE_ASSETS) { $private:releaseArgs['Asset'] = $env:RELEASE_ASSETS }
$VerbosePreference = 'Continue'
.\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Release.ps1 > $null
.\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Release.ps1 @private:releaseArgs > $null
displayName: Create GitHub release
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
env:
Expand Down

0 comments on commit 30da6cb

Please sign in to comment.