11name : av-windows-defender
22on :
33 workflow_dispatch :
4+ inputs :
5+ tag :
6+ description : ' Release tag to scan (e.g., v0.15.16)'
7+ required : false
48 release :
59 types : [published]
610 pull_request :
@@ -13,6 +17,7 @@ permissions:
1317
1418jobs :
1519 defender-scan :
20+ if : github.event_name == 'release' || github.event_name == 'workflow_dispatch'
1621 name : Windows Defender scan (release assets)
1722 runs-on : windows-latest
1823 permissions :
@@ -23,41 +28,51 @@ jobs:
2328 shell : pwsh
2429 run : New-Item -ItemType Directory -Force -Path dist-release | Out-Null
2530
31+ - name : Resolve release tag
32+ id : resolve_tag
33+ shell : pwsh
34+ env :
35+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
36+ run : |
37+ $tag = "${{ github.event.release.tag_name }}"
38+ if (-not $tag) { $tag = "${{ github.event.inputs.tag }}" }
39+ if (-not $tag) { $tag = (gh release list --limit 1 --json tagName -q ".[0].tagName") }
40+ if (-not $tag) { throw 'No release tag found' }
41+ "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
42+
2643 - name : Download assets for this release
2744 shell : pwsh
2845 env :
2946 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3047 run : |
31- if (-not "${{ github.event.release.tag_name }}") {
32- throw "This workflow requires a release context or manual tag input."
33- }
34- gh release download "${{ github.event.release.tag_name }}" --dir dist-release --clobber
48+ gh release download "${{ steps.resolve_tag.outputs.tag }}" --dir dist-release --clobber
3549
3650 - name : List assets
3751 shell : pwsh
38- run : Get-ChildItem -File dist-release | Select-Object FullName, Length | Format-Table | Out-String | Tee-Object -FilePath dist-release\\ asset-list.txt
52+ run : Get-ChildItem -File dist-release | Select-Object FullName, Length | Format-Table | Out-String | Tee-Object -FilePath dist-release\asset-list.txt
3953
4054 - name : Scan each asset with Defender
4155 shell : pwsh
4256 run : |
43- $mp = "$env:ProgramFiles\\Windows Defender\\MpCmdRun.exe"
44- $detections = @()
57+ $mp = (Get-Command MpCmdRun.exe -ErrorAction SilentlyContinue).Source
58+ if (-not $mp) { $mp = "$env:ProgramFiles\Windows Defender\MpCmdRun.exe" }
59+ if (-not (Test-Path $mp)) { throw 'MpCmdRun.exe not found' }
4560 Get-ChildItem -File dist-release | ForEach-Object {
4661 Write-Host "Scanning $($_.FullName)"
4762 & $mp -Scan -ScanType 3 -File $_.FullName
4863 Start-Sleep -Seconds 3
4964 }
50- # Collect * recent* detections (last 30 minutes) and only for our folder
65+ # Collect recent detections (last 30 minutes) and only for our folder
5166 $since = (Get-Date).AddMinutes(-30)
5267 $recent = Get-MpThreatDetection | Where-Object {
5368 $_.InitialDetectionTime -ge $since -and
5469 $_.Resources -and ($_.Resources.Resource -match [Regex]::Escape((Resolve-Path "dist-release").Path))
5570 }
5671 if ($recent) {
57- $recent | ConvertTo-Json -Depth 5 | Out-File dist-release\\ defender-detections.json -Encoding UTF8
72+ $recent | ConvertTo-Json -Depth 5 | Out-File dist-release\defender-detections.json -Encoding UTF8
5873 Write-Error "Windows Defender found detections. See artifact."
5974 } else {
60- '{"status":"clean"}' | Out-File dist-release\\ defender-detections.json -Encoding UTF8
75+ '{"status":"clean"}' | Out-File dist-release\defender-detections.json -Encoding UTF8
6176 }
6277
6378 - name : Upload scan results
0 commit comments