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

Fixed resolving of path to support PSDrives #61

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions BuildHelpers/Private/Get-FullPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function Get-FullPath ([string]$Path) {
# https://github.com/pester/Pester/blob/5796c95e4d6ff5528b8e14865e3f25e40f01bd65/Functions/TestResults.ps1#L13-L27
$Folder = Split-Path -Path $Path -Parent
$File = Split-Path -Path $Path -Leaf
if ( -not ([String]::IsNullOrEmpty($Folder))) {
$FolderResolved = Resolve-Path -Path $Folder
}
else {
$FolderResolved = Resolve-Path -Path $ExecutionContext.SessionState.Path.CurrentFileSystemLocation
}
$Path = Join-Path -Path $FolderResolved.ProviderPath -ChildPath $File

return $Path
}
33 changes: 21 additions & 12 deletions BuildHelpers/Public/Add-TestResultToAppveyor.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Add-TestResultToAppveyor {
function Add-TestResultToAppveyor
{
<#
.SYNOPSIS
Upload test results to AppVeyor
Expand Down Expand Up @@ -27,30 +28,38 @@ function Add-TestResultToAppveyor {

# List of files to be uploaded
[Parameter(Mandatory,
Position,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
ValueFromRemainingArguments
Position,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
ValueFromRemainingArguments
)]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $_ })]
[Alias("FullName")]
[string[]]
$TestFile
)

