Skip to content

Consolidate build scripts into a single Build-Samples.ps1#1363

Merged
5an7y-Microsoft merged 11 commits intodevelopfrom
user/jvalesmena/new-build-samples
Mar 31, 2026
Merged

Consolidate build scripts into a single Build-Samples.ps1#1363
5an7y-Microsoft merged 11 commits intodevelopfrom
user/jvalesmena/new-build-samples

Conversation

@5an7y-Microsoft
Copy link
Copy Markdown
Contributor

@5an7y-Microsoft 5an7y-Microsoft commented Mar 30, 2026

Summary

Replaces the three separate build scripts (Build-AllSamples.ps1, Build-SampleSet.ps1, Build-Sample.ps1) with a single unified Build-Samples.ps1 that handles all build scenarios. Adds a new ListAllSamples.ps1 for sample discovery.

Motivation

The previous build system required users to choose between three scripts depending on the scenario, with a confusing call chain (Build-AllSamplesBuild-SampleSetBuild-Sample). This consolidation provides a single entry point while keeping the code maintainable through internal helper functions.

Changes

New scripts

  • Build-Samples.ps1 — Single build orchestrator that replaces all three scripts. Includes:
    • Build-SingleSample internal function (formerly Build-Sample.ps1)
    • Resolve-BuildEnvironment, Import-SampleExclusions, and other well-structured helpers
    • Wildcard support in -Samples parameter (e.g. .\Build-Samples -Samples 'tools.*')
    • Improved build plan and failure output formatting
    • Requires PowerShell 7+ (explicit #Requires directive)
  • ListAllSamples.ps1 — Dedicated sample discovery script, decoupled from building

Deleted scripts

  • Build-AllSamples.ps1
  • Build-SampleSet.ps1
  • Build-Sample.ps1

Updated files

  • .github/workflows/ci.yml — Calls Build-Samples.ps1 instead of Build-AllSamples.ps1
  • .github/scripts/Build-ChangedSamples.ps1 — Uses Build-Samples.ps1 for both full and partial builds
  • Building-Locally.md — Rewritten Step 6 with new script usage, examples (including wildcards), and updated example output

Usage examples

# Build everything (discovers samples automatically):
.\Build-Samples

# Build samples matching a wildcard:
.\Build-Samples -Samples 'tools.*'

# Build specific samples for one configuration:
.\Build-Samples -Samples 'usb.kmdf_fx2' -Configurations 'Debug' -Platforms 'x64'

Testing

CI workflow runs successfully on fork (5an7y-Microsoft/Windows-driver-samples-2)

5an7y and others added 6 commits March 19, 2026 15:36
- ListAllSamples.ps1: Enumerates .sln files and writes Samples.txt
- Build-Samples.ps1: Unified build script reading Samples.txt with
  exclusion support, parallel execution, and report generation
- Build-Sample.ps1: Fix retry bug where all-fail exits 0 instead of 1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Build-Samples.ps1:
- Extract helper functions for readability (Resolve-BuildEnvironment,
  Import-SampleExclusions, Initialize-DevShell, Assert-MsBuildAvailable,
  Get-DiskFreeGB)
- Add #Requires -Version 7.0
- Fix build_number to explicit [int] cast (was string from regex)
- Fix multi-socket CPU handling (sum LogicalProcessors)
- Fix NuGet path detection to use absolute repo root path
- Support wildcard patterns in exclusion paths (-like vs ContainsKey)
- Guard Invoke-Item for CI/automation (skip in non-interactive sessions)
- Validate sample directories exist before building
- Wrap Get-Volume in try/catch for UNC/network drives
- Use Write-Host with carriage return for progress (Write-Progress
  unreliable in -Parallel runspaces)
- Clean up variable names and add section comments
- Use switch instead of if/elseif for exit codes

ListAllSamples.ps1:
- Fix NuGet packages filter regex to catch packages anywhere in path
  (was only matching paths starting with packages)

Samples.txt:
- Regenerated with fixed filter, remove BOM

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- ListAllSamples.ps1: output sorted sample names to stdout instead of
  writing Samples.txt. The file output is replaced with Write-Output
  so callers can capture results via pipeline or command substitution.
- Build-Samples.ps1: remove SampleListPath parameter. Default discovery
  now calls ListAllSamples.ps1 at runtime and consumes its stdout.
  Explicit -Samples array still works and is sorted alphabetically.
  Both paths guarantee a consistent alphabetical sample ordering.
- Samples.txt: deleted. No longer needed as a pre-generated artifact.

WDS_TestPass.cs is unaffected - it only passes -LogFilesDirectory and
-InfOptions, neither of which changed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@5an7y-Microsoft 5an7y-Microsoft marked this pull request as ready for review March 30, 2026 19:02
@5an7y-Microsoft 5an7y-Microsoft requested a review from a team as a code owner March 30, 2026 19:02
5an7y added 5 commits March 30, 2026 15:26
…-Samples.ps1

- Delete Build-AllSamples.ps1 and Build-SampleSet.ps1 (replaced by Build-Samples.ps1)
- Update ci.yml workflow to call Build-Samples.ps1
- Update Build-ChangedSamples.ps1 to call Build-Samples.ps1
- Rewrite Building-Locally.md Step 6 with new script usage and output format
- Update Step 7 NuGet notes to reference Build-Samples.ps1
- Inline Build-Sample.ps1 logic as Build-SingleSample function in Build-Samples.ps1
- Pass function definition into parallel runspaces via $using: pattern
- Replace exit codes with return values for in-process execution
- Delete Build-Sample.ps1 (no longer needed as a separate script)
- Update Build-ChangedSamples.ps1 trigger file list
- When -Samples contains wildcards (* or ?), discover all samples first
  then filter with -like (same pattern style as exclusions.csv)
- Exact sample names still work as before without discovery overhead
- Update parameter docs, examples, and Building-Locally.md
…w-build-samples

# Conflicts:
#	Build-AllSamples.ps1
#	Build-SampleSet.ps1
@5an7y-Microsoft 5an7y-Microsoft changed the title User/jvalesmena/new build samples Consolidate build scripts into a single Build-Samples.ps1 Mar 30, 2026
@5an7y-Microsoft 5an7y-Microsoft merged commit 3b06a54 into develop Mar 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants