-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished first draft of test workflow
- Loading branch information
1 parent
f1012df
commit 14da135
Showing
4 changed files
with
252 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
name: ".Platform - Run CI tests" | ||
|
||
on: | ||
push: # TODO: Remove trigger once done | ||
workflow_dispatch: | ||
inputs: | ||
testFile: | ||
type: string | ||
description: "The regex of the test file(s) to run" | ||
required: false | ||
default: '.*' | ||
testCase: | ||
type: string | ||
description: "The test case to run" | ||
required: false | ||
default: '' | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
env: | ||
workflowPath: ".github/workflows/platform.ci-tests.yml" | ||
|
||
|
||
jobs: | ||
########################### | ||
# Initialize pipeline # | ||
########################### | ||
job_initialize_pipeline: | ||
runs-on: ubuntu-latest | ||
name: "Initialize pipeline" | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: "Set input parameters to output variables" | ||
id: get-workflow-param | ||
uses: ./.github/actions/templates/avm-getWorkflowInput | ||
with: | ||
workflowPath: "${{ env.workflowPath}}" | ||
outputs: | ||
workflowInput: ${{ steps.get-workflow-param.outputs.workflowInput }} | ||
|
||
############### | ||
# Removal # | ||
############### | ||
job_run_tests: | ||
runs-on: ubuntu-20.04 | ||
name: "Run CI tests" | ||
needs: | ||
- job_initialize_pipeline | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set environment | ||
uses: ./.github/actions/templates/avm-setEnvironment | ||
|
||
- name: Run CI tests | ||
id: pester_run_step | ||
uses: azure/powershell@v2 | ||
with: | ||
inlineScript: | | ||
# Load used functions | ||
. (Join-Path $env:GITHUB_WORKSPACE 'avm' 'utilities' 'tests' 'Test-CI.ps1') | ||
$functionInput = @{ | ||
RepoRootPath = $env:GITHUB_WORKSPACE | ||
BranchName = $env:GITHUB_REF | ||
TestFile = '${{ (fromJson(needs.job_initialize_pipeline.outputs.workflowInput)).testFile }}' | ||
TestCase = '${{ (fromJson(needs.job_initialize_pipeline.outputs.workflowInput)).testCase }}' | ||
} | ||
Write-Verbose "Invoke task with" -Verbose | ||
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose | ||
$outputsFilePath = Test-CI @functionInput | ||
Write-Output ('{0}={1}' -f 'formattedPesterResultsPath', $outputsFilePath) >> $env:GITHUB_OUTPUT | ||
azPSVersion: "latest" | ||
|
||
- 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::' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Pester validation summary | ||
|
||
| Total No. of Processed Tests| Passed Tests :white_check_mark: | Failed Tests :x: | Skipped Tests :paperclip: | Tests with warnings :warning: | | ||
| :-- | :-- | :-- | :-- | :-- | | ||
| 3 | 3 | 0 | 0 | 0 | | ||
|
||
|
||
<details> | ||
<summary>List of failed Tests</summary> | ||
|
||
No tests failed. | ||
|
||
</details> | ||
|
||
|
||
<details> | ||
<summary>List of passed Tests</summary> | ||
|
||
| Name | Source | | ||
| :-- | :-- | | ||
| Test sequence ordering / **Remove first sequence should be as expected** | <code>[Get-OrderedResourcesList.tests.ps1:10](https://github.com/C:\dev\ip\bicep-registry-modules\fork-AlexanderSehr/blob/users/alsehr/pesterCiTests/avm\utilities\tests\pipelines\Get-OrderedResourcesList.tests.ps1#L10)</code> | | ||
| Test sequence ordering / **Remove last sequence should be as expected** | <code>[Get-OrderedResourcesList.tests.ps1:77](https://github.com/C:\dev\ip\bicep-registry-modules\fork-AlexanderSehr/blob/users/alsehr/pesterCiTests/avm\utilities\tests\pipelines\Get-OrderedResourcesList.tests.ps1#L77)</code> | | ||
| Test sequence ordering / **Remove sequence should be as expected if both first & last priorities are provided** | <code>[Get-OrderedResourcesList.tests.ps1:146](https://github.com/C:\dev\ip\bicep-registry-modules\fork-AlexanderSehr/blob/users/alsehr/pesterCiTests/avm\utilities\tests\pipelines\Get-OrderedResourcesList.tests.ps1#L146)</code> | | ||
|
||
</details> | ||
|
||
|
||
<details> | ||
<summary>List of skipped Tests</summary> | ||
|
||
No tests were skipped. | ||
|
||
</details> | ||
|
||
|
||
<details> | ||
<summary>List of explicit warnings</summary> | ||
|
||
No tests with warnings. | ||
|
||
</details> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
function Test-CI { | ||
|
||
[CmdletBinding()] | ||
param ( | ||
[Parameter()] | ||
[string] $RepoRootPath = (Get-Item $PSScriptRoot).Parent.Parent.Parent.FullName, | ||
|
||
[Parameter()] | ||
[string] $BranchName = (git branch --show-current), | ||
|
||
[Parameter()] | ||
[string] $TestFile = '.*', | ||
|
||
[Parameter()] | ||
[string] $TestCase # TODO: Add support | ||
) | ||
|
||
# Load used functions | ||
. (Join-Path $RepoRootPath 'avm' 'utilities' 'pipelines' 'staticValidation' 'compliance' 'Set-PesterGitHubOutput.ps1') | ||
|
||
$testFiles = (Get-ChildItem -Path (Join-Path $RepoRootPath 'avm' 'utilities' 'tests') -Recurse -File -Filter '*.tests.ps1').FullName | Where-Object { | ||
$_ -match $TestFile | ||
} | ||
|
||
# ------------------- # | ||
# Invoke Pester tests # | ||
# ------------------- # | ||
$pesterConfiguration = @{ | ||
Run = @{ | ||
Container = New-PesterContainer -Path $testFiles -Data @{ | ||
RepoRootPath = $RepoRootPath | ||
} | ||
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 = @{ | ||
RepoRootPath = $RepoRootPath | ||
PesterTestResults = $testResults | ||
OutputFilePath = Join-Path $RepoRootPath 'avm' 'utilities' 'tests' 'Pester-output.md' | ||
GitHubRepository = $RepoRootPath | ||
BranchName = $BranchName | ||
} | ||
|
||
Write-Verbose 'Invoke Pester formatting function with' -Verbose | ||
Write-Verbose ($functionInput | ConvertTo-Json -Depth 0 | Out-String) -Verbose | ||
|
||
Set-PesterGitHubOutput @functionInput -Verbose | ||
|
||
return $functionInput.OutputFilePath | ||
} | ||
|
||
|
||
|