begin {
$wc = New-Object 'System.Net.WebClient'
begin
{
$wc = New-Object 'System.Net.WebClient'
}

process {
foreach ($File in $TestFile) {
if (Test-Path $File) {
process
{
foreach ($File in $TestFile)
{
$file = Get-FullPath $file
if (Test-Path $File)
{
Write-Verbose "Uploading $File for Job ID: $APPVEYOR_JOB_ID"
$wc.UploadFile("https://ci.appveyor.com/api/testresults/$ResultType/$($APPVEYOR_JOB_ID)", $File)
}
}
}

end {
end
{
$wc.Dispose()
}
}
}
32 changes: 19 additions & 13 deletions BuildHelpers/Public/Find-NugetPackage.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# All credit and major props to Joel Bennett for this simplified solution that doesn't depend on PowerShellGet
# https://gist.github.com/Jaykul/1caf0d6d26380509b04cf4ecef807355
function Find-NugetPackage {
function Find-NugetPackage
{
<#
.SYNOPSIS
Query a Nuget feed for details on a package
Expand Down Expand Up @@ -58,6 +59,7 @@ function Find-NugetPackage {
param(
# The name of a package to find
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
$Name,
# The repository api URL -- like https://www.powershellgallery.com/api/v2/ or https://www.nuget.org/api/v2/
$PackageSourceUrl = 'https://www.powershellgallery.com/api/v2/',
Expand Down Expand Up @@ -86,16 +88,20 @@ function Find-NugetPackage {
}

Invoke-RestMethod $URI |
Select-Object @{n='Name';ex={$_.title.('#text')}},
@{n='Author';ex={$_.author.name}},
@{n='Version';ex={
if($_.properties.NormalizedVersion){
$_.properties.NormalizedVersion
}else{
$_.properties.Version
}
}},
@{n='Uri';ex={$_.Content.src}},
@{n='Description';ex={$_.properties.Description}},
@{n='Properties';ex={$_.properties}}
Select-Object @{n='Name';ex={$_.title.('#text')}},
@{n='Author';ex={$_.author.name}},
@{n='Version';ex={
if($_.properties.NormalizedVersion)
{
$_.properties.NormalizedVersion
}
else
{
$_.properties.Version
}
}
},
@{n='Uri';ex={$_.Content.src}},
@{n='Description';ex={$_.properties.Description}},
@{n='Properties';ex={$_.properties}}
}
5 changes: 3 additions & 2 deletions BuildHelpers/Public/Get-BuildEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function Get-BuildEnvironment {
[cmdletbinding()]
param(
[validatescript({ Test-Path $_ -PathType Container })]
[ValidateNotNullOrEmpty()]
$Path = $PWD.Path,

[string]$BuildOutput = '$ProjectPath\BuildOutput',
Expand All @@ -81,7 +82,7 @@ function Get-BuildEnvironment {
[validateset('object', 'hashtable')]
[string]$As = 'object'
)
$GBVParams = @{Path = $Path}
$GBVParams = @{Path = Get-FullPath $Path}
if($PSBoundParameters.ContainsKey('GitPath'))
{
$GBVParams.add('GitPath', $GitPath)
Expand Down Expand Up @@ -116,4 +117,4 @@ function Get-BuildEnvironment {
if($As -eq 'hashtable') {
return $BuildHelpersVariables
}
}
}
53 changes: 34 additions & 19 deletions BuildHelpers/Public/Get-BuildVariables.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Get-BuildVariables {
function Get-BuildVariables
{
<#
.SYNOPSIS
Normalize build system variables
Expand Down Expand Up @@ -61,20 +62,23 @@ function Get-BuildVariables {
#>
[cmdletbinding()]
param(
[ValidateNotNullOrEmpty()]
$Path = $PWD.Path,

[validatescript({
if(-not (Get-Command $_ -ErrorAction SilentlyContinue))
{
throw "Could not find command at GitPath [$_]"
}
$true
})]
if(-not (Get-Command $_ -ErrorAction SilentlyContinue))
{
throw "Could not find command at GitPath [$_]"
}
$true
})]
$GitPath = 'git'
)

$Path = ( Resolve-Path $Path ).Path
$Path = Get-FullPath $Path
$Environment = Get-Item ENV:
if(!$PSboundParameters.ContainsKey('GitPath')) {
if(!$PSboundParameters.ContainsKey('GitPath'))
{
$GitPath = (Get-Command $GitPath -ErrorAction SilentlyContinue)[0].Path
}

Expand Down Expand Up @@ -117,9 +121,12 @@ function Get-BuildVariables {
}
if(-not $BuildRoot)
{
if ($BuildSystem -eq 'Teamcity') {
if ($BuildSystem -eq 'Teamcity')
{
$BuildRoot = $tcProperties['teamcity.build.checkoutDir']
} else {
}
else
{
# Assumption: this function is defined in a file at the root of the build folder
$BuildRoot = $Path
}
Expand Down Expand Up @@ -149,53 +156,61 @@ function Get-BuildVariables {
# Find the git commit message
$CommitMessage = switch ($Environment.Name)
{
'APPVEYOR_REPO_COMMIT_MESSAGE' {
'APPVEYOR_REPO_COMMIT_MESSAGE'
{
"$env:APPVEYOR_REPO_COMMIT_MESSAGE $env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED".TrimEnd()
break
}
'CI_COMMIT_SHA' {
'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' {
'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' {
'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_SOURCEVERSION' {
'BUILD_SOURCEVERSION'
{
if($WeCanGit)
{
Invoke-Git @IGParams -Arguments "log --format=%B -n 1 $( (Get-Item -Path "ENV:$_").Value )"
break
} # VSTS (https://www.visualstudio.com/en-us/docs/build/define/variables#)
}
'BUILD_VCS_NUMBER' {
'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' {
'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' {
'TRAVIS_COMMIT_MESSAGE'
{
"$env:TRAVIS_COMMIT_MESSAGE"
break
}
Expand Down
5 changes: 3 additions & 2 deletions BuildHelpers/Public/Get-GitChangedFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function Get-GitChangedFile {
[cmdletbinding()]
param(
[validateScript({ Test-Path $_ -PathType Container })]
[ValidateNotNullOrEmpty()]
$Path = $PWD.Path,

$Commit,
Expand All @@ -61,7 +62,7 @@ function Get-GitChangedFile {

[switch]$Resolve
)
$Path = (Resolve-Path $Path).Path
$Path = Get-FullPath $Path
$GitPathRaw = Invoke-Git rev-parse --show-toplevel -Path $Path
Write-Verbose "Found git root [$GitPathRaw]"
$GitPath = Resolve-Path $GitPathRaw
Expand Down Expand Up @@ -112,4 +113,4 @@ function Get-GitChangedFile {
{
Write-Warning "Something went wrong, no files returned:`nIs [$Path], with repo root [$GitPath] a valid git path?"
}
}
}
14 changes: 8 additions & 6 deletions BuildHelpers/Public/Get-ModuleAliases.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Get-ModuleAliases {
function Get-ModuleAliases
{
<#
.SYNOPSIS
List aliases imported by a module
Expand Down Expand Up @@ -27,6 +28,7 @@ function Get-ModuleAliases {
[cmdletbinding()]
param(
[parameter(ValueFromPipeline = $True)]
[ValidateNotNullOrEmpty()]
[Alias('Path')]
[string]$Name
)
Expand All @@ -41,19 +43,19 @@ function Get-ModuleAliases {
$params = @{
Force = $True
Passthru = $True
Name = $Name
Name = Get-FullPath $Name

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this will always be a path, but comment based help could use a tweak to avoid confusion (i.e. it's not either a name or path, it's a path and only a path)?

}

# Create a runspace, add script to run
$PowerShell = [Powershell]::Create()
[void]$PowerShell.AddScript({
Param ($Force, $Passthru, $Name)
Import-Module -Name $Name -PassThru:$Passthru -Force:$Force
Param ($Force, $Passthru, $Name)
Import-Module -Name $Name -PassThru:$Passthru -Force:$Force

}).AddParameters($Params)
}).AddParameters($Params)

( $PowerShell.Invoke() ).ExportedAliases.Keys

$PowerShell.Dispose()
}
}
}
14 changes: 8 additions & 6 deletions BuildHelpers/Public/Get-ModuleFunctions.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Get-ModuleFunctions {
function Get-ModuleFunctions
{
<#
.SYNOPSIS
List functions imported by a module
Expand Down Expand Up @@ -27,6 +28,7 @@ function Get-ModuleFunctions {
[cmdletbinding()]
param(
[parameter(ValueFromPipeline = $True)]
[ValidateNotNullOrEmpty()]
[Alias('Path')]
[string]$Name
)
Expand All @@ -41,19 +43,19 @@ function Get-ModuleFunctions {
$params = @{
Force = $True
Passthru = $True
Name = $Name
Name = Get-FullPath $Name

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - I assume this will always be a path, but comment based help could use a tweak to avoid confusion (i.e. it's not either a name or path, it's a path and only a path)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow.
CBH on Get-FullPath?
Or using a named parameter instead of positioned?

Copy link
Owner

@RamblingCookieMonster RamblingCookieMonster Jun 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry! To clarify, for all of these, they're used with Import-Module -Name - i.e. could be either a Path, or a Name. It really should always be a path in the context of buildhelpers, but comment based help for Name still mentions it: Name or path to module to inspect.

}

# Create a runspace, add script to run
$PowerShell = [Powershell]::Create()
[void]$PowerShell.AddScript({
Param ($Force, $Passthru, $Name)
Import-Module -Name $Name -PassThru:$Passthru -Force:$Force
Param ($Force, $Passthru, $Name)
Import-Module -Name $Name -PassThru:$Passthru -Force:$Force

}).AddParameters($Params)
}).AddParameters($Params)

( $PowerShell.Invoke() ).ExportedFunctions.Keys

$PowerShell.Dispose()
}
}
}
Loading