|
| 1 | +--- |
| 2 | +name: CI-Driver |
| 3 | +permissions: {} |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + azure_signing_account: |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + default: '' |
| 12 | + azure_signing_cert_profile: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: '' |
| 16 | + azure_signing_endpoint: |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: '' |
| 20 | + publish_release: |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + release_commit: |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + release_version: |
| 27 | + required: true |
| 28 | + type: string |
| 29 | + secrets: |
| 30 | + AZURE_CLIENT_ID: |
| 31 | + required: false |
| 32 | + AZURE_CLIENT_SECRET: |
| 33 | + required: false |
| 34 | + AZURE_TENANT_ID: |
| 35 | + required: false |
| 36 | + |
| 37 | +env: |
| 38 | + DRIVER_BUILD_CONFIG: Release |
| 39 | + |
| 40 | +jobs: |
| 41 | + windows_driver: |
| 42 | + name: Windows Driver Installer |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + runs-on: windows-2022 |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 49 | + with: |
| 50 | + submodules: recursive |
| 51 | + |
| 52 | + - name: Setup dotnet |
| 53 | + uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 |
| 54 | + with: |
| 55 | + dotnet-version: '10.x' |
| 56 | + |
| 57 | + - name: Configure Windows driver package |
| 58 | + shell: pwsh |
| 59 | + env: |
| 60 | + BRANCH: ${{ github.head_ref || github.ref_name }} |
| 61 | + BUILD_VERSION: ${{ inputs.release_version }} |
| 62 | + COMMIT: ${{ inputs.release_commit }} |
| 63 | + run: | |
| 64 | + $certificatePath = Join-Path $env:GITHUB_WORKSPACE "cmake-build-driver\certificates\libvirtualhid-ci-test.cer" |
| 65 | + cmake ` |
| 66 | + -DBUILD_DOCS=OFF ` |
| 67 | + -DBUILD_EXAMPLES=ON ` |
| 68 | + -DBUILD_TESTS=OFF ` |
| 69 | + -DLIBVIRTUALHID_BUILD_WINDOWS_DRIVER=ON ` |
| 70 | + -DLIBVIRTUALHID_ENABLE_PACKAGING=ON ` |
| 71 | + "-DLIBVIRTUALHID_DRIVER_TEST_CERTIFICATE=$certificatePath" ` |
| 72 | + -A x64 ` |
| 73 | + -B cmake-build-driver ` |
| 74 | + -G "Visual Studio 17 2022" ` |
| 75 | + -S . |
| 76 | +
|
| 77 | + - name: Build Windows driver package |
| 78 | + shell: pwsh |
| 79 | + run: >- |
| 80 | + cmake --build cmake-build-driver |
| 81 | + --config ${{ env.DRIVER_BUILD_CONFIG }} |
| 82 | + --target libvirtualhid_windows_catalog libvirtualhid_broker gamepad_adapter virtualhid_control |
| 83 | + --parallel 2 |
| 84 | +
|
| 85 | + - name: Validate Azure signing configuration |
| 86 | + if: >- |
| 87 | + github.event_name == 'push' && |
| 88 | + inputs.publish_release == 'true' && |
| 89 | + inputs.azure_signing_account == '' |
| 90 | + shell: pwsh |
| 91 | + run: throw "Release builds must use Azure Trusted Signing for the Windows driver package." |
| 92 | + |
| 93 | + - name: Sign Windows driver package with local test certificate |
| 94 | + if: >- |
| 95 | + github.event_name == 'pull_request' || |
| 96 | + inputs.publish_release != 'true' |
| 97 | + shell: pwsh |
| 98 | + run: | |
| 99 | + $packagePath = Join-Path ` |
| 100 | + $env:GITHUB_WORKSPACE ` |
| 101 | + "cmake-build-driver\src\platform\windows\driver\package\$env:DRIVER_BUILD_CONFIG" |
| 102 | + $certificatePath = Join-Path ` |
| 103 | + $env:GITHUB_WORKSPACE ` |
| 104 | + "cmake-build-driver\certificates\libvirtualhid-ci-test.cer" |
| 105 | + .\scripts\windows\sign-driver-package.ps1 ` |
| 106 | + -PackagePath $packagePath ` |
| 107 | + -CertificatePath $certificatePath |
| 108 | +
|
| 109 | + - name: Locate Windows driver catalog |
| 110 | + id: driver_catalog |
| 111 | + if: >- |
| 112 | + github.event_name == 'push' && |
| 113 | + inputs.publish_release == 'true' && |
| 114 | + inputs.azure_signing_account != '' |
| 115 | + shell: pwsh |
| 116 | + run: | |
| 117 | + $catalogPath = Join-Path ` |
| 118 | + $env:GITHUB_WORKSPACE ` |
| 119 | + "cmake-build-driver\src\platform\windows\driver\package\$env:DRIVER_BUILD_CONFIG\libvirtualhid.cat" |
| 120 | + "path=$catalogPath" >> $env:GITHUB_OUTPUT |
| 121 | +
|
| 122 | + - name: Sign Windows driver package with Azure Trusted Signing |
| 123 | + if: >- |
| 124 | + github.event_name == 'push' && |
| 125 | + inputs.publish_release == 'true' && |
| 126 | + inputs.azure_signing_account != '' |
| 127 | + uses: azure/trusted-signing-action@c7ab2a863ab5f9a846ddb8265964877ef296ee82 # v2.0.0 |
| 128 | + with: |
| 129 | + azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 130 | + azure-client-secret: ${{ secrets.AZURE_CLIENT_SECRET }} |
| 131 | + azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 132 | + certificate-profile-name: ${{ inputs.azure_signing_cert_profile }} |
| 133 | + endpoint: ${{ inputs.azure_signing_endpoint }} |
| 134 | + files: | |
| 135 | + ${{ steps.driver_catalog.outputs.path }} |
| 136 | + signing-account-name: ${{ inputs.azure_signing_account }} |
| 137 | + |
| 138 | + - name: Package Windows driver installer |
| 139 | + shell: pwsh |
| 140 | + run: | |
| 141 | + Push-Location .\cmake-build-driver |
| 142 | + cpack -G WIX -C $env:DRIVER_BUILD_CONFIG |
| 143 | + $packageExitCode = $LASTEXITCODE |
| 144 | + Pop-Location |
| 145 | + if ($packageExitCode -ne 0) { |
| 146 | + exit $packageExitCode |
| 147 | + } |
| 148 | + New-Item -ItemType Directory -Force -Path artifacts | Out-Null |
| 149 | + Copy-Item ` |
| 150 | + -LiteralPath .\cmake-build-driver\cpack_artifacts\libvirtualhid.msi ` |
| 151 | + -Destination ` |
| 152 | + ".\artifacts\libvirtualhid-Windows-AMD64-driver-installer.msi" |
| 153 | +
|
| 154 | + - name: Export Azure driver signing certificate |
| 155 | + if: >- |
| 156 | + github.event_name == 'push' && |
| 157 | + inputs.publish_release == 'true' && |
| 158 | + inputs.azure_signing_account != '' |
| 159 | + shell: pwsh |
| 160 | + run: | |
| 161 | + $catalogPath = Join-Path ` |
| 162 | + $env:GITHUB_WORKSPACE ` |
| 163 | + "cmake-build-driver\src\platform\windows\driver\package\$env:DRIVER_BUILD_CONFIG\libvirtualhid.cat" |
| 164 | + $signature = Get-AuthenticodeSignature -FilePath $catalogPath |
| 165 | + if ($signature.Status -ne "Valid") { |
| 166 | + throw "Azure signed driver catalog is not valid: $($signature.StatusMessage)" |
| 167 | + } |
| 168 | + if (!$signature.SignerCertificate) { |
| 169 | + throw "Azure signed driver catalog did not expose a signer certificate." |
| 170 | + } |
| 171 | +
|
| 172 | + $certificatePath = Join-Path $env:GITHUB_WORKSPACE "artifacts\libvirtualhid-driver-signing.cer" |
| 173 | + New-Item -ItemType Directory -Force -Path (Split-Path -Parent $certificatePath) | Out-Null |
| 174 | + Export-Certificate -Cert $signature.SignerCertificate -FilePath $certificatePath -Force | Out-Null |
| 175 | + Write-Host ( |
| 176 | + "Exported Azure driver signing certificate " + |
| 177 | + "$($signature.SignerCertificate.Subject) [$($signature.SignerCertificate.Thumbprint)]." |
| 178 | + ) |
| 179 | +
|
| 180 | + - name: Sign Windows driver installer with Azure Trusted Signing |
| 181 | + if: >- |
| 182 | + github.event_name == 'push' && |
| 183 | + inputs.publish_release == 'true' && |
| 184 | + inputs.azure_signing_account != '' |
| 185 | + uses: azure/trusted-signing-action@c7ab2a863ab5f9a846ddb8265964877ef296ee82 # v2.0.0 |
| 186 | + with: |
| 187 | + azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 188 | + azure-client-secret: ${{ secrets.AZURE_CLIENT_SECRET }} |
| 189 | + azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 190 | + certificate-profile-name: ${{ inputs.azure_signing_cert_profile }} |
| 191 | + endpoint: ${{ inputs.azure_signing_endpoint }} |
| 192 | + files-folder: artifacts |
| 193 | + files-folder-filter: msi |
| 194 | + files-folder-recurse: false |
| 195 | + signing-account-name: ${{ inputs.azure_signing_account }} |
| 196 | + |
| 197 | + - name: Validate release signing identities |
| 198 | + if: >- |
| 199 | + github.event_name == 'push' && |
| 200 | + inputs.publish_release == 'true' && |
| 201 | + inputs.azure_signing_account != '' |
| 202 | + shell: pwsh |
| 203 | + run: | |
| 204 | + $catalogPath = Join-Path ` |
| 205 | + $env:GITHUB_WORKSPACE ` |
| 206 | + "cmake-build-driver\src\platform\windows\driver\package\$env:DRIVER_BUILD_CONFIG\libvirtualhid.cat" |
| 207 | + $installerPath = Get-ChildItem -LiteralPath .\artifacts -Filter *.msi | |
| 208 | + Select-Object -ExpandProperty FullName -First 1 |
| 209 | + if (!$installerPath) { |
| 210 | + throw "The signed Windows driver installer was not found." |
| 211 | + } |
| 212 | +
|
| 213 | + $catalogSignature = Get-AuthenticodeSignature -FilePath $catalogPath |
| 214 | + $installerSignature = Get-AuthenticodeSignature -FilePath $installerPath |
| 215 | + foreach ($signature in @($catalogSignature, $installerSignature)) { |
| 216 | + if ($signature.Status -ne "Valid" -or !$signature.SignerCertificate) { |
| 217 | + throw "A release signature is invalid: $($signature.StatusMessage)" |
| 218 | + } |
| 219 | + } |
| 220 | + if ($catalogSignature.SignerCertificate.Subject -cne ` |
| 221 | + $installerSignature.SignerCertificate.Subject) { |
| 222 | + throw "The catalog and MSI were signed with different identities." |
| 223 | + } |
| 224 | + Write-Host ( |
| 225 | + "Validated release signer " + |
| 226 | + "$($installerSignature.SignerCertificate.Subject) " + |
| 227 | + "[$($installerSignature.SignerCertificate.Thumbprint)]." |
| 228 | + ) |
| 229 | +
|
| 230 | + - name: Debug wix |
| 231 | + if: always() |
| 232 | + shell: pwsh |
| 233 | + run: | |
| 234 | + Get-Content .\cmake-build-driver\cpack_artifacts\_CPack_Packages\win64\WIX\wix.log ` |
| 235 | + -ErrorAction SilentlyContinue |
| 236 | +
|
| 237 | + - name: Upload Windows driver installer artifact |
| 238 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 239 | + with: |
| 240 | + name: windows-driver-installer |
| 241 | + path: artifacts |
| 242 | + if-no-files-found: error |
0 commit comments