Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement (ci): Use single Invoke-Release.ps1 entrypoint script for both development and CI environments #29

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. Simply specify the 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
79 changes: 60 additions & 19 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=$false)]
[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,13 +79,15 @@ 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) {
if ($Asset) {
try {
$private:releaseAssetsArr = $env:RELEASE_ASSETS -Split "`n" | % { $_.Trim() } | ? { $_ }
$private:releaseAssetsArr = $Asset -Split "`n" | % { $_.Trim() } | ? { $_ }
"Release assets (Specified):" | Write-Verbose
$private:releaseAssetsArr | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose
Push-Location $private:superProjectDir
Expand All @@ -62,7 +103,7 @@ try {
$private:uploadReleaseAssetsArgs = @{
UploadUrl = $responseContent.upload_url
Asset = $private:assets
ApiKey = $env:GITHUB_API_TOKEN
ApiKey = $ApiKey
}
Upload-GitHubReleaseAsset @private:uploadReleaseAssetsArgs
}
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