-
Notifications
You must be signed in to change notification settings - Fork 124
chore: update cargo-wdk templates to use latest crate versions #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6f2c016
Initial plan
Copilot cb786ad
Update template versions and add version validation test
Copilot 56ce8bb
Add copyright header to template_versions_test.rs
Copilot 3fa7426
Replace Rust test with PowerShell script and workflow
Copilot 4eef7d5
Remove toml dependency that's no longer needed
Copilot 5d31951
Read versions from workspace dependencies instead of package sections
Copilot 0f1ef99
Merge branch 'main' into copilot/update-cargo-wdk-templates
gurry ab53273
Migrate template version checks to version-checks.yaml workflow
Copilot f25e3b5
Remove blank line and simplify template version checks
Copilot d388767
Update .github/workflows/version-checks.yaml
gurry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #!/usr/bin/env pwsh | ||
| # Copyright (c) Microsoft Corporation | ||
| # License: MIT OR Apache-2.0 | ||
|
|
||
| # This script verifies that the cargo-wdk template Cargo.toml files use the correct | ||
| # versions of WDK crates by reading from each crate's [package] section. | ||
|
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| # Function to extract version from a Cargo.toml [package] section | ||
| function Get-PackageVersion { | ||
| param ( | ||
| [string]$CargoTomlPath | ||
| ) | ||
|
|
||
| if (-not (Test-Path $CargoTomlPath)) { | ||
| Write-Error "Cargo.toml not found at: $CargoTomlPath" | ||
| exit 1 | ||
| } | ||
|
|
||
| $content = Get-Content $CargoTomlPath -Raw | ||
|
|
||
| # Match version in [package] section | ||
| if ($content -match '(?ms)\[package\].*?version\s*=\s*"([^"]+)"') { | ||
| return $Matches[1] | ||
| } | ||
|
|
||
| Write-Error "Could not find version in [package] section of $CargoTomlPath" | ||
| exit 1 | ||
| } | ||
|
|
||
| # Function to extract dependency versions from a template file | ||
| function Get-TemplateDependencies { | ||
| param ( | ||
| [string]$TemplatePath | ||
| ) | ||
|
|
||
| if (-not (Test-Path $TemplatePath)) { | ||
| Write-Error "Template not found at: $TemplatePath" | ||
| exit 1 | ||
| } | ||
|
|
||
| $content = Get-Content $TemplatePath -Raw | ||
| $dependencies = @{} | ||
|
|
||
| # Extract wdk-* dependencies and their versions | ||
| $pattern = '(wdk[a-z-]*)\s*=\s*"([^"]+)"' | ||
| $matches = [regex]::Matches($content, $pattern) | ||
|
|
||
| foreach ($match in $matches) { | ||
| $depName = $match.Groups[1].Value | ||
| $depVersion = $match.Groups[2].Value | ||
| $dependencies[$depName] = $depVersion | ||
| } | ||
|
|
||
| return $dependencies | ||
| } | ||
|
|
||
| Write-Host "Checking template versions against crate package versions..." -ForegroundColor Cyan | ||
|
|
||
| # Get actual crate versions from [package] sections | ||
| $wdkVersion = Get-PackageVersion "crates/wdk/Cargo.toml" | ||
| $wdkAllocVersion = Get-PackageVersion "crates/wdk-alloc/Cargo.toml" | ||
| $wdkBuildVersion = Get-PackageVersion "crates/wdk-build/Cargo.toml" | ||
| $wdkPanicVersion = Get-PackageVersion "crates/wdk-panic/Cargo.toml" | ||
| $wdkSysVersion = Get-PackageVersion "crates/wdk-sys/Cargo.toml" | ||
|
|
||
| Write-Host "" | ||
| Write-Host "Current crate versions:" -ForegroundColor Green | ||
| Write-Host " wdk: $wdkVersion" | ||
| Write-Host " wdk-alloc: $wdkAllocVersion" | ||
| Write-Host " wdk-build: $wdkBuildVersion" | ||
| Write-Host " wdk-panic: $wdkPanicVersion" | ||
| Write-Host " wdk-sys: $wdkSysVersion" | ||
| Write-Host "" | ||
|
|
||
| $expectedVersions = @{ | ||
| "wdk" = $wdkVersion | ||
| "wdk-alloc" = $wdkAllocVersion | ||
| "wdk-build" = $wdkBuildVersion | ||
| "wdk-panic" = $wdkPanicVersion | ||
| "wdk-sys" = $wdkSysVersion | ||
| } | ||
|
|
||
| $templates = @( | ||
| @{ | ||
| Name = "KMDF" | ||
| Path = "crates/cargo-wdk/templates/kmdf/Cargo.toml.tmp" | ||
| ExpectedDeps = @("wdk", "wdk-alloc", "wdk-build", "wdk-panic", "wdk-sys") | ||
| }, | ||
| @{ | ||
| Name = "UMDF" | ||
| Path = "crates/cargo-wdk/templates/umdf/Cargo.toml.tmp" | ||
| ExpectedDeps = @("wdk", "wdk-build", "wdk-sys") | ||
| }, | ||
| @{ | ||
| Name = "WDM" | ||
| Path = "crates/cargo-wdk/templates/wdm/Cargo.toml.tmp" | ||
| ExpectedDeps = @("wdk", "wdk-alloc", "wdk-build", "wdk-panic", "wdk-sys") | ||
| } | ||
| ) | ||
|
|
||
| $hasErrors = $false | ||
|
|
||
| foreach ($template in $templates) { | ||
| Write-Host "Checking $($template.Name) template..." -ForegroundColor Cyan | ||
|
|
||
| $templateDeps = Get-TemplateDependencies $template.Path | ||
|
|
||
| foreach ($depName in $template.ExpectedDeps) { | ||
| if (-not $templateDeps.ContainsKey($depName)) { | ||
| Write-Host " ERROR: $depName is missing from template" -ForegroundColor Red | ||
| $hasErrors = $true | ||
| continue | ||
| } | ||
|
|
||
| $templateVersion = $templateDeps[$depName] | ||
| $expectedVersion = $expectedVersions[$depName] | ||
|
|
||
| if ($templateVersion -ne $expectedVersion) { | ||
| Write-Host " ERROR: $depName version mismatch" -ForegroundColor Red | ||
| Write-Host " Template has: $templateVersion" -ForegroundColor Red | ||
| Write-Host " Expected: $expectedVersion" -ForegroundColor Red | ||
| $hasErrors = $true | ||
| } else { | ||
| Write-Host " OK: $depName = $templateVersion" -ForegroundColor Green | ||
| } | ||
| } | ||
|
|
||
| Write-Host "" | ||
| } | ||
|
|
||
| if ($hasErrors) { | ||
| Write-Host "Template version check FAILED!" -ForegroundColor Red | ||
| exit 1 | ||
| } else { | ||
| Write-Host "All template versions are correct!" -ForegroundColor Green | ||
| exit 0 | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Template Version Check | ||
|
gurry marked this conversation as resolved.
Outdated
|
||
|
|
||
| on: | ||
| push: | ||
| branches-ignore: | ||
| - 'gh-readonly-queue/**' | ||
| pull_request: | ||
| merge_group: | ||
| schedule: # Trigger a job on default branch at 4AM PST everyday | ||
| - cron: 0 11 * * * | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.compare || github.head_ref || github.ref }} | ||
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
|
||
| jobs: | ||
| check-template-versions: | ||
| name: Check Template Versions | ||
| runs-on: windows-2025 | ||
|
|
||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Run Template Version Check | ||
| shell: pwsh | ||
| run: .github/scripts/check-template-versions.ps1 | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.