mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Update the NuGet package provider when needed (#50759)
* Update the NuGet package provider when needed * Update NuGet provider conditionally
This commit is contained in:
parent
9c35f18dd6
commit
a7528cdd25
2 changed files with 12 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
|||
#!powershell
|
||||
|
||||
# Copyright: (c) 2017, Daniele Lazzari <lazzari@mailup.com>
|
||||
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net>
|
||||
# Copyright: (c) 2017, Daniele Lazzari <lazzari@mailup.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#Requires -Module Ansible.ModuleUtils.Legacy
|
||||
|
@ -18,13 +18,21 @@ $installationpolicy = Get-AnsibleParam -obj $params -name "installation_policy"
|
|||
|
||||
$result = @{"changed" = $false}
|
||||
|
||||
Function Update-NuGetPackageProvider {
|
||||
$PackageProvider = Get-PackageProvider -ListAvailable | Where-Object { ($_.name -eq 'Nuget') -and ($_.version -ge "2.8.5.201") }
|
||||
if ($null -eq $PackageProvider) {
|
||||
Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
$Repo = Get-PSRepository -Name $name -ErrorAction Ignore
|
||||
if ($state -eq "present") {
|
||||
if ($null -eq $Repo){
|
||||
if ($null -eq $Repo) {
|
||||
if ($null -eq $installationpolicy) {
|
||||
$installationpolicy = "trusted"
|
||||
}
|
||||
if (-not $check_mode) {
|
||||
Update-NuGetPackageProvider
|
||||
Register-PSRepository -Name $name -SourceLocation $source -InstallationPolicy $installationpolicy
|
||||
}
|
||||
$result.changed = $true
|
||||
|
@ -42,6 +50,7 @@ if ($state -eq "present") {
|
|||
|
||||
if ($changed_properties.Count -gt 0) {
|
||||
if (-not $check_mode) {
|
||||
Update-NuGetPackageProvider
|
||||
Set-PSRepository -Name $name @changed_properties
|
||||
}
|
||||
$result.changed = $true
|
||||
|
@ -50,6 +59,7 @@ if ($state -eq "present") {
|
|||
}
|
||||
elseif ($state -eq "absent" -and $null -ne $Repo) {
|
||||
if (-not $check_mode) {
|
||||
Update-NuGetPackageProvider
|
||||
Unregister-PSRepository -Name $name
|
||||
}
|
||||
$result.changed = $true
|
||||
|
|
|
@ -13,18 +13,6 @@
|
|||
when: powershell_major_version.stdout | int >= 5
|
||||
block:
|
||||
|
||||
- name: update NuGet version
|
||||
win_shell: |
|
||||
$nuget_exists = (Get-PackageProvider | Where-Object { $_.Name -eq 'Nuget' } | Measure-Object).Count -eq 1
|
||||
|
||||
if ( $nuget_exists ) {
|
||||
$nuget_outdated = (Get-PackageProvider -Name NuGet -ErrorAction Ignore).Version -lt [Version]"2.8.5.201"
|
||||
}
|
||||
|
||||
if ( -not $nuget_exists -or $nuget_outdated ) {
|
||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
|
||||
}
|
||||
|
||||
- name: ensure test repository is deleted
|
||||
win_psrepository:
|
||||
name: '{{ repository_name }}'
|
||||
|
|
Loading…
Reference in a new issue