1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add posibilities to run the integration tests for PowerShell < 5.0 (#50808)

* Add posibilities to run the integration tests for PowerShell < 5.0

* Update of tests - based at a review comments for #50612

* The correction of YAML structure
This commit is contained in:
Wojciech Sciesinski 2019-02-12 21:51:03 +01:00 committed by ansibot
parent a7528cdd25
commit a431e802ed
2 changed files with 77 additions and 16 deletions

View file

@ -44,7 +44,11 @@ options:
type: str type: str
choices: [ trusted, untrusted ] choices: [ trusted, untrusted ]
notes: notes:
- The PowerShellGet module (version 1.6.0 or newer) and the NuGet package provider (version 2.8.5.201 or newer) are required. - PowerShell modules needed
- PowerShellGet >= 1.6.0
- PackageManagement >= 1.1.7
- PowerShell package provider needed
- NuGet >= 2.8.5.201
- See the examples on how to update the NuGet package provider. - See the examples on how to update the NuGet package provider.
- You can not use C(win_psrepository) to re-register (add) removed PSGallery, use the command C(Register-PSRepository -Default) instead. - You can not use C(win_psrepository) to re-register (add) removed PSGallery, use the command C(Register-PSRepository -Default) instead.
seealso: seealso:
@ -53,10 +57,10 @@ author:
- Wojciech Sciesinski (@it-praktyk) - Wojciech Sciesinski (@it-praktyk)
''' '''
EXAMPLES = r''' EXAMPLES = '''
--- ---
- name: Ensure the required NuGet package provider version is installed - name: Ensure the required NuGet package provider version is installed
win_shell: Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force win_shell: Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force
- name: Add a PowerShell module and register a repository - name: Add a PowerShell module and register a repository
win_psrepository: win_psrepository:
@ -70,5 +74,5 @@ EXAMPLES = r'''
state: absent state: absent
''' '''
RETURN = r''' RETURN = '''
''' '''

View file

@ -9,21 +9,78 @@
win_shell: '$PSVersionTable.PSVersion.Major' win_shell: '$PSVersionTable.PSVersion.Major'
register: powershell_major_version register: powershell_major_version
- name: Perform integration tests for Powershell 5+ - name: update PackageManagement and PowerShellGet when PowerShell < 5.0
when: powershell_major_version.stdout | int >= 5 when: powershell_major_version.stdout | int < 5
block: block:
- name: download PackageManagement
win_get_url:
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psmodule/PackageManagement_x64.msi
dest: '{{ win_output_dir }}\PackageManagement_x64.msi'
- name: ensure test repository is deleted - name: install PackageManagement
win_psrepository: win_package:
name: '{{ repository_name }}' path: '{{ win_output_dir }}\PackageManagement_x64.msi'
state: present
- name: create the required folder
win_file:
path: 'C:\Program Files\PackageManagement\ProviderAssemblies'
state: directory
- name: download nuget
win_get_url:
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psmodule/nuget.exe
dest: 'C:\Program Files\PackageManagement\ProviderAssemblies\NuGet-anycpu.exe'
- name: update NuGet provider
win_shell: 'Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies'
- name: download and save the nevest version of the PackageManagement module from PowerShell Gallery
win_shell: 'Save-Module -Name PackageManagement, PowerShellGet -Path {{ win_output_dir }} -Force'
- name: unload PackageManagement and PowerShellGet modules
win_shell: 'Remove-Module -Name PackageManagement,PowerShellGet -Force -ErrorAction Ignore'
ignore_errors: yes
- name: get PSModulePath
win_shell: "$($Env:PSModulePath -Split ';')[0]"
register: psmodulepath
- name: remove older versions of the PackageManagement and PowerShellGet
win_file:
path: "{{ psmodulepath.stdout | trim }}\\{{ item }}"
state: absent state: absent
with_items:
- PackageManagement
- PowerShellGet
- name: run all tests - name: create required folder
include_tasks: tests.yml win_file:
path: "{{ psmodulepath.stdout | trim }}"
state: directory
always: - name: update PowerShellGet and PackageManagement modules
win_shell: 'Copy-Item -Path {{ win_output_dir }}\{{ item }} -Destination {{ psmodulepath.stdout | trim }}\ -Recurse -Force'
with_items:
- PackageManagement
- PowerShellGet
- name: ensure test repository is deleted after tests run - name: update NuGet version
win_psrepository: when: powershell_major_version.stdout | int >= 5
name: '{{ repository_name }}' win_shell: |
state: absent $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 ) {
Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force
}
- name: unregister the repository
win_shell: 'Unregister-PSRepository {{ repository_name | quote }} -ErrorAction Ignore'
changed_when: false
- name: run all tests
include_tasks: tests.yml