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-Generate.ps1 entrypoint script for both development and CI environments #27

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 @@ -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

Expand Down
62 changes: 49 additions & 13 deletions src/scripts/ci/Invoke-Generate.ps1
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
46 changes: 0 additions & 46 deletions src/scripts/dev/Invoke-Generate.ps1

This file was deleted.

9 changes: 6 additions & 3 deletions templates/azure-pipelines/entrypoint/generate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
NOTES_PATH: ''
VARIANT: ''
NOTES_PATH: ''

steps:
- pwsh: |
Expand All @@ -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'] }}
9 changes: 6 additions & 3 deletions templates/azure-pipelines/entrypoint/powershell/generate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
NOTES_PATH: ''
VARIANT: ''
NOTES_PATH: ''

steps:
- powershell: |
Expand All @@ -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'] }}
9 changes: 6 additions & 3 deletions templates/azure-pipelines/entrypoint/pwsh/generate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
NOTES_PATH: ''
VARIANT: ''
NOTES_PATH: ''

steps:
- pwsh: |
Expand All @@ -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'] }}
6 changes: 5 additions & 1 deletion test/PSRepositoryReleaseManager.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ foreach ($variant in $ReleaseNotesVariant) {
$env:RELEASE_NOTES_PATH = "$(git rev-parse --show-toplevel)/test/.release-notes.$variant.md"

$cmd = "../src/scripts/ci/Invoke-Generate.ps1"
$cmdArgs=@{}
$cmdArgs=@{
ReleaseTagRef = $env:RELEASE_TAG_REF
ReleaseNotesVariant = $env:RELEASE_NOTES_VARIANT
ReleaseNotesPath = $env:RELEASE_NOTES_PATH
}
$iterations = 1
& $functionTestScriptBlock
}
Expand Down