Skip to content

Commit

Permalink
Add CI workflows for building and validating driver samples (microsof…
Browse files Browse the repository at this point in the history
…t#775)

* Add scripts to build a set of samples, as well as individual solution folders.
* Add GitHub workflows to use these scripts and build all samples on push and changed samples on pull request.

For now samples will be built under Windows 2019 but eventually workflow will be moved to run under Windows 2022.
  • Loading branch information
NeoAdonis authored Aug 26, 2022
1 parent 73c55fd commit d504c54
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/scripts/Build-ChangedProjects.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
param (
[array]$ChangedFiles
)

$root = (Get-Location).Path

# To include in CI gate
$projectSet = @{}
foreach ($file in $ChangedFiles)
{
if (-not (Test-Path $file)) {
Write-Output "❔ Changed file $file cannot be found"
continue
}
$dir = (Get-Item $file).DirectoryName
while ((-not ($slnItems = (Get-ChildItem $dir '*.sln'))) -and ($dir -ne $root))
{
$dir = (Get-Item $dir).Parent.FullName
}
if ($dir -eq $root)
{
Write-Output "❔ Changed file $file does not match a project."
continue
}
$projectName = $dir.Replace($root, '').Trim('\').Replace('\', '.').ToLower()
Write-Output "🔎 Found project [$projectName] at $dir from changed file $file"
if (-not ($projectSet.ContainsKey($projectName)))
{
$projectSet[$projectName] = $dir
}
}

.\Build-ProjectSet -ProjectSet $projectSet

40 changes: 40 additions & 0 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build changes to driver samples
on:
pull_request:
branches:
- main
- develop
paths-ignore:
- '**.md'
- 'LICENSE'
jobs:
build:
strategy:
fail-fast: false
matrix:
configuration: [Debug, Release]
platform: [x64, arm64]
runs-on: windows-2019
env:
Solution_Path: general\echo\kmdf\kmdfecho.sln
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Add MSBuild to PATH
uses: microsoft/[email protected]

- name: Get changed files
id: get-changed-files
uses: tj-actions/changed-files@v27

- name: Retrieve and build solutions from changed files
id: build-changed-projects
run: |
$changedFiles = "${{ steps.get-changed-files.outputs.all_changed_files }}".Split(' ')
.\.github\scripts\Build-ChangedProjects.ps1 -ChangedFiles $changedFiles
env:
Configuration: ${{ matrix.configuration }}
Platform: ${{ matrix.platform }}
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build all driver samples
on:
push:
branches:
- main
- develop
paths-ignore:
- '**.md'
- 'LICENSE'
jobs:
build:
strategy:
fail-fast: false
matrix:
configuration: [Debug, Release]
platform: [x64, arm64]
runs-on: windows-2019
env:
Solution_Path: general\echo\kmdf\kmdfecho.sln
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Add MSBuild to PATH
uses: microsoft/[email protected]

- name: Retrieve and build all available solutions
id: build-all-projects
run: |
.\Build-AllProjects.ps1
env:
Configuration: ${{ matrix.configuration }}
Platform: ${{ matrix.platform }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ bld/
[Bb]in/
[Oo]bj/

# Visual Studo 2015 cache/options directory
# Visual Studio 2015 cache/options directory
.vs/

# Visual Studio Code directory
.vscode/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
Expand Down Expand Up @@ -54,6 +57,7 @@ dlldata.c
*.tmp
*.tmp_proj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
Expand Down
15 changes: 15 additions & 0 deletions Build-AllProjects.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$root = Get-Location
$solutionFiles = Get-ChildItem -Path $root -Recurse -Filter *.sln | Select-Object -ExpandProperty FullName

# To include in CI gate
$projectSet = @{}
foreach ($file in $solutionFiles)
{
$dir = (Get-Item $file).DirectoryName
$dir_norm = $dir.Replace($root, '').Trim('\').Replace('\', '.').ToLower()
echo "🔎 Found project [$dir_norm] at $dir"
$projectSet[$dir_norm] = $dir
}

.\Build-ProjectSet -ProjectSet $projectSet

64 changes: 64 additions & 0 deletions Build-Project.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
param(
$Directory,
[string]$ProjectName,
$LogFilesDirectory = "_logfiles",
[string]$Configuration = "Debug",
[string]$Platform = "x64"
)

# TODO Validate $Directory and $LogFilesDirectory
New-Item -ItemType Directory -Force -Path $LogFilesDirectory | Out-Null

if ([string]::IsNullOrWhitespace($ProjectName))
{
$ProjectName = (Resolve-Path $Directory).Path.Replace((Get-Location), '').Replace('\', '.').Trim('.').ToLower()
}

$solutionFile = Get-ChildItem -Path $Directory -Filter *.sln | Select-Object -ExpandProperty FullName -First 1

$configurationIsSupported = $false
$inSolutionConfigurationPlatformsSection = $false
foreach ($line in Get-Content -Path $solutionFile)
{
if (-not $inSolutionConfigurationPlatformsSection -and $line -match "\s*GlobalSection\(SolutionConfigurationPlatforms\).*")
{
$inSolutionConfigurationPlatformsSection = $true;
continue;
}
elseif ($line -match "\s*EndGlobalSection.*")
{
$inSolutionConfigurationPlatformsSection = $false;
continue;
}

if ($inSolutionConfigurationPlatformsSection)
{
[regex]$regex = ".*=\s*(?<ConfigString>(?<Configuration>.*)\|(?<Platform>.*))\s*"
$match = $regex.Match($line)
if ([string]::IsNullOrWhiteSpace($match.Groups["ConfigString"].Value) -or [string]::IsNullOrWhiteSpace($match.Groups["Platform"].Value))
{
Write-Warning "Could not parse configuration entry $line from file $solutionFile."
continue;
}
if ($match.Groups["Configuration"].Value.Trim() -eq $Configuration -and $match.Groups["Platform"].Value.Trim() -eq $Platform)
{
$configurationIsSupported = $true;
}
}
}

if (-not $configurationIsSupported)
{
Write-Output "[$ProjectName] ⏩ Skipped. Configuration $Configuration|$Platform not supported."
exit 0
}

$errorLogFilePath = "$LogFilesDirectory\$ProjectName.err"
$warnLogFilePath = "$LogFilesDirectory\$ProjectName.wrn"
Write-Output "[$ProjectName] ⚒️ Building project..."
msbuild $solutionFile -clp:Verbosity=m -t:clean,build -property:Configuration=$Configuration -property:Platform=$Platform -p:TargetVersion=Windows10 -p:InfVerif_AdditionalOptions="/msft /sw1205 /sw1324 /sw1420 /sw1421" -p:SignToolWS=/fdws -p:DriverCFlagAddOn=/wd4996 -flp1:errorsonly`;logfile=$errorLogFilePath -flp2:WarningsOnly`;logfile=$warnLogFilePath -noLogo
if ($LASTEXITCODE -ne 0)
{
Write-Warning "❌ Build failed. Log available at $errorLogFilePath"
exit 1
}
38 changes: 38 additions & 0 deletions Build-ProjectSet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
param(
[hashtable]$ProjectSet,
[string]$Configuration = $env:Configuration,
[string]$Platform = $env:Platform
)

#TODO validate params

$exclusionsSet = @{}
$failSet = @()
Import-Csv 'exclusions.csv' | ForEach-Object {
$exclusionsSet[$_.Path.Replace($root, '').Trim('\').Replace('\', '.').ToLower()] = $_.Reason
}

$ProjectSet.GetEnumerator() | ForEach-Object {
$projectName = $_.Key
if ($exclusionsSet.ContainsKey($projectName))
{
Write-Output "[$projectName] ⏩ Excluded and skipped. Reason: $($exclusionsSet[$projectName])"
return;
}
$directory = $_.Value
.\Build-Project -Directory $directory -ProjectName $ProjectName -Configuration $Configuration -Platform $Platform
if ($LASTEXITCODE -ne 0)
{
$failSet += $ProjectName
}
}

if ($failSet.Count -gt 0)
{
Write-Output "Some projects were built with errors:"
foreach ($failedProject in $failSet)
{
Write-Output "$failedProject"
}
Write-Error "Some projects were built with errors."
}
15 changes: 15 additions & 0 deletions exclusions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Path,Reason
general\dchu\osrfx2_dchu_base,Wrong Toolset - needs migration
general\dchu\osrfx2_dchu_extension_loose,Needs fix for project not found
general\dchu\osrfx2_dchu_extension_tight,Wrong Toolset - needs migration
general\filehistory,Deprecated APIs
general\simplemediasource,ARM64 LNK1181: cannot open input file 'SimpleMediaSource.lib'
general\winhec 2017 lab\toaster driver,Needs input from end user
general\winhec 2017 lab\toaster support app,Needs input from end user
network\trans\stmedit,Invalid Win32 architecture
network\trans\wfpsampler,Missing INF section; missing libs
network\wlan\wdi,Invalid architecture
print\oem printer customization plug-in samples\c++,Invalid architecture
print\v4printdriversamples\printerextensionsample,Invalid architecture
tree,Missing headers
video\indirectdisplay,ARM64 Warning C4530: C++ exception handler used, but unwind semantics are not enabled

0 comments on commit d504c54

Please sign in to comment.