Skip to content

Commit

Permalink
Merge pull request #26 from sam-cogan/samcogan/update-023
Browse files Browse the repository at this point in the history
Update to TTK 0.23
  • Loading branch information
sam-cogan authored Oct 5, 2023
2 parents cfda8b3 + dafd340 commit fe503ca
Show file tree
Hide file tree
Showing 17 changed files with 3,455 additions and 1,662 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

name: RunPester
on:
workflow_dispatch:
push:
pull_request:
jobs:
TestPowerShellOnLinux:
runs-on: ubuntu-latest
steps:
- name: InstallPester
id: InstallPester
shell: pwsh
run: |
$Parameters = @{}
$Parameters.PesterMaxVersion = ${env:PesterMaxVersion}
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
}
}
Write-Host "::debug:: InstallPester $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
& './GitHubWorkflow/Steps/InstallPester.ps1' @Parameters
- name: Check out repository
uses: actions/checkout@v2
- name: RunPester
id: RunPester
shell: pwsh
run: |
$Parameters = @{}
$Parameters.ModulePath = ${env:ModulePath}
$Parameters.PesterMaxVersion = ${env:PesterMaxVersion}
foreach ($k in @($parameters.Keys)) {
if ([String]::IsNullOrEmpty($parameters[$k])) {
$parameters.Remove($k)
}
}
Write-Host "::debug:: RunPester $(@(foreach ($p in $Parameters.GetEnumerator()) {'-' + $p.Key + ' ' + $p.Value}) -join ' ')"
& './GitHubWorkflow/Steps/RunPester.ps1' @Parameters
- name: PublishTestResults
uses: actions/upload-artifact@v2
with:
name: PesterResults
path: '**.TestResults.xml'
if: ${{always()}}
env:
ModulePath: .\arm-ttk\arm-ttk.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@{
"runs-on" = "ubuntu-latest"
steps = @('Checkout','CheckoutTTK', 'RunTTK')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@{
"runs-on" = "ubuntu-latest"
steps = @('Checkout','InstallPester', 'RunPester', 'PublishTestResults')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@{
"runs-on" = "ubuntu-latest"
steps = @(
'Checkout',
'AzureLogin',
'UpdateTTKCache'
)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@{
name = 'Checkout TTK'
uses = 'actions/checkout@v2'
id = 'CheckoutTTK'
with = @{
# Exclude = '*.tests.ps1;*.psdevops.ps1'
repository = 'Azure/arm-ttk'
path = 'ttk'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<#
.Synopsis
Installs Pester
.Description
Installs Pester
#>
param(
# The maximum pester version. Defaults to 4.99.99.
[string]
$PesterMaxVersion = '4.99.99'
)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module -Name Pester -Repository PSGallery -Force -Scope CurrentUser -MaximumVersion $PesterMaxVersion -SkipPublisherCheck -AllowClobber
Import-Module Pester -Force -PassThru -MaximumVersion $PesterMaxVersion
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<#
.Synopsis
Runs Pester
.Description
Runs Pester tests after importing a PowerShell module
#>
param(
# The module path. If not provided, will default to the second half of the repository ID.
[string]
$ModulePath,
# The Pester max version. By default, this is pinned to 4.99.99.
[string]
$PesterMaxVersion = '4.99.99'
)

$global:ErrorActionPreference = 'continue'
$global:ProgressPreference = 'silentlycontinue'

$orgName, $moduleName = $env:GITHUB_REPOSITORY -split "/"
if (-not $ModulePath) { $ModulePath = ".\$moduleName.psd1" }
$importedPester = Import-Module Pester -Force -PassThru -MaximumVersion $PesterMaxVersion
$importedModule = Import-Module $ModulePath -Force -PassThru
$importedPester, $importedModule | Out-Host



$result =
Invoke-Pester -PassThru -Verbose -OutputFile ".\$moduleName.TestResults.xml" -OutputFormat NUnitXml `
-CodeCoverage "$($importedModule | Split-Path)\*-*.ps1" -CodeCoverageOutputFile ".\$moduleName.Coverage.xml"

"::set-output name=TotalCount::$($result.TotalCount)",
"::set-output name=PassedCount::$($result.PassedCount)",
"::set-output name=FailedCount::$($result.FailedCount)" | Out-Host
if ($result.FailedCount -gt 0) {
"::debug:: $($result.FailedCount) tests failed"
foreach ($r in $result.TestResult) {
if (-not $r.Passed) {
"::error::$($r.describe, $r.context, $r.name -join ' ') $($r.FailureMessage)"
}
}
throw "::error:: $($result.FailedCount) tests failed"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Import-Module ./ttk/arm-ttk/ -Force -PassThru | Out-Host
Get-ChildItem -Recurse -Filter *.json |
Where-Object Path -notlike '*ttk*' |
Test-AzTemplate
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@{
name = "Update TTK Cache"
uses = "Azure/powershell@v1"
with = @{
"inlineScript" = @'
Get-ChildItem -Recurse -Filter arm-ttk.psd1 | Import-Module -Name { $_.FullName} -Force -PassThru | Out-String
Update-TTKCache
'@
"azPSVersion" = "3.1.0"
}
}
<#
name: Azure PowerShell Action
uses: Azure/powershell@v1
with:
inlineScript: Get-AzVM -ResourceGroupName "< YOUR RESOURCE GROUP >"
azPSVersion: 3.1.0
#>
8 changes: 4 additions & 4 deletions arm-ttk-extension-xplatform/arm-ttk/Test-AzTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,10 @@ Each test script has access to a set of well-known variables:
if ($PSCmdlet.ParameterSetName -eq 'NearbyTemplate') {
# attempt to find one in the current directory and it's subdirectories
$possibleJsonFiles = @(Get-ChildItem -Filter *.json -Recurse |
Sort-Object Name -Descending) <# | # (sort by name descending so that MainTemplate.json comes first).
Where-Object {
'azureDeploy.json', 'mainTemplate.json' -contains $_.Name
})#>
Sort-Object Name -Descending) # | # (sort by name descending so that MainTemplate.json comes first).
# Where-Object {
# 'azureDeploy.json', 'mainTemplate.json' -contains $_.Name
# })


# If more than one template was found, warn which one we'll be testing.
Expand Down
2 changes: 1 addition & 1 deletion arm-ttk-extension-xplatform/arm-ttk/arm-ttk.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = 0.22
ModuleVersion = 0.23
ModuleToProcess = 'arm-ttk.psm1'
Description = 'Validation tools for Azure Resource Manager Templates'
FormatsToProcess = 'arm-ttk.format.ps1xml'
Expand Down
Loading

0 comments on commit fe503ca

Please sign in to comment.