-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (92 loc) · 3.85 KB
/
qa.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
# File: .github/workflows/qa.yml
on:
workflow_dispatch:
pull_request:
branches:
- 'main'
- 'releases/**'
name: PowerShell Module Quality Assurance
jobs:
lint-and-test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Az PowerShell Module
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Run PSScriptAnalyzer
uses: microsoft/[email protected]
with:
path: .\
recurse: true
output: results.sarif
excludeRule: '"PSAvoidUsingPlainTextForPassword"'
- name: Run Pester tests
shell: pwsh
env:
WATTTIMEUSERNAME: ${{ secrets.WATTTIMEUSERNAME }}
WATTTIMEPASSWORD: ${{ secrets.WATTTIMEPASSWORD }}
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module Az.Resources
Import-Module Az.Resources
Import-Module Pester
$pConfig = New-PesterConfiguration
$pConfig.Run.Path = './tests/PSWattTime.Tests/PSWattTime.Tests.ps1'
$pConfig.Run.PassThru = $true
$pConfig.Output.CIFormat = 'GithubActions'
$pConfig.Output.Verbosity = 'Detailed'
$pConfig.TestResult.OutputFormat = 'JunitXml'
$pConfig.TestResult.OutputPath ='./tests/junit.xml'
$pConfig.TestResult.Enabled = $true
$pConfig.CodeCoverage.Enabled = $true
$pConfig.CodeCoverage.OutputFormat = 'JaCoCo'
$pConfig.CodeCoverage.OutputPath = './tests/coverage.xml'
$pConfig.CodeCoverage.Path = './src/PSWattTime/PSWattTime.psm1'
$p = Invoke-Pester -Configuration $pConfig
Write-Output "## Pester Test Results" >> $env:GITHUB_STEP_SUMMARY
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
Write-Output "- Code coverage: **$($p.CodeCoverage.CoveragePercent)**" >> $env:GITHUB_STEP_SUMMARY
Write-Output "- Commands Executed: **$($p.CodeCoverage.CommandsExecutedCount)**" >> $env:GITHUB_STEP_SUMMARY
Write-Output "- Commands Missed: **$($p.CodeCoverage.CommandsMissedCount)**" >> $env:GITHUB_STEP_SUMMARY
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
Write-Output "|Block|Test|Duration|Result|" >> $env:GITHUB_STEP_SUMMARY
Write-Output "|---|---|---|---|" >> $env:GITHUB_STEP_SUMMARY
$p.Tests | ForEach-Object {
$mdTestResult = ""
If($_.Result -eq 'Failed') {
$mdTestResult = ":boom: Failed"
}
ElseIf($_.Result -eq 'Passed') {
$mdTestResult = ":green_heart: Passed"
}
Else {
$mdTestResult = ":nerd_face: $($_.Result)"
}
Write-Output "|$($_.Block)|$($_.Name)|$($_.Duration)|$($mdTestResult)|"
} >> $env:GITHUB_STEP_SUMMARY
Write-Output "" >> $env:GITHUB_STEP_SUMMARY
- name: Test the Module Manifest
shell: pwsh
run: Test-ModuleManifest -Path ./src/PSWattTime/PSWattTime.psd1
- name: Run the GitHub action in this commit
uses: ./
id: watttime_action
with:
azure_credential: ${{ secrets.AZURE_CREDENTIALS }}
watttime_username: ${{ secrets.WATTTIMEUSERNAME }}
watttime_password: ${{ secrets.WATTTIMEPASSWORD }}
regions: '"westeurope","northeurope","uksouth","francecentral","germanynorth"'
- name: Echo region from action
run: |
echo 'Best emissions region: ${{ steps.watttime_action.outputs.region }}'
echo 'Best emissions percent: ${{ steps.watttime_action.outputs.percent }}'
- name: Upload test results
uses: actions/upload-artifact@v3
with:
name: unit-tests
path: ./tests/*.xml
if: ${{ always() }}