wingetautoupdate/.github/workflows/powershell-tests.yaml

59 lines
2.1 KiB
YAML
Raw Permalink Normal View History

2023-04-18 12:41:35 +00:00
---
2023-07-30 06:31:15 +00:00
name: Powershell Test Runs
# yamllint disable-line rule:truthy
on:
pull_request:
2023-04-18 12:49:26 +00:00
branches: [master, main]
workflow_dispatch:
permissions:
contents: read
pull-requests: read
jobs:
powershell-tests:
name: Pester test and PSScriptAnalyzer
runs-on: windows-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Perform a Pester test for the WAU installation
shell: powershell
run: |
2024-09-01 14:04:58 +00:00
$command = New-PesterContainer -Path Sources/Winget-AutoUpdate-Install.ps1 -Data @{ Silent = $true }
Invoke-Pester -PassThru -Container $command -ErrorAction Continue
- name: Perform a Pester test for WAU run
shell: powershell
run: |
$command = New-PesterContainer -Path C:\ProgramData\Winget-AutoUpdate\user-run.ps1
Invoke-Pester -PassThru -Container $command -ErrorAction Continue
#- name: Read WAU Log
# id: package
# uses: juliangruber/read-file-action@v1
# with:
# path: 'C:\ProgramData\Winget-AutoUpdate\Logs\updates.log'
#- name: Display WAU Log
# run: type "${{ steps.package.outputs.content }}"
- name: Install PSScriptAnalyzer module from PSGallery
shell: powershell
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -ErrorAction Stop
- name: Lint with PSScriptAnalyzer
shell: powershell
run: |
Invoke-ScriptAnalyzer -Path *.ps1 -Recurse -Outvariable issues
$errors = $issues.Where({$_.Severity -eq 'Error'})
$warnings = $issues.Where({$_.Severity -eq 'Warning'})
if ($($errors.Count) -gt 0) {
$ErrorAction = "Stop"
} else {
$ErrorAction = "Continue"
}
if ($errors) {
Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction $ErrorAction
} else {
Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total."
}