diff --git a/README.md b/README.md index 8f14bbb..cb229cf 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Add a secret variable `GITHUB_API_TOKEN` containing your [GitHub API token](http #### Generating release notes -The entrypoint script [`Invoke-Generate.ps1`](src/scripts/dev/Invoke-Generate.ps1) is used to generate release notes based off local repositories. To generate one, specify the path to the local repository and the variant of release notes to generate. +The entrypoint script [`Invoke-Generate.ps1`](src/scripts/ci/Invoke-Generate.ps1) is used to generate release notes based off local repositories. To generate one, specify the path to the local repository and the variant of release notes to generate. ##### Variants diff --git a/src/scripts/ci/Invoke-Generate.ps1 b/src/scripts/ci/Invoke-Generate.ps1 index fbd2039..39cb857 100644 --- a/src/scripts/ci/Invoke-Generate.ps1 +++ b/src/scripts/ci/Invoke-Generate.ps1 @@ -1,5 +1,37 @@ [CmdletBinding()] -param() +param( + [Parameter(Mandatory=$false)] + [ValidateScript({Test-Path -Path $_ -PathType Container})] + [string]$ProjectDirectory + , + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string]$ReleaseTagRef + , + [Parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [string]$ReleaseNotesVariant + , + [Parameter(Mandatory=$false)] + [ValidateNotNullOrEmpty()] + [string]$ReleaseNotesPath + <# + # Maximum defaults + ./Invoke-Generate.ps1 -ReleaseTagRef v1.0.12 + + # Default -ReleaseNotesVariant and -ReleaseNotesPath + ./Invoke-Generate.ps1 -ProjectDirectory '/path/to/repository' -ReleaseTagRef v1.0.12 + + # Default -ReleaseNotesPath + ./Invoke-Generate.ps1 -ProjectDirectory '/path/to/repository' -ReleaseTagRef v1.0.12 -ReleaseNotesVariant 'Changes-HashSubject-NoMerges' + + # Custom -ReleaseNotesPath relative to -ProjectDirectory + ./Invoke-Generate.ps1 -ProjectDirectory '/path/to/repository' -ReleaseTagRef v1.0.12 -ReleaseNotesVariant 'Changes-HashSubject-NoMerges' -ReleaseNotesPath 'my-custom-release-notes.md' + + # No defaults + ./Invoke-Generate.ps1 -ProjectDirectory '/path/to/repository' -ReleaseTagRef v1.0.12 -ReleaseNotesVariant 'Changes-HashSubject-NoMerges' -ReleaseNotesPath '/path/to/repository/.release-notes.md' + #> +) $ErrorActionPreference = 'Stop' $ErrorView = 'NormalView' @@ -11,22 +43,26 @@ try { Import-Module "$(git rev-parse --show-toplevel)\src\PSRepositoryReleaseManager\PSRepositoryReleaseManager.psm1" -Force -Verbose # Generate release notes - $private:superProjectDir = git rev-parse --show-superproject-working-tree - if ($private:superProjectDir) { - "Using superproject path '$private:ProjectDir'" | Write-Verbose - $private:ProjectDir = $private:superProjectDir + if ($private:ProjectDirectory) { + $private:ProjectDir = $private:ProjectDirectory }else { - $private:ProjectDir = git rev-parse --show-toplevel - "Superproject does not exist. Using project path '$private:ProjectDir'" | Write-Verbose + $private:superProjectDir = git rev-parse --show-superproject-working-tree + if ($private:superProjectDir) { + "Using superproject path '$private:ProjectDir'" | Write-Verbose + $private:ProjectDir = $private:superProjectDir + }else { + $private:ProjectDir = git rev-parse --show-toplevel + "Superproject does not exist. Using project path '$private:ProjectDir'" | Write-Verbose + } } $private:generateArgs = @{ Path = $private:ProjectDir - TagName = $env:RELEASE_TAG_REF - Variant = if ($env:RELEASE_NOTES_VARIANT) { $env:RELEASE_NOTES_VARIANT } else { 'VersionDate-HashSubject-NoMerges' } - ReleaseNotesPath = if ($env:RELEASE_NOTES_PATH) { - "Using specified release notes path '$env:RELEASE_NOTES_PATH'" | Write-Verbose - if ([System.IO.Path]::IsPathRooted($env:RELEASE_NOTES_PATH)) { $env:RELEASE_NOTES_PATH } - else { "$private:ProjectDir/$env:RELEASE_NOTES_PATH" } + TagName = $private:ReleaseTagRef + Variant = if ($private:ReleaseNotesVariant) { $private:ReleaseNotesVariant } else { 'VersionDate-HashSubject-NoMerges' } + ReleaseNotesPath = if ($private:ReleaseNotesPath) { + "Using specified release notes path '$private:ReleaseNotesPath'" | Write-Verbose + if ([System.IO.Path]::IsPathRooted($private:ReleaseNotesPath)) { $private:ReleaseNotesPath } + else { "$private:ProjectDir/$private:ReleaseNotesPath" } }else { $private:defaultReleaseNotesPath = "$(git rev-parse --show-toplevel)/.release-notes.md" "Using the default release notes path '$private:defaultReleaseNotesPath'" | Write-Verbose diff --git a/src/scripts/dev/Invoke-Generate.ps1 b/src/scripts/dev/Invoke-Generate.ps1 deleted file mode 100644 index 46c17fe..0000000 --- a/src/scripts/dev/Invoke-Generate.ps1 +++ /dev/null @@ -1,46 +0,0 @@ -[CmdletBinding()] -param() - -################################################ - -$private:path = '/path/to/mylocalrepository' -$private:myGenerateArgs = @{ - Path = $private:path - TagName = 'v0.0.0' - Variant = 'VersionDate-HashSubject-NoMerges' - ReleaseNotesPath = "$($private:path)/.release-notes.md" -} - -################################################ - -$ErrorActionPreference = 'Stop' -$ErrorView = 'NormalView' -$VerbosePreference = 'Continue' -Set-StrictMode -Version Latest - -try { - Push-Location $PSScriptRoot - Import-Module "$(git rev-parse --show-toplevel)\src\PSRepositoryReleaseManager\PSRepositoryReleaseManager.psm1" -Force -Verbose - - # Generate release notes - $private:generateArgs = @{ - Path = if ($private:myGenerateArgs['Path']) { $private:myGenerateArgs['Path'] } - TagName = if ($private:myGenerateArgs['TagName']) { $private:myGenerateArgs['TagName'] } - Variant = if ($private:myGenerateArgs['Variant']) { $private:myGenerateArgs['Variant'] } else { 'VersionDate-HashSubject-NoMerges' } - ReleaseNotesPath = if ($private:myGenerateArgs['ReleaseNotesPath']) { - "Using specified release notes path '$($private:myGenerateArgs['ReleaseNotesPath'])'" | Write-Verbose - if ([System.IO.Path]::IsPathRooted($private:myGenerateArgs['ReleaseNotesPath'])) { $private:myGenerateArgs['ReleaseNotesPath'] } - else { $private:myGenerateArgs['ReleaseNotesPath'] } - }else { - $private:defaultReleaseNotesPath = "$(git rev-parse --show-toplevel)/.release-notes.md" - "Using the default release notes path '$private:defaultReleaseNotesPath'" | Write-Verbose - $private:defaultReleaseNotesPath - } - } - Generate-ReleaseNotes @private:generateArgs - -}catch { - throw -}finally { - Pop-Location -} diff --git a/templates/azure-pipelines/entrypoint/generate.yml b/templates/azure-pipelines/entrypoint/generate.yml index ac122ef..3aa5e78 100644 --- a/templates/azure-pipelines/entrypoint/generate.yml +++ b/templates/azure-pipelines/entrypoint/generate.yml @@ -1,6 +1,6 @@ parameters: - NOTES_PATH: '' VARIANT: '' + NOTES_PATH: '' steps: - pwsh: | @@ -17,9 +17,12 @@ steps: "Repository: '$env:RELEASE_REPOSITORY'" | Write-Host "Tag ref: '$env:RELEASE_TAG_REF'" | Write-Host $VerbosePreference = 'Continue' - .\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Generate.ps1 + $private:generateArgs = @{ ReleaseTagRef = $env:RELEASE_TAG_REF } + if ($env:RELEASE_NOTES_VARIANT) { $private:generateArgs['ReleaseNotesVariant'] = $env:RELEASE_NOTES_VARIANT } + if ($env:RELEASE_NOTES_PATH) { $private:generateArgs['ReleaseNotesPath'] = $env:RELEASE_NOTES_PATH } + .\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Generate.ps1 @private:generateArgs displayName: Generate release notes condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/')) env: - RELEASE_NOTES_PATH: ${{ parameters['NOTES_PATH'] }} RELEASE_NOTES_VARIANT: ${{ parameters['VARIANT'] }} + RELEASE_NOTES_PATH: ${{ parameters['NOTES_PATH'] }} diff --git a/templates/azure-pipelines/entrypoint/powershell/generate.yml b/templates/azure-pipelines/entrypoint/powershell/generate.yml index 2c371c5..23f02db 100644 --- a/templates/azure-pipelines/entrypoint/powershell/generate.yml +++ b/templates/azure-pipelines/entrypoint/powershell/generate.yml @@ -1,6 +1,6 @@ parameters: - NOTES_PATH: '' VARIANT: '' + NOTES_PATH: '' steps: - powershell: | @@ -17,9 +17,12 @@ steps: "Repository: '$env:RELEASE_REPOSITORY'" | Write-Host "Tag ref: '$env:RELEASE_TAG_REF'" | Write-Host $VerbosePreference = 'Continue' - .\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Generate.ps1 + $private:generateArgs = @{ ReleaseTagRef = $env:RELEASE_TAG_REF } + if ($env:RELEASE_NOTES_VARIANT) { $private:generateArgs['ReleaseNotesVariant'] = $env:RELEASE_NOTES_VARIANT } + if ($env:RELEASE_NOTES_PATH) { $private:generateArgs['ReleaseNotesPath'] = $env:RELEASE_NOTES_PATH } + .\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Generate.ps1 @private:generateArgs displayName: Generate release notes condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/')) env: - RELEASE_NOTES_PATH: ${{ parameters['NOTES_PATH'] }} RELEASE_NOTES_VARIANT: ${{ parameters['VARIANT'] }} + RELEASE_NOTES_PATH: ${{ parameters['NOTES_PATH'] }} diff --git a/templates/azure-pipelines/entrypoint/pwsh/generate.yml b/templates/azure-pipelines/entrypoint/pwsh/generate.yml index ac122ef..3aa5e78 100644 --- a/templates/azure-pipelines/entrypoint/pwsh/generate.yml +++ b/templates/azure-pipelines/entrypoint/pwsh/generate.yml @@ -1,6 +1,6 @@ parameters: - NOTES_PATH: '' VARIANT: '' + NOTES_PATH: '' steps: - pwsh: | @@ -17,9 +17,12 @@ steps: "Repository: '$env:RELEASE_REPOSITORY'" | Write-Host "Tag ref: '$env:RELEASE_TAG_REF'" | Write-Host $VerbosePreference = 'Continue' - .\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Generate.ps1 + $private:generateArgs = @{ ReleaseTagRef = $env:RELEASE_TAG_REF } + if ($env:RELEASE_NOTES_VARIANT) { $private:generateArgs['ReleaseNotesVariant'] = $env:RELEASE_NOTES_VARIANT } + if ($env:RELEASE_NOTES_PATH) { $private:generateArgs['ReleaseNotesPath'] = $env:RELEASE_NOTES_PATH } + .\build\PSRepositoryReleaseManager\src\scripts\ci\Invoke-Generate.ps1 @private:generateArgs displayName: Generate release notes condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/')) env: - RELEASE_NOTES_PATH: ${{ parameters['NOTES_PATH'] }} RELEASE_NOTES_VARIANT: ${{ parameters['VARIANT'] }} + RELEASE_NOTES_PATH: ${{ parameters['NOTES_PATH'] }}