Updated installation instructions. #38
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
name: Run Pester Tests | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
jobs: | |
pester: | |
strategy: | |
matrix: | |
os: [windows-latest, ubuntu-latest, macos-latest] | |
include: | |
- os: windows-latest | |
bw_dir: C:\Users\runneradmin\AppData\Local\bitwarden-cli | |
pwsh_modules: C:\Users\runneradmin\Documents\PowerShell\Modules | |
- os: ubuntu-latest | |
bw_dir: /opt/bitwarden-cli | |
pwsh_modules: /home/runner/.local/share/powershell/Modules | |
- os: macos-latest | |
bw_dir: /usr/local/bin/bitwarden-cli | |
pwsh_modules: /Users/runner/.local/share/powershell/Modules | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Bitwraden CLI Cache | |
id: bwcacher | |
uses: actions/cache@v4 | |
with: | |
path: ${{ matrix.bw_dir }} | |
key: ${{ runner.os }}-BitwardenCLI | |
- name: Setup PowerShell Module Cache | |
id: cacher | |
uses: actions/cache@v4 | |
with: | |
path: ${{ matrix.pwsh_modules }} | |
key: ${{ runner.os }}-Pester-SecretManagement | |
- name: Install PowerShell Dependencies | |
if: steps.cacher.outputs.cache-hit != 'true' | |
shell: pwsh | |
run: Install-PSResource -Name Pester,Microsoft.PowerShell.SecretManagement -Repository PSGallery -Scope CurrentUser -TrustRepository | |
- name: Install Bitwarden CLI | |
if: steps.bwcacher.outputs.cache-hit != 'true' | |
shell: pwsh | |
run: | | |
# Get Latest Version Number | |
$res = Invoke-RestMethod "https://github.com/bitwarden/clients/releases.atom" | |
$version = ($res.id | Select-String -Pattern "(?<=\/cli-v)([\d.]+)").Matches[0].Value | |
# Determine OS string. | |
if($IsWindows) { $os = "windows"} | |
elseif($IsMacOS) { $os = "macos"} | |
elseif($IsLinux) { $os = "linux"} | |
# Download file list | |
$Downloads = @( | |
@{ | |
Name = "Binary" | |
Uri = "https://github.com/bitwarden/clients/releases/download/cli-v$version/bw-$os-$version.zip" | |
OutFile = New-TemporaryFile | |
}, | |
@{ | |
Name = "Checksum" | |
Uri = "https://github.com/bitwarden/clients/releases/download/cli-v$version/bw-$os-sha256-$version.txt" | |
OutFile = New-TemporaryFile | |
} | |
) | |
# Download files in parallel. | |
$jobs = @() | |
foreach ($Download in $Downloads) { | |
$jobs += Start-ThreadJob -Name $Download.Name -ScriptBlock { | |
$params = $using:Download | |
Invoke-WebRequest -Uri $params.Uri -OutFile $params.OutFile | |
} | |
} | |
Write-Host "Downloading Bitwarden" | |
Receive-Job -Job $jobs -Wait | |
$hash = Get-FileHash -Path ($Downloads | Where-Object {$_.Name -eq "Binary"}).OutFile -Algorithm SHA256 | |
$checksum = Get-Content -Path ($Downloads | Where-Object {$_.Name -eq "Checksum"}).OutFile | |
if($hash.Hash -ine $checksum) { | |
Write-Error @" | |
The SHA256 Hash of the Downloaded Bitwarden CLI Doesn't Match The Provided Checksum! | |
Hash: {0} | |
Checksum: {1} | |
"@ -f $hash.Hash, $checksum | |
} | |
else { | |
if(!(Test-Path -Path "${{ matrix.bw_dir }}" -PathType Container)) { | |
New-Item -Path "${{ matrix.bw_dir }}" -ItemType Directory | Out-Null | |
} | |
# Extract bw from the downloaded zip file. | |
Expand-Archive -Path ($Downloads | Where-Object {$_.Name -eq "Binary"}).OutFile -DestinationPath "${{ matrix.bw_dir }}" | |
# Cleanup Downloaded Files | |
$Downloads.OutFile | Remove-Item | |
} | |
- name: Run Pester Tests with Code Coverage | |
shell: pwsh | |
working-directory: . | |
run: | | |
Import-Module Microsoft.PowerShell.SecretManagement | |
$env:BITWARDEN_CLI_PATH = (Get-ChildItem -Path "${{ matrix.bw_dir }}" -Filter "bw*" -File).FullName | |
# Run Pester tests | |
$config = New-PesterConfiguration | |
$config.Run.Path = "." | |
$config.CodeCoverage.Enabled = $IsLinux | |
$config.CodeCoverage.Path = @( | |
"./SecretManagement.Warden.Extension/classes", | |
"./SecretManagement.Warden.Extension/private", | |
"./SecretManagement.Warden.Extension/public" | |
) | |
$config.CodeCoverage.OutputPath = "coverage.xml" | |
$config.TestResult.Enabled = $true | |
$config.TestResult.OutputPath = "Unit.Tests.xml" | |
$config.Output.Verbosity = "Detailed" | |
Invoke-Pester -Configuration $config | |
- name: Upload test results | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ runner.os }}-Unit-Tests | |
path: Unit.Tests.xml | |
retention-days: 7 | |
- name: Setup .NET Core # Required to execute ReportGenerator | |
if: runner.os == 'Linux' | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.x | |
dotnet-quality: 'ga' | |
- name: ReportGenerator | |
if: runner.os == 'Linux' | |
uses: danielpalme/[email protected] | |
with: | |
reports: coverage.xml | |
targetdir: . | |
reporttypes: MarkdownSummaryGithub | |
- name: Publish Coverage In Build Summary | |
if: runner.os == 'Linux' | |
shell: bash | |
run: cat ./SummaryGithub.md >> $GITHUB_STEP_SUMMARY # Adjust path and filename if necessary |