-
Notifications
You must be signed in to change notification settings - Fork 7
73 lines (71 loc) · 3.82 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Tests
on:
push:
branches: [develop]
paths:
- "**.psm1"
- "**.psd1"
workflow_dispatch:
jobs:
basic_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Run Basic Tests
working-directory: ${{ github.workspace }}
shell: pwsh
run: |
Write-Output "INFO: Setting PowerShell Gallery as a trusted repository."
Set-PSRepository psgallery -InstallationPolicy trusted
Write-Output "INFO: Installing module 'VMware.vSphere.SsoAdmin' from PSGallery."
Install-Module -Name VMware.vSphere.SsoAdmin -confirm:$false -Force
$moduleManifest = (Get-ChildItem -Path $env:GITHUB_WORKSPACE -Filter *.psd1).Name
if ($moduleManifest) {
Write-Output "SUCCESS: Manifest '$moduleManifest' found in '$env:GITHUB_WORKSPACE'."
} else {
Write-Output "FAILURE: Manifest not found in '$env:GITHUB_WORKSPACE'."
}
if ($moduleManifest -match '^(.*)\.psd1$') {
$moduleName = $Matches[1]
Write-Output "SUCCESS: Determining module name from manifest'$moduleManifest'."
} else {
Write-Error "FAILED: Determining module name from manifest '$moduleManifest'."
}
Write-Output "INFO: Reading module manifest '$moduleManifest'."
$moduleManifestData = Import-PowerShellDataFile -Path $moduleManifest
$requiredModules = $moduleManifestData.RequiredModules
$requiredModules = $requiredModules | Where-Object { $_.ModuleName -ne 'VMware.vSphere.SsoAdmin' }
Write-Output "INFO: Required modules are $($requiredModules.ModuleName -join ', ')."
foreach ($module in $requiredModules) {
$requiredModuleName = $module.ModuleName
$licenseUri = [System.Uri] (Find-Module -Name $requiredModuleName).LicenseUri
$gitUri = $licenseUri.AbsoluteUri.Split('/blob/')[0].TrimEnd('/') -replace '\.git$'
$requiredModuleFolder = Join-Path -Path $PSScriptRoot -ChildPath "dependencies/$requiredModuleName"
if (-not (Test-Path -Path $requiredModuleFolder -PathType Container)) {
Write-Output "INFO: Cloning module '$requiredModuleName' from '$gitUri' to '$requiredModuleFolder'."
git clone $gitUri $requiredModuleFolder | Out-Null
if (Test-Path -Path $requiredModuleFolder -PathType Container) {
Write-Output "SUCCESS: Module '$requiredModuleName' was cloned."
} else {
Write-Error "FAILED: Module '$requiredModuleName' was not cloned."
}
}
Write-Output "INFO: Importing module '$requiredModuleName' from '$requiredModuleFolder'."
Import-Module -Name (Join-Path -Path $requiredModuleFolder -ChildPath "$requiredModuleName.psd1") -Force
if (Get-Module -Name $requiredModuleName) {
Write-Output "SUCCESS: Module '$requiredModuleName' was imported."
} else {
Write-Error "FAILED: Module '$requiredModuleName' was not imported."
}
}
Write-Output "INFO: Importing module '$moduleName' from '$moduleManifest'."
Import-Module -Name (Resolve-Path $moduleManifest).Path -Force -ErrorAction Stop
if (Get-Module -Name $moduleName) {
Write-Output "SUCCESS: Module '$moduleName' was imported."
} else {
Write-Error "FAILED: Module '$moduleName' was not imported."
}
Write-Output "INFO: Installing module 'Pester' from PSGallery."
Install-Module -Name Pester -confirm:$false -Force
Write-Output "INFO: Invoking Pester tests."
Invoke-Pester -Path "./.ci/pester.tests.ps1" -Output Detailed -PassThru