Skip to content

Commit

Permalink
Merge branch 'master' into fix/PSDriveInPath
Browse files Browse the repository at this point in the history
  • Loading branch information
lipkau committed Jan 3, 2019
2 parents 8e98841 + 614bce2 commit 9cc8a58
Show file tree
Hide file tree
Showing 32 changed files with 725 additions and 392 deletions.
6 changes: 3 additions & 3 deletions Build/psake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ Task Build -Depends Test {
$lines

# Load the module, read the exported functions, update the psd1 FunctionsToExport
Set-ModuleFunctions
Set-ModuleFunction

# Bump the module version if we didn't already
Try
{
[version]$GalleryVersion = Get-NextPSGalleryVersion -Name $env:BHProjectName -ErrorAction Stop
[version]$GalleryVersion = Get-NextNugetPackageVersion -Name $env:BHProjectName -ErrorAction Stop
[version]$GithubVersion = Get-MetaData -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -ErrorAction Stop
if($GalleryVersion -ge $GithubVersion) {
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $GalleryVersion -ErrorAction stop
Expand All @@ -86,4 +86,4 @@ Task Deploy -Depends Build {
Recurse = $false # We keep psdeploy artifacts, avoid deploying those : )
}
Invoke-PSDeploy @Verbose @Params
}
}
6 changes: 3 additions & 3 deletions BuildHelpers/BuildHelpers.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'BuildHelpers.psm1'

# Version number of this module.
ModuleVersion = '1.1.0'
ModuleVersion = '2.0.0'

# ID used to uniquely identify this module
GUID = 'ec079170-28b7-40b4-aaae-f8ebf76850ab'
Expand Down Expand Up @@ -67,7 +67,7 @@ CmdletsToExport = '*'
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = 'Set-BuildVariable'
AliasesToExport = @('Set-BuildVariable', 'Get-NextPSGalleryVersion')

# DSC resources to export from this module
# DscResourcesToExport = @()
Expand Down Expand Up @@ -96,7 +96,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''
ReleaseNotes = "This release will load an external copy of Joel Bennett's Configuration module if we find one on your system, and it is newer than the embedded Configuration module"

} # End of PSData hashtable

Expand Down
63 changes: 49 additions & 14 deletions BuildHelpers/BuildHelpers.psm1
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
#Get public and private function definition files.
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
$ModuleRoot = $PSScriptRoot
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
# $ModuleRoot = $PSScriptRoot

