Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
* development:
  (build) Updated module version
  (GH-114) Fix typo
  (GH-114) Skip verifying Pester publisher check
  [#105] Chocolatey params passed in when upgrading a package.
  Choco Run Errors out because of Null Source
  (GH-90) Cache choco list output
  • Loading branch information
pauby committed Nov 13, 2018
2 parents aeb501f + a24523f commit 7113f4c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
5 changes: 3 additions & 2 deletions AppVeyor/AppVeyorInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Write-Host 'Running AppVeyor install script' -ForegroundColor Yellow
#---------------------------------#
# Install NuGet #
#---------------------------------#
Write-Host 'Installing NuGet PackageProvide'
Write-Host 'Installing NuGet PackageProvider'
$pkg = Install-PackageProvider -Name NuGet -Force -ErrorAction Stop
Write-Host "Installed NuGet version '$($pkg.version)'"

Expand All @@ -30,7 +30,8 @@ Write-Host "Installed NuGet version '$($pkg.version)'"
#---------------------------------#
[version]$ScriptAnalyzerVersion = '1.8.1'
Install-Module -Name 'PSScriptAnalyzer' -Repository PSGallery -Force -ErrorAction Stop -MaximumVersion $ScriptAnalyzerVersion
Install-Module -Name 'Pester','xDSCResourceDesigner' -Repository PSGallery -Force -ErrorAction Stop
Install-Module -Name 'Pester' -SkipPublisherCheck -Repository PSGallery -Force -ErrorAction Stop
Install-Module -Name 'xDSCResourceDesigner' -Repository PSGallery -Force -ErrorAction Stop

#---------------------------------#
# Update PSModulePath #
Expand Down
43 changes: 35 additions & 8 deletions DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2017 Chocolatey Software, Inc.
# Copyright (c) 2017 Chocolatey Software, Inc.
# Copyright (c) 2013 - 2017 Lawrence Gripper & original authors/contributors from https://github.com/chocolatey/cChoco
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -69,7 +69,6 @@ function Set-TargetResource
[ValidateNotNullOrEmpty()]
[string]
$Version,
[ValidateNotNullOrEmpty()]
[string]
$Source,
[String]
Expand Down Expand Up @@ -103,7 +102,7 @@ function Set-TargetResource
InstallPackage -pName $Name -pParams $Params -pVersion $Version -pSource $Source -cParams $chocoParams
} elseif ($AutoUpgrade) {
Write-Verbose -Message "Upgrading $Name due to version mis-match"
Upgrade-Package -pName $Name -pParams $Params -pSource $Source
Upgrade-Package -pName $Name -pParams $Params -pSource $Source -cParams $chocoParams
}
}
}
Expand Down Expand Up @@ -134,7 +133,6 @@ function Test-TargetResource
[ValidateNotNullOrEmpty()]
[string]
$Version,
[ValidateNotNullOrEmpty()]
[string]
$Source,
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -167,7 +165,10 @@ function Test-TargetResource
Write-Verbose -Message "Checking if $Name is installed"

if ($AutoUpgrade -and $isInstalled) {
$result = Test-LatestVersionInstalled -pName $Name -pSource $Source
if ($Source){
[string]$pSource = "-pSource `"$Source`""
}
$result = Test-LatestVersionInstalled -pName $Name $pSource
} else {
$result = $isInstalled
}
Expand Down Expand Up @@ -244,6 +245,9 @@ function InstallPackage
$packageInstallOuput = Invoke-Expression -Command "choco install $pName $chocoinstallparams"
Write-Verbose -Message "Package output $packageInstallOuput "

# Clear Package Cache
Get-ChocoInstalledPackage 'Purge'

#refresh path varaible in powershell, as choco doesn"t, to pull in git
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine')
}
Expand Down Expand Up @@ -273,6 +277,9 @@ function UninstallPackage

Write-Verbose -Message "Package uninstall output $packageUninstallOuput "

# Clear Package Cache
Get-ChocoInstalledPackage 'Purge'

#refresh path varaible in powershell, as choco doesn"t, to pull in git
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine')
}
Expand Down Expand Up @@ -314,7 +321,6 @@ Function Test-LatestVersionInstalled {
param(
[Parameter(Mandatory)]
[string]$pName,
[Parameter(Mandatory)]
[string]$pSource
)
Write-Verbose -Message "Testing if $pName can be upgraded"
Expand Down Expand Up @@ -393,10 +399,31 @@ Function Upgrade-Package {

$packageUpgradeOuput = Invoke-Expression -Command $cmd
$packageUpgradeOuput | ForEach-Object { Write-Verbose -Message $_ }

# Clear Package Cache
Get-ChocoInstalledPackage 'Purge'
}

function Get-ChocoInstalledPackage {
Return (choco list -lo -r | ConvertFrom-Csv -Header 'Name', 'Version' -Delimiter "|")
function Get-ChocoInstalledPackage ($action) {
$ChocoInstallLP = Join-Path -Path $env:ChocolateyInstall -ChildPath 'cache'
if ( -not (Test-Path $ChocoInstallLP)){
New-Item -Name 'cache' -Path $env:ChocolateyInstall -ItemType Directory | Out-Null
}
$ChocoInstallList = Join-Path -Path $ChocoInstallLP -ChildPath 'ChocoInstalled.xml'

if ($action -eq 'Purge') {
Remove-Item $ChocoInstallList -Force
$res = $true
} else {
$PackageCacheSec = (Get-Date).AddSeconds('-60')
if ( $PackageCacheSec -lt (Get-Item $ChocoInstallList -ErrorAction SilentlyContinue).LastWriteTime ) {
$res = Import-Clixml $ChocoInstallList
} else {
choco list -lo -r | ConvertFrom-Csv -Header 'Name', 'Version' -Delimiter "|" -OutVariable res | Export-Clixml -Path $ChocoInstallList
}
}

Return $res
}

Export-ModuleMember -Function *-TargetResource
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#---------------------------------#
# environment configuration #
#---------------------------------#
version: 2.3.1.{build}
version: 2.4.0.{build}
os: WMF 5
install:
- ps: . .\AppVeyor\AppVeyorInstall.ps1
Expand Down
2 changes: 1 addition & 1 deletion cChoco.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
CLRVersion = "4.0";
CmdletsToExport = "*";
Author = "Chocolatey Software, Lawrence Gripper, Javy de Koning";
ModuleVersion = "2.3.1.0"
ModuleVersion = "2.4.0.0"
}

0 comments on commit 7113f4c

Please sign in to comment.