diff --git a/README.md b/README.md index b92e8d3..1031d12 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/scripts/ci/Invoke-Release.ps1 b/src/scripts/ci/Invoke-Release.ps1 index c17a492..ffdf368 100644 --- a/src/scripts/ci/Invoke-Release.ps1 +++ b/src/scripts/ci/Invoke-Release.ps1 @@ -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' @@ -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) { @@ -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 diff --git a/src/scripts/dev/Invoke-Release.ps1 b/src/scripts/dev/Invoke-Release.ps1 deleted file mode 100644 index 8c340ec..0000000 --- a/src/scripts/dev/Invoke-Release.ps1 +++ /dev/null @@ -1,97 +0,0 @@ -[CmdletBinding()] -param() - -################################################ - -$private:path = '/path/to/mylocalrepository' -$private:tagName = 'v0.0.0' -$private:myReleaseArgs = @{ - Namespace = 'myusername' - Repository = 'myrepository' - ApiKey = 'myapikey' - TagName = $private:tagName - TargetCommitish = git --git-dir "$private:path/.git" rev-parse $private:tagName - Name = $private:tagName - ReleaseNotesPath = "$private:path/.release-notes.md" - # ReleaseNotesContent = Get-Content "$private:path/.release-notes.md" -Raw - Draft = $false - Prerelease = $false - Assets = @( - # "$private:path/path/to/asset1.tar.gz" - # "$private:path/path/to/asset2.gz" - # "$private:path/path/to/asset3.zip" - # "$private:path/path/to/assets/*.gz" - # "$private:path/path/to/assets/*.zip" - ) -} - -################################################ - -$ErrorActionPreference = 'Stop' -$ErrorView = 'NormalView' -$VerbosePreference = 'Continue' -Set-StrictMode -Version Latest - -try { - Push-Location $PSScriptRoot - Import-Module "$(git rev-parse --show-toplevel)\lib\PSGitHubRestApi\src\PSGitHubRestApi\PSGitHubRestApi.psm1" -Force -Verbose - Import-Module "$(git rev-parse --show-toplevel)\src\PSRepositoryReleaseManager\PSRepositoryReleaseManager.psm1" -Force -Verbose - - # Create GitHub release - $private:createReleaseArgs = @{ - Namespace = $private:myReleaseArgs['Namespace'] - Repository = $private:myReleaseArgs['Repository'] - ApiKey = $private:myReleaseArgs['ApiKey'] - TagName = $private:myReleaseArgs['TagName'] - TargetCommitish = $private:myReleaseArgs['TargetCommitish'] - Name = $private:myReleaseArgs['Name'] - Draft = $private:myReleaseArgs['Draft'] - Prerelease = $private:myReleaseArgs['Prerelease'] - } - if ($private:myReleaseArgs['ReleaseNotesPath']) { - "Sourcing from specified release notes path '$($private:myReleaseArgs['ReleaseNotesPath'])'" | Write-Verbose - $private:createReleaseArgs['ReleaseNotesPath'] = if ([System.IO.Path]::IsPathRooted($private:myReleaseArgs['ReleaseNotesPath'])) { $private:myReleaseArgs['ReleaseNotesPath'] } - else { $private:myReleaseArgs['ReleaseNotesPath'] } - }elseif ($private:myReleaseArgs['ReleaseNotesPath']) { - "Using specified release notes content" | Write-Verbose - $private:createReleaseArgs['ReleaseNotesContent'] = $private:myReleaseArgs['ReleaseNotesPath'] - }else { - $private:defaultReleaseNotesPath = "$(git rev-parse --show-toplevel)/.release-notes.md" - if (Test-Path -Path $private:defaultReleaseNotesPath -PathType Leaf) { - "Sourcing from the default release notes path '$private:defaultReleaseNotesPath'" | Write-Verbose - $private:createReleaseArgs['ReleaseNotesPath'] = $private:defaultReleaseNotesPath - }else { - "Default release notes not found at the path '$private:defaultReleaseNotesPath'. No release notes will be included with the release." | Write-Verbose - } - } - $response = Create-GitHubRelease @private:createReleaseArgs - $responseContent = $response.Content | ConvertFrom-Json - - # Upload release assets - if ($private:myReleaseArgs['Assets']) { - try { - "Release assets (Specified):" | Write-Verbose - $private:myReleaseArgs['Assets'] | Out-String -Stream | % { $_.Trim() } | ? { $_ } | Write-Verbose - Push-Location $private:path - $private:assets = $private:myReleaseArgs['Assets'] | % { 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 = $private:myReleaseArgs['ApiKey'] - } - Upload-GitHubReleaseAsset @private:uploadReleaseAssetsArgs - } - -}catch { - throw -}finally { - Pop-Location -} diff --git a/templates/azure-pipelines/entrypoint/powershell/release.yml b/templates/azure-pipelines/entrypoint/powershell/release.yml index 9010142..bf5c414 100644 --- a/templates/azure-pipelines/entrypoint/powershell/release.yml +++ b/templates/azure-pipelines/entrypoint/powershell/release.yml @@ -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: diff --git a/templates/azure-pipelines/entrypoint/pwsh/release.yml b/templates/azure-pipelines/entrypoint/pwsh/release.yml index 4b24540..52b4db9 100644 --- a/templates/azure-pipelines/entrypoint/pwsh/release.yml +++ b/templates/azure-pipelines/entrypoint/pwsh/release.yml @@ -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: diff --git a/templates/azure-pipelines/entrypoint/release.yml b/templates/azure-pipelines/entrypoint/release.yml index 4b24540..52b4db9 100644 --- a/templates/azure-pipelines/entrypoint/release.yml +++ b/templates/azure-pipelines/entrypoint/release.yml @@ -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: