|
| 1 | +name: Install WDK |
| 2 | + |
| 3 | +inputs: |
| 4 | + version: |
| 5 | + description: "WDK version to install. Format: 10.0.XXXXX or 10.0.XXXXX.YYYY. If QFE (4th component) is omitted, the latest available QFE is selected." |
| 6 | + required: true |
| 7 | + source: |
| 8 | + description: "Source to install WDK from (nuget or winget)." |
| 9 | + required: true |
| 10 | + # required to set WDKBinRoot and WDKToolRoot based on the host architecture when using nuget |
| 11 | + host: |
| 12 | + description: "Host architecture (x64 or ARM64)." |
| 13 | + required: true |
| 14 | + # required to set WDKContentRoot based on the target architecture when using nuget |
| 15 | + target: |
| 16 | + description: "Target architecture (x64 or ARM64)." |
| 17 | + required: true |
| 18 | + |
| 19 | +runs: |
| 20 | + using: "composite" |
| 21 | + steps: |
| 22 | + - name: Install WDK |
| 23 | + shell: pwsh |
| 24 | + run: | |
| 25 | + # Function to normalize architecture names |
| 26 | + function Normalize-Architecture($arch) { |
| 27 | + switch ($arch.ToLower()) { |
| 28 | + 'amd64' { return 'x64' } |
| 29 | + 'arm64' { return 'arm64' } |
| 30 | + default { |
| 31 | + Write-Error "Invalid architecture: $arch. Supported architectures are 'amd64' and 'arm64'." |
| 32 | + exit 1 |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | +
|
| 37 | + $hostArch = Normalize-Architecture '${{ inputs.host }}' |
| 38 | + $targetArch = Normalize-Architecture '${{ inputs.target }}' |
| 39 | + |
| 40 | + $inputVersion = '${{ inputs.version }}' |
| 41 | + if ($inputVersion -notmatch '^10\.0\.\d{5}(\.\d{1,4})?$') { |
| 42 | + Write-Error "Invalid version format: $inputVersion" |
| 43 | + exit 1 |
| 44 | + } |
| 45 | + $versionParts = $inputVersion.Split('.') |
| 46 | + $sdkVersion = $versionParts[0..2] -join '.' |
| 47 | + |
| 48 | + $source = '${{ inputs.source }}' |
| 49 | + if ($source -ne 'nuget' -and $source -ne 'winget') { |
| 50 | + Write-Error "Invalid source: $source. Supported sources are 'nuget' and 'winget'." |
| 51 | + exit 1 |
| 52 | + } |
| 53 | +
|
| 54 | + if ($source -eq 'nuget') { |
| 55 | +
|
| 56 | + if ($versionParts.Length -eq 3) { |
| 57 | + # No QFE specified, find the latest QFE for this base version |
| 58 | + Write-Host "No QFE specified, searching for latest QFE for version $inputVersion..." |
| 59 | + $baseVersion = $inputVersion |
| 60 | + try { |
| 61 | + $availableVersions = @() |
| 62 | + Write-Host "Trying NuGet API..." |
| 63 | + try { |
| 64 | + # Check available `x64` versions. `arm64` and `x64` kits are released together almost always |
| 65 | + $nugetApiUrl = "https://api.nuget.org/v3-flatcontainer/microsoft.windows.wdk.x64/index.json" |
| 66 | + $response = Invoke-RestMethod -Uri $nugetApiUrl -ErrorAction SilentlyContinue |
| 67 | + if ($response -and $response.versions) { |
| 68 | + $availableVersions = $response.versions | Where-Object { $_ -match '^\d+\.\d+\.\d+\.\d+$' } |
| 69 | + Write-Host "Found $($availableVersions.Count) versions using NuGet API" |
| 70 | + } |
| 71 | + } catch { |
| 72 | + Write-Host "NuGet API query failed: $_" |
| 73 | + exit 1 |
| 74 | + } |
| 75 | + |
| 76 | + # Filter versions that match the base version and find the latest QFE |
| 77 | + $matchingVersions = $availableVersions | Where-Object { $_.StartsWith("$baseVersion.") } |
| 78 | + if ($matchingVersions.Count -eq 0) { |
| 79 | + Write-Warning "No QFE versions found for base version $baseVersion, trying without QFE..." |
| 80 | + $version = $inputVersion |
| 81 | + } else { |
| 82 | + # Sort versions and get the latest |
| 83 | + $version = $matchingVersions | Sort-Object { [System.Version]$_ } | Select-Object -Last 1 |
| 84 | + Write-Host "Found latest QFE version: $version" |
| 85 | + } |
| 86 | + } catch { |
| 87 | + Write-Warning "Failed to query NuGet for latest QFE version: $_" |
| 88 | + exit 1 |
| 89 | + } |
| 90 | + } else { |
| 91 | + $version = $inputVersion |
| 92 | + Write-Host "Using specified version: $version" |
| 93 | + } |
| 94 | + |
| 95 | + $packages = "C:\packages" |
| 96 | + |
| 97 | + Write-Host "Trying nuget install for version $version..." |
| 98 | + try { |
| 99 | + Write-Host "Installing Microsoft.Windows.SDK.CPP version $version..." |
| 100 | + nuget install Microsoft.Windows.SDK.CPP -Version $version -OutputDirectory $packages |
| 101 | + if ($LASTEXITCODE -ne 0) { throw "Microsoft.Windows.SDK.CPP" } |
| 102 | + |
| 103 | + Write-Host "Installing Microsoft.Windows.WDK.x64 version $version..." |
| 104 | + nuget install Microsoft.Windows.WDK.x64 -Version $version -OutputDirectory $packages |
| 105 | + if ($LASTEXITCODE -ne 0) { throw "Microsoft.Windows.WDK.x64" } |
| 106 | +
|
| 107 | + Write-Host "Installing Microsoft.Windows.WDK.arm64 version $version..." |
| 108 | + nuget install Microsoft.Windows.WDK.arm64 -Version $version -OutputDirectory $packages |
| 109 | + if ($LASTEXITCODE -ne 0) { throw "Microsoft.Windows.WDK.arm64" } |
| 110 | +
|
| 111 | + Write-Host "Successfully installed all WDK packages for version $version" |
| 112 | + } catch { |
| 113 | + Write-Error "Failed to install $_ version $version" |
| 114 | + exit 1 |
| 115 | + } |
| 116 | + if (-not (Test-Path $packages)) { |
| 117 | + Write-Error "$packages path could not be found. Please check the WDK version and source." |
| 118 | + exit 1 |
| 119 | + } |
| 120 | +
|
| 121 | + Write-Host "Setting WDKContentRoot environment variable..." |
| 122 | + Write-Output "WDKContentRoot=$packages\Microsoft.Windows.WDK.$targetArch.$version\c\" >> $env:GITHUB_ENV |
| 123 | +
|
| 124 | + Write-Host "Setting Version_Number environment variable..." |
| 125 | + Write-Output "Version_Number=$sdkVersion.0" >> $env:GITHUB_ENV |
| 126 | +
|
| 127 | + Write-Host "Setting WDKBinRoot environment variable..." |
| 128 | + Write-Output "WDKBinRoot=$packages\Microsoft.Windows.WDK.$hostArch.$version\c\bin" >> $env:GITHUB_ENV |
| 129 | +
|
| 130 | + Write-Host "Setting WDKToolRoot environment variable..." |
| 131 | + Write-Output "WDKToolRoot=$packages\Microsoft.Windows.WDK.$hostArch.$version\c\tools" >> $env:GITHUB_ENV |
| 132 | +
|
| 133 | + Write-Host "Setting WindowsSdkBinPath environment variable..." |
| 134 | + Write-Output "WindowsSdkBinPath=$packages\Microsoft.Windows.SDK.CPP.$version\c\bin" >> $env:GITHUB_ENV |
| 135 | + } else { |
| 136 | +
|
| 137 | + Write-Host "Using Winget to install WDK and SDK version $inputVersion..." |
| 138 | +
|
| 139 | + $sdk = "Microsoft.WindowsSDK.$sdkVersion" |
| 140 | + $wdk = "Microsoft.WindowsWDK.$inputVersion" |
| 141 | + Write-Host "Installing $sdk..." |
| 142 | + Install-WinGetPackage -Id $sdk -Source winget -MatchOption Equals -Mode Silent -Force -Override '/q /features +' |
| 143 | + $installSuccess = $? |
| 144 | + if (-not $installSuccess) { |
| 145 | + Write-Error "$sdk installation failed. Last exit code: $LASTEXITCODE and success status: $installSuccess" |
| 146 | + exit 1 |
| 147 | + } |
| 148 | +
|
| 149 | + Write-Host "Installing $wdk..." |
| 150 | + Install-WinGetPackage -Id $wdk -Source winget -MatchOption Equals -Mode Silent -Force |
| 151 | + $installSuccess = $? |
| 152 | + if (-not $installSuccess) { |
| 153 | + Write-Error "$wdk installation failed. Last exit code: $LASTEXITCODE and success status: $installSuccess" |
| 154 | + exit 1 |
| 155 | + } |
| 156 | +
|
| 157 | + Write-Host "Setting Version_Number environment variable to $sdkVersion..." |
| 158 | + Write-Output "Version_Number=$sdkVersion.0" >> $env:GITHUB_ENV |
| 159 | + } |
0 commit comments