Skip to content

Commit

Permalink
(maint) Refactor testing GitHub Actions
Browse files Browse the repository at this point in the history
Previously the CI testing used Azure DevOps pipelines with hosted agents. This
commit:
* Changes the build and test process to not be destructive and instead create
 the moudle in the 'Output' directory
* Adds the ability the use a different directory to load the module from before
 running the Pester tests
* Uploads the Test Results and Code Coverage as per AzDo pipelines
* Installs PowerShell on the test agent when needed.  Mainly needed to x86
 version of PowerShell 7
* Updates the module testing to use relative path to the module root instead of
 assuming the path is in a fixed location
  • Loading branch information
glennsarti committed Oct 19, 2021
1 parent 1d28b2f commit 61988a0
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 234 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: BurntToast CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
Win2019-x64-pwsh:
name: Server 2019 - PowerShell - x64
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- name: Perform a Pester test from the command-line
shell: pwsh
run: ./Tasks/build.ps1 -Bootstrap -Test

Win2019-x86-pwsh:
name: Server 2019 - PowerShell - x86
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- name: Perform a Pester test from the command-line
shell: pwsh
run: |
$Pwsh32 = .github/workflows/pwsh32.ps1
& $Pwsh32 -File ./Tasks/build.ps1 -Bootstrap -Test
Win2019-x64-winpwsh:
name: Server 2019 - Windows PowerShell - x64
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- name: Perform a Pester test from the command-line
shell: powershell
run: ./Tasks/build.ps1 -Bootstrap -Test

Win2019-x86-winpwsh:
name: Server 2019 - Windows PowerShell - x86
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- name: Perform a Pester test from the command-line
shell: powershell
# TODO: This could be problematic with hardcoding
run: C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -File ./Tasks/build.ps1 -Bootstrap -Test

build-and-oat-module:
name: Build Module and OAT
needs: ["Win2019-x64-pwsh", "Win2019-x64-winpwsh", "Win2019-x86-pwsh", "Win2019-x86-winpwsh"]
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- name: Compile Module
shell: pwsh
run: ./Tasks/build.ps1 -Bootstrap -Compile
- name: OAT
shell: pwsh
env:
# Use the compiled module for testing
BURNTTOAST_MODULE_ROOT: './Output/BurntToast/BurntToast.psd1'
run: |
./Tasks/build.ps1 -Test -CodeCoverage
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: test-results
path: "*.xml"
- name: Upload PowerShell Module
if: always()
uses: actions/upload-artifact@v2
with:
name: burnttoast-module
path: "./Output/BurntToast/"

publish-test-results:
name: "Publish Tests Results"
needs: build-and-oat-module
runs-on: ubuntu-latest
if: always()
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: test-results
path: artifacts
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: artifacts/**/TestResults.xml
- uses: codecov/codecov-action@v2
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: artifacts/CoverageResults.xml
25 changes: 25 additions & 0 deletions .github/workflows/pwsh32.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
param(
[Switch]$Force
)
$CurrentPSVersion = "$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Patch)"

$DownloadDir = Join-Path $PSScriptRoot '../../downloads'
If (-Not(Test-Path $DownloadDir)) { New-Item -Path $DownloadDir -ItemType 'Directory' | Out-Null }

$PwshZip = Join-Path $DownloadDir 'pwsh.zip'
If ((Test-Path $PwshZip) -and $Force) { Remove-Item -Path $DownloadDir -Force -Confirm:$false | Out-Null }
If (-Not (Test-Path $PwshZip)) {
$DownloadUrl = "https://github.com/PowerShell/PowerShell/releases/download/v$CurrentPSVersion/PowerShell-$CurrentPSVersion-win-x86.zip"
Write-Host "Downloading $DownloadURL ..."
Invoke-WebRequest -Uri $DownloadUrl -OutFile $PwshZip
} else {
Write-Host "ZIP file has been downloaded"
}

$PwshExtract = Join-Path $DownloadDir 'pwsh32'
If ((Test-Path $PwshExtract) -and $Force) { Remove-Item -Path $PwshExtract -Force -Confirm:$false -Recurse | Out-Null }
If (-Not (Test-Path $PwshExtract)) {
Expand-Archive -Path $PwshZip -DestinationPath $PwshExtract
}

Join-Path $PwshExtract 'pwsh.exe'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
downloads/
Output/
TestResults.xml
CoverageResults.xml
105 changes: 0 additions & 105 deletions Azure-Pipelines/build.ps1

This file was deleted.

123 changes: 0 additions & 123 deletions Azure-Pipelines/build.yml

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 61988a0

Please sign in to comment.