From 6bb922800367bd2435b821da46cfad142d48c4ee Mon Sep 17 00:00:00 2001 From: Peppe Date: Wed, 12 Jun 2019 08:01:06 +0200 Subject: [PATCH 1/3] fixes #109 and #110 --- BuildHelpers/BuildHelpers.psd1 | 2 +- BuildHelpers/Public/Get-BuildEnvironment.ps1 | 13 +- BuildHelpers/Public/Get-BuildVariable.ps1 | 132 ++++++++++--------- BuildHelpers/Public/Get-PSModuleManifest.ps1 | 4 +- BuildHelpers/Public/Get-ProjectName.ps1 | 5 +- 5 files changed, 86 insertions(+), 70 deletions(-) diff --git a/BuildHelpers/BuildHelpers.psd1 b/BuildHelpers/BuildHelpers.psd1 index 1b83359..a1bf4f6 100644 --- a/BuildHelpers/BuildHelpers.psd1 +++ b/BuildHelpers/BuildHelpers.psd1 @@ -106,7 +106,7 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = "Add support for GitHub Actions, and fix bug in Invoke-Git error handling" + ReleaseNotes = "Peppe Kerstens 6/12//2019: Fixes bug 109 and 110" } # End of PSData hashtable diff --git a/BuildHelpers/Public/Get-BuildEnvironment.ps1 b/BuildHelpers/Public/Get-BuildEnvironment.ps1 index 63cc14a..5baf045 100644 --- a/BuildHelpers/Public/Get-BuildEnvironment.ps1 +++ b/BuildHelpers/Public/Get-BuildEnvironment.ps1 @@ -82,14 +82,19 @@ function Get-BuildEnvironment { [validateset('object', 'hashtable')] [string]$As = 'object' ) - $GBVParams = @{Path = $Path} + + [System.Collections.ArrayList]$GBVParams + if($PSboundParameters.ContainsKey('Path')) { + $GBVParams.Path = ( Resolve-Path $Path ).Path + } + ${Build.ProjectName} = Get-ProjectName @GBVParams + ${Build.ManifestPath} = Get-PSModuleManifest @GBVParams if($PSBoundParameters.ContainsKey('GitPath')) { - $GBVParams.add('GitPath', $GitPath) + $GBVParams.GitPath = $GitPath } ${Build.Vars} = Get-BuildVariable @GBVParams - ${Build.ProjectName} = Get-ProjectName -Path $Path - ${Build.ManifestPath} = Get-PSModuleManifest -Path $Path + if( ${Build.ManifestPath} ) { ${Build.ModulePath} = Split-Path -Path ${Build.ManifestPath} -Parent } diff --git a/BuildHelpers/Public/Get-BuildVariable.ps1 b/BuildHelpers/Public/Get-BuildVariable.ps1 index 2bf79a6..ba4bce7 100644 --- a/BuildHelpers/Public/Get-BuildVariable.ps1 +++ b/BuildHelpers/Public/Get-BuildVariable.ps1 @@ -73,7 +73,10 @@ function Get-BuildVariable { $GitPath = 'git' ) - $Path = ( Resolve-Path $Path ).Path + if($PSboundParameters.ContainsKey('Path')) { + $Path = ( Resolve-Path $Path ).Path + } + $Environment = Get-Item ENV: if(!$PSboundParameters.ContainsKey('GitPath')) { $GitPath = (Get-Command $GitPath -ErrorAction SilentlyContinue)[0].Path @@ -150,73 +153,76 @@ function Get-BuildVariable { } } - # Find the git commit message - $CommitMessage = switch ($Environment.Name) - { - 'APPVEYOR_REPO_COMMIT_MESSAGE' { - "$env:APPVEYOR_REPO_COMMIT_MESSAGE $env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED".TrimEnd() - break - } - 'CI_COMMIT_SHA' { - if($WeCanGit) - { - Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" - break - } # Gitlab 9.0+ - thanks to mipadi http://stackoverflow.com/a/3357357/3067642 - } - 'CI_BUILD_REF' { - if($WeCanGit) - { - Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" - break - } # Gitlab 8.x - thanks to mipadi http://stackoverflow.com/a/3357357/3067642 - } - 'GIT_COMMIT' { - if($WeCanGit) - { - Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" - break - } # Jenkins - thanks to mipadi http://stackoverflow.com/a/3357357/3067642 - } - 'BUILD_SOURCEVERSIONMESSAGE' { #Azure Pipelines, present in classic build pipelines, and all YAML pipelines, but not classic release pipelines - ($env:BUILD_SOURCEVERSIONMESSAGE).split([Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries) -join " " - break - # Azure Pipelines Classic Build & YAML(https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables) - } - 'SYSTEM_DEFAULTWORKINGDIRECTORY' { #Azure Pipelines, this will be triggered in the case of a classic release pipeline - if($WeCanGit) - { - (Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )").split([Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries) -join " " - break - } # Azure Pipelines Classic Release (https://docs.microsoft.com/en-us/azure/devops/pipelines/release/variables) - } - 'BUILD_VCS_NUMBER' { - if($WeCanGit) - { - Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + # Find the git commit message in environment when no path is provided + if(!$PSboundParameters.ContainsKey('Path')) { + $CommitMessage = switch ($Environment.Name) + { + 'APPVEYOR_REPO_COMMIT_MESSAGE' { + "$env:APPVEYOR_REPO_COMMIT_MESSAGE $env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED".TrimEnd() break - } # Teamcity https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters - } - 'BAMBOO_REPOSITORY_REVISION_NUMBER' { - if($WeCanGit) - { - Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + } + 'CI_COMMIT_SHA' { + if($WeCanGit) + { + Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + break + } # Gitlab 9.0+ - thanks to mipadi http://stackoverflow.com/a/3357357/3067642 + } + 'CI_BUILD_REF' { + if($WeCanGit) + { + Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + break + } # Gitlab 8.x - thanks to mipadi http://stackoverflow.com/a/3357357/3067642 + } + 'GIT_COMMIT' { + if($WeCanGit) + { + Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + break + } # Jenkins - thanks to mipadi http://stackoverflow.com/a/3357357/3067642 + } + 'BUILD_SOURCEVERSIONMESSAGE' { #Azure Pipelines, present in classic build pipelines, and all YAML pipelines, but not classic release pipelines + ($env:BUILD_SOURCEVERSIONMESSAGE).split([Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries) -join " " break - } # Bamboo https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html - } - 'TRAVIS_COMMIT_MESSAGE' { - "$env:TRAVIS_COMMIT_MESSAGE" - break - } - 'GITHUB_SHA' { - if($WeCanGit) - { - Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + # Azure Pipelines Classic Build & YAML(https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables) + } + 'AGENT_RELEASEDIRECTORY' { #Azure Pipelines, this will be triggered in the case of a release pipeline + if($WeCanGit) + { + (Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )").split([Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries) -join " " + break + } # Azure Pipelines Release (https://docs.microsoft.com/en-us/azure/devops/pipelines/release/variables) + } + 'BUILD_VCS_NUMBER' { + if($WeCanGit) + { + Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + break + } # Teamcity https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters + } + 'BAMBOO_REPOSITORY_REVISION_NUMBER' { + if($WeCanGit) + { + Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + break + } # Bamboo https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html + } + 'TRAVIS_COMMIT_MESSAGE' { + "$env:TRAVIS_COMMIT_MESSAGE" break - } # GitHub Actions https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables - } + } + 'GITHUB_SHA' { + if($WeCanGit) + { + Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )" + break + } # GitHub Actions https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables + } + } } + #Fall-back on path when nothing is found if(-not $CommitMessage) { if($WeCanGit) diff --git a/BuildHelpers/Public/Get-PSModuleManifest.ps1 b/BuildHelpers/Public/Get-PSModuleManifest.ps1 index cbf394c..27dca7a 100644 --- a/BuildHelpers/Public/Get-PSModuleManifest.ps1 +++ b/BuildHelpers/Public/Get-PSModuleManifest.ps1 @@ -44,7 +44,9 @@ $Path = $PWD.Path ) - $Path = ( Resolve-Path $Path ).Path + if($PSboundParameters.ContainsKey('Path')) { + $Path = ( Resolve-Path $Path ).Path + } $CurrentFolder = Split-Path $Path -Leaf $ExpectedPath = Join-Path -Path $Path -ChildPath $CurrentFolder diff --git a/BuildHelpers/Public/Get-ProjectName.ps1 b/BuildHelpers/Public/Get-ProjectName.ps1 index 6e44d7e..0cd30b2 100644 --- a/BuildHelpers/Public/Get-ProjectName.ps1 +++ b/BuildHelpers/Public/Get-ProjectName.ps1 @@ -45,7 +45,10 @@ function Get-ProjectName $Path = $PWD.Path ) - $Path = ( Resolve-Path $Path ).Path + if($PSboundParameters.ContainsKey('Path')) { + $Path = ( Resolve-Path $Path ).Path + } + $CurrentFolder = Split-Path $Path -Leaf $ExpectedPath = Join-Path -Path $Path -ChildPath $CurrentFolder if(Test-Path $ExpectedPath) From c2c518b9f47d513b5763b71133799d250ec53c24 Mon Sep 17 00:00:00 2001 From: Peppe Date: Wed, 12 Jun 2019 09:28:15 +0200 Subject: [PATCH 2/3] forcing empty array for manipulation --- BuildHelpers/Public/Get-BuildEnvironment.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BuildHelpers/Public/Get-BuildEnvironment.ps1 b/BuildHelpers/Public/Get-BuildEnvironment.ps1 index 5baf045..128946e 100644 --- a/BuildHelpers/Public/Get-BuildEnvironment.ps1 +++ b/BuildHelpers/Public/Get-BuildEnvironment.ps1 @@ -83,7 +83,7 @@ function Get-BuildEnvironment { [string]$As = 'object' ) - [System.Collections.ArrayList]$GBVParams + [System.Collections.ArrayList]$GBVParams = @{} if($PSboundParameters.ContainsKey('Path')) { $GBVParams.Path = ( Resolve-Path $Path ).Path } From dc6d7149c4e933b760214c662dc82a087b626ffa Mon Sep 17 00:00:00 2001 From: Peppe Date: Wed, 12 Jun 2019 10:09:26 +0200 Subject: [PATCH 3/3] wrong typecast..duh! --- BuildHelpers/Public/Get-BuildEnvironment.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BuildHelpers/Public/Get-BuildEnvironment.ps1 b/BuildHelpers/Public/Get-BuildEnvironment.ps1 index 128946e..4495078 100644 --- a/BuildHelpers/Public/Get-BuildEnvironment.ps1 +++ b/BuildHelpers/Public/Get-BuildEnvironment.ps1 @@ -83,7 +83,7 @@ function Get-BuildEnvironment { [string]$As = 'object' ) - [System.Collections.ArrayList]$GBVParams = @{} + [System.Collections.Hashtable]$GBVParams = @{} if($PSboundParameters.ContainsKey('Path')) { $GBVParams.Path = ( Resolve-Path $Path ).Path }