#Dot source the files
Foreach($import in @($Public + $Private))
Foreach($import in @($Public + $Private))
{
Try
{
Try
{
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}

# Load dependencies. TODO: Move to module dependency once the bug that
# causes this is fixed: https://ci.appveyor.com/project/RamblingCookieMonster/buildhelpers/build/1.0.22
# Thanks to Joel Bennett for this!
Import-Module $PSScriptRoot\Private\Modules\Configuration
$fallbackModule = Get-Module -Name $PSScriptRoot\Private\Modules\Configuration -ListAvailable
if ($configModule = Get-Module $fallbackModule.Name -ListAvailable)
{
$configModule |
Where-Object { $_.Version -gt $fallbackModule.Version} |
Sort-Object -Property Version -Descending |
Select-Object -First 1 |
Import-Module -Force
}
if (-not (Get-Module $fallbackModule.Name | Where-Object { $_.Version -gt $fallbackModule.Version}))
{
$fallbackModule | Import-Module -Force
}

Export-ModuleMember -Function $Public.Basename
Export-ModuleMember -Function Get-Metadata, Update-Metadata, Export-Metadata

# Set aliases (#10)
Set-Alias -Name Set-BuildVariable -Value $PSScriptRoot\Scripts\Set-BuildVariable.ps1
Export-ModuleMember -Alias Set-BuildVariable
Set-Alias -Name Get-NextPSGalleryVersion -Value Get-NextNugetPackageVersion
# Backwards compatibilty to command names prior to #72
Set-Alias -Name Get-BuildVariables -Value Get-BuildVariable
Set-Alias -Name Get-ModuleAliases -Value Get-ModuleAlias
Set-Alias -Name Get-ModuleFunctions -Value Get-ModuleFunction
Set-Alias -Name Set-ModuleAliases -Value Set-ModuleAlias
Set-Alias -Name Set-ModuleFormats -Value Set-ModuleFormat
Set-Alias -Name Set-ModuleFunctions -Value Set-ModuleFunction
Set-Alias -Name Set-ModuleTypes -Value Set-ModuleType

$exportModuleMemberSplat = @{
Alias = @(
'Set-BuildVariable'
'Get-NextPSGalleryVersion'
'Get-BuildVariables'
'Get-ModuleAliases'
'Get-ModuleFunctions'
'Set-ModuleAliases'
'Set-ModuleFormats'
'Set-ModuleFunctions'
'Set-ModuleTypes'
)
}
Export-ModuleMember @exportModuleMemberSplat
22 changes: 11 additions & 11 deletions BuildHelpers/Private/Get-InstalledSoftware.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
[Parameter(
Position = 0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false
)]
[ValidateNotNullOrEmpty()]
[Alias('CN','__SERVER','Server','Computer')]
[string[]]$ComputerName = $env:computername,

[string]$DisplayName = $null,

[string]$Publisher = $null
)

Expand All @@ -58,7 +58,7 @@
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"


function Get-SoftwareKeys {
function Get-SoftwareKey {
[cmdletbinding()]
param(
$Reg,
Expand Down Expand Up @@ -89,7 +89,7 @@
foreach($key in $subkeys)
{
#Build the full path to the key for this software
$thisKey = $UninstallKey+"\\"+$key
$thisKey = $UninstallKey+"\\"+$key

#Open the subkey for this software
$thisSubKey = $null
Expand All @@ -101,7 +101,7 @@
{
#Get the display name. If this is not empty we know there is information to show
$dispName = $thisSubKey.GetValue("DisplayName")

#Get the publisher name ahead of time to allow filtering using Publisher parameter
$pubName = $thisSubKey.GetValue("Publisher")

Expand All @@ -119,11 +119,11 @@
DisplayName = $dispname
Publisher = $pubName
Version = $thisSubKey.GetValue("DisplayVersion")
UninstallString = $thisSubKey.GetValue("UninstallString")
UninstallString = $thisSubKey.GetValue("UninstallString")
InstallDate = $thisSubKey.GetValue("InstallDate")
Hive = $Hive
Arch = $Arch
} | select ComputerName, DisplayName, Publisher, Version, Hive, Arch, UninstallString, InstallDate
} | Select-Object ComputerName, DisplayName, Publisher, Version, Hive, Arch, UninstallString, InstallDate
}
}
Catch
Expand Down Expand Up @@ -171,7 +171,7 @@
foreach($uninstallKey in $UninstallKeys)
{
Write-Verbose "Checking [LocalMachine] [$uninstallKey] on [$computer]"
Get-SoftwareKeys -Reg $Reg -UninstallKey $uninstallKey -Hive 'HKLM'
Get-SoftwareKey -Reg $Reg -UninstallKey $uninstallKey -Hive 'HKLM'
}

Try
Expand All @@ -191,8 +191,8 @@
foreach($uninstallKey in $UninstallKeys)
{
Write-Verbose "Checking [CurrentUser] [$uninstallKey] on [$computer]"
Get-SoftwareKeys -Reg $Reg -UninstallKey $uninstallKey -Hive HKCU
Get-SoftwareKey -Reg $Reg -UninstallKey $uninstallKey -Hive HKCU
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
function Get-TeamCityProperties
function Get-TeamCityProperty
{
<#
.SYNOPSIS
Loads TeamCity system build properties into a hashtable
Doesn't do anything if not running under TeamCity
.DESCRIPTION
Teamcity generates a build properties file and stores the location in the environent
variable TEAMCITY_BUILD_PROPERTIES_FILE.
Teamcity generates a build properties file and stores the location in the environent
variable TEAMCITY_BUILD_PROPERTIES_FILE.
Loads the TeamCity system build properties into a hashtable.
.PARAMETER propertiesfile
Path to properties xml file. Defaults to environent
variable TEAMCITY_BUILD_PROPERTIES_FILE.
Path to properties xml file. Defaults to environent
variable TEAMCITY_BUILD_PROPERTIES_FILE.
.NOTES
We assume you are in the project root, for several of the fallback options
.EXAMPLE
Get-TeamCityProperties
Get-TeamCityProperty
.LINK
https://gist.github.com/piers7/6432985
.LINK
Get-BuildVariables
Get-BuildVariable
#>
[OutputType([hashtable])]
param(
Expand All @@ -46,7 +46,7 @@
{
$buildProperties[$entry.Key] = $entry.'#text'
}

Write-Output -InputObject $buildProperties
}
}
10 changes: 5 additions & 5 deletions BuildHelpers/Private/Invoke-LikeFilter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function Invoke-LikeFilter {
[string[]]$FilterArray, # Array of strings to filter on with a -like operator
[switch]$Not # return items that are not -like...
)

if($FilterArray.count -gt 0)
{
Write-Verbose "Running FilterArray [$FilterArray] against [$($Collection.count)] items"
$Collection | Where {
$Collection | Where-Object {
$Status = $False
foreach($item in $FilterArray)
{
Expand All @@ -25,8 +25,8 @@ function Invoke-LikeFilter {
}
elseif($NestedPropertyName)
{
# Code injection, beware...
$Value = Invoke-Expression "`$_.$($NestedPropertyName -join '.')"
$dump = $_
$Value = $NestedPropertyName | Foreach-Object -process {$dump = $dump.$_} -end {$dump}
if($Value -like $item)
{
$Status = $True
Expand Down Expand Up @@ -54,4 +54,4 @@ function Invoke-LikeFilter {
{
$Collection
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Join-Parts {
function Join-Part {
<#
.SYNOPSIS
Join strings with a specified separator.
Expand All @@ -17,24 +17,24 @@ function Join-Parts {
Strings to join
.EXAMPLE
Join-Parts -Separator "/" this //should $Null /work/ /well
Join-Part -Separator "/" this //should $Null /work/ /well
# Output: this/should/work/well
.EXAMPLE
Join-Parts -Parts http://this.com, should, /work/, /wel
Join-Part -Parts http://this.com, should, /work/, /wel
# Output: http://this.com/should/work/wel
.EXAMPLE
Join-Parts -Separator "?" this ?should work ???well
Join-Part -Separator "?" this ?should work ???well
# Output: this?should?work?well
.EXAMPLE
$CouldBeOneOrMore = @( "JustOne" )
Join-Parts -Separator ? -Parts CouldBeOneOrMore
Join-Part -Separator ? -Parts CouldBeOneOrMore
# Output JustOne
Expand All @@ -43,8 +43,8 @@ function Join-Parts {
.NOTES
Credit to Rob C. and Michael S. from this post:
http://stackoverflow.com/questions/9593535/best-way-to-join-parts-with-a-separator-in-powershell
http://stackoverflow.com/questions/9593535/best-way-to-Join-Part-with-a-separator-in-powershell
#>
[cmdletbinding()]
param
Expand All @@ -60,4 +60,4 @@ function Join-Parts {
Foreach-Object { ( [string]$_ ).trim($Separator) } |
Where-Object { $_ }
) -join $Separator
}
}
36 changes: 16 additions & 20 deletions BuildHelpers/Public/Find-NugetPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,30 @@ function Find-NugetPackage
if($IsLatest)
{
Write-Verbose "Searching for latest [$name] module"
$URI = Join-Parts -Separator / -Parts $PackageSourceUrl, "Packages?`$filter=Id eq '$name' and IsLatestVersion"
$URI = Join-Part -Separator / -Parts $PackageSourceUrl, "Packages?`$filter=Id eq '$name' and IsLatestVersion"
}
elseif($PSBoundParameters.ContainsKey($Version))
{
Write-Verbose "Searching for version [$version] of [$name]"
$URI = Join-Parts -Separator / -Parts $PackageSourceUrl, "Packages?`$filter=Id eq '$name' and Version eq '$Version'"
$URI = Join-Part -Separator / -Parts $PackageSourceUrl, "Packages?`$filter=Id eq '$name' and Version eq '$Version'"
}
else
{
Write-Verbose "Searching for all versions of [$name] module"
$URI = Join-Parts -Separator / -Parts $PackageSourceUrl ,"Packages?`$filter=Id eq '$name'"
$URI = Join-Part -Separator / -Parts $PackageSourceUrl ,"Packages?`$filter=Id eq '$name'"
}

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}}
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}}
}
Loading

0 comments on commit 9cc8a58

Please sign in to comment.