-
Notifications
You must be signed in to change notification settings - Fork 377
/
action.yml
123 lines (104 loc) · 5.22 KB
/
action.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#########################################################
## 'Validate module with Pester' Composite Action ##
#########################################################
##
## This composite action contains the logic to validate a module using a set of Pester tests
##
#########################################################
##
##-------------------------------------------##
## ACTION PARAMETERS ##
##-------------------------------------------##
##
## |===========================================================================================================================================================|
## | Parameter | Required | Default | Description | Example |
## |--------------------------|----------|---------|--------------------------------------|--------------------------------------------------------------------|
## | modulePath | true | '' | The path to the module's folder | 'modules/api-management/service' |
## | moduleTestFilePath | true | '' | The path to the module Pester tests. | 'utilities/pipelines/staticValidation/compliance/module.tests.ps1' |
## |===========================================================================================================================================================|
##
##---------------------------------------------##
name: "Execute Pester module tests"
description: "Execute Pester module tests (if any)"
inputs:
modulePath:
description: "The path to the module's folder"
required: true
default: ""
moduleTestFilePath:
description: "The path to the test file"
required: true
default: "utilities/pipelines/staticValidation/compliance/module.tests.ps1"
runs:
using: "composite"
steps:
# [Module Pester Test] task(s)
#-----------------------------
- name: "Run Pester tests"
id: pester_run_step
shell: pwsh
run: |
# Grouping task logs
Write-Output '::group::Run Pester tests'
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'staticValidation' 'compliance' 'Set-PesterGitHubOutput.ps1')
# Set repo root path
$repoRootPath = $env:GITHUB_WORKSPACE
# Set test input module path
$moduleFolderPaths = @(Join-Path $repoRootPath "${{ inputs.modulePath }}")
$moduleFolderPaths += (Get-ChildItem $moduleFolderPaths -Recurse -Directory -Force).FullName | Where-Object {
(Get-ChildItem $_ -File -Depth 0 -Include @('main.json', 'main.bicep') -Force).Count -gt 0
}
Write-Verbose 'Execute tests in path(s):' -Verbose
foreach ($moduleFolderPath in $moduleFolderPaths) {
Write-Verbose "- [$moduleFolderPath]" -Verbose
}
# --------------------- #
# Invoke Pester test(s) #
# --------------------- #
$testFiles = @(
(Join-Path $repoRootPath '${{ inputs.moduleTestFilePath }}'), # AVM Compliance Tests
(Join-Path "${{ inputs.modulePath }}" 'tests' 'unit') # Custom Unit Tests
)
$pesterConfiguration = @{
Run = @{
Container = New-PesterContainer -Path $testFiles -Data @{
moduleFolderPaths = $moduleFolderPaths
RepoRootPath = $env:GITHUB_WORKSPACE
}
PassThru = $true
}
Output = @{
Verbosity = 'Detailed'
}
}
Write-Verbose 'Invoke test with' -Verbose
Write-Verbose ($pesterConfiguration | ConvertTo-Json -Depth 4 | Out-String) -Verbose
$testResults = Invoke-Pester -Configuration $pesterConfiguration
# ----------------------------------------- #
# Create formatted Pester Test Results File #
# ----------------------------------------- #
$functionInput = @{
PesterTestResults = $testResults
OutputFilePath = Join-Path $env:GITHUB_WORKSPACE 'avm' 'Pester-output.md'
GitHubRepository = $env:GITHUB_REPOSITORY
BranchName = $env:GITHUB_REF
}
Write-Verbose 'Invoke Pester formatting function with' -Verbose
Write-Verbose ($functionInput | ConvertTo-Json -Depth 0 | Out-String) -Verbose
Set-PesterGitHubOutput @functionInput -Verbose
Write-Output ('{0}={1}' -f 'formattedPesterResultsPath', $functionInput.outputFilePath) >> $env:GITHUB_OUTPUT
- name: "Output to GitHub job summaries"
if: always()
shell: pwsh
run: |
# Grouping task logs
Write-Output '::group::Output to GitHub job summaries'
$mdPesterOutputFilePath = '${{ steps.pester_run_step.outputs.formattedPesterResultsPath }}'
if (-not (Test-Path $mdPesterOutputFilePath)) {
Write-Warning ('Input file [{0}] not found. Please check if the previous task threw an error and try again.' -f $mdPesterOutputFilePath)
} else {
Get-Content $mdPesterOutputFilePath >> $env:GITHUB_STEP_SUMMARY
Write-Verbose ('Successfully printed out file [{0}] to Job Summaries' -f $mdPesterOutputFilePath) -Verbose
}
Write-Output '::endgroup::'