Skip to content

Commit

Permalink
chore(ci): update tests (#241)
Browse files Browse the repository at this point in the history
- Updates the basic tests to be generic and discoverable for pull requests.
- Tests that the module can be imported and that the manifest is well formed.
- Updated to Pester 5 syntax with detailed output.

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
Ryan Johnson authored Oct 4, 2023
1 parent b506b21 commit 18eb64b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 49 deletions.
42 changes: 0 additions & 42 deletions .github/workflows/ci-module.yml

This file was deleted.

45 changes: 38 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
name: Tests

on:
pull_request:
push:
branches: [develop]
paths:
- "**.psm1"
- "**.psd1"
workflow_dispatch:

jobs:
basic_tests:
strategy:
matrix:
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
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'."
Expand All @@ -30,13 +33,41 @@ jobs:
} 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."
}
Set-PSRepository psgallery -InstallationPolicy trusted
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
shell: pwsh

0 comments on commit 18eb64b

Please sign in to comment.