Skip to content

Commit

Permalink
Enhancement (ci): Use single Invoke-Generate.ps1 entrypoint script …
Browse files Browse the repository at this point in the history
…for both development and CI environments
  • Loading branch information
joeltimothyoh committed May 4, 2024
1 parent 47fa26c commit 9d10e9d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 69 deletions.
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'] }}

0 comments on commit 9d10e9d

Please sign in to comment.