Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
peppekerstens committed Jun 12, 2019
1 parent 303eebe commit 6bb9228
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 70 deletions.
2 changes: 1 addition & 1 deletion BuildHelpers/BuildHelpers.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions BuildHelpers/Public/Get-BuildEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ function Get-BuildEnvironment {
[validateset('object', 'hashtable')]
[string]$As = 'object'
)
$GBVParams = @{Path = $Path}

[System.Collections.ArrayList]$GBVParams

This comment has been minimized.

Copy link
@FISHMANPET

FISHMANPET Jun 12, 2019

I'm fairly sure this won't work, you're creating an arraylist then treating it like a hash table. Additionally GBVParams should contain PATH even if it's not specified. Invoke-Git will assume the PWD if it doesn't get a PATH passed to it and since if no path is specified to this cmdlet, the PWD will be assumed the behavior is probably the same, but it probably makes more sense to stay consistent and be explicit and always pass the path in.

This comment has been minimized.

Copy link
@FISHMANPET

FISHMANPET Jun 12, 2019

At the very least I think to maintain the behavior you're trying here this line should be $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
}
Expand Down
132 changes: 69 additions & 63 deletions BuildHelpers/Public/Get-BuildVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion BuildHelpers/Public/Get-PSModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion BuildHelpers/Public/Get-ProjectName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6bb9228

Please sign in to comment.