Skip to content

Running unit tests for 37/merge by @aldrichtr #18

Running unit tests for 37/merge by @aldrichtr

Running unit tests for 37/merge by @aldrichtr #18

# Github action workflow to run the Pester tests in the Unit directory
name: '[cicd] Run unit tests'
run-name: Running unit tests for ${{ github.ref_name }} by @${{ github.actor }}
on:
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
UnitTest:
name: Run unit tests with Pester
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# Ensure we checkout the buildtools git submodule
submodules: recursive
fetch-depth: 0
- name: Confirm environment
id: confirm-env
shell: pwsh
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
"The current environment:"
Get-ChildItem env:
$githubContext = $env:GITHUB_CONTEXT | ConvertFrom-Json -Depth 32
"$('-' * 78)"
"Github Context:"
$githubContext
"$('-' * 78)"
"Powershell:"
$PSVersionTable
"Module Path"
($env:PSModulePath -split ';')
"Current Directory"
$pwd
- name: Install gitversion
id: install-gitversion
run: |
dotnet tool install --global GitVersion.Tool
- name: Configure the module cache
id: cache-modules
uses: actions/cache@v3
with:
path: C:\Users\runneradmin\Documents\PowerShell\Modules
key: ${{ runner.os }}-${{ hashFiles('**/requirements.psd1') }}
restore-keys: |
${{ runner.os }}-psdepend-
- name: Install PSDepend2 from PSGallery
id: install-psdepend
#! We only need to install this if it wasn't cached previously
if: steps.cache-modules.outputs.cache-hit != 'true'
run: |
$psdependModule = Get-InstalledModule PSDepend2 -ErrorAction SilentlyContinue
if ($null -ne $psdependModule) {
Write-Host "PSDepend2 is already installed"
} else {
Set-PSRepository psgallery -InstallationPolicy trusted
Install-Module PSDepend2 -Scope CurrentUser -Confirm:$false -Force
}
- name: Call PSDepend to install modules
id: invoke-psdepend
if: steps.cache-modules.outputs.cache-hit != 'true'
run: |
Import-Module PSDepend2
Invoke-PSDepend -Path "." -Recurse:$true -Tags 'ci' -Test | Format-Table DependencyName, Version, DependencyType
Invoke-PSDepend -Path "." -Recurse:$true -Confirm:$false -Target 'CurrentUser' -Tags 'ci'
# Run Pester Unit tests after validating the project
- name: Run unit tests
id: unit-tests
run: |
Import-Module ".\source\stitch\stitch.psd1" -Force
Invoke-Build Validate, Test