88 release :
99 types : [published]
1010 pull_request :
11- branches : [dev]
11+ push :
1212 schedule :
13- - cron : " 0 4 * * 1" # weekly, 04:00 UTC Mondays
13+ - cron : " 0 4 * * 1"
1414
1515permissions :
1616 contents : read
1717
1818jobs :
19+ defender-pr :
20+ if : github.event_name == 'pull_request' || github.event_name == 'push'
21+ runs-on : windows-latest
22+ steps :
23+ - uses : actions/checkout@v4
24+ - name : Prepare PR scan payload
25+ shell : pwsh
26+ run : |
27+ New-Item -ItemType Directory -Force -Path dist-pr | Out-Null
28+ if (Test-Path dist) { Compress-Archive -Path dist\* -DestinationPath dist-pr\scan.zip -Force }
29+ elseif (Test-Path build) { Compress-Archive -Path build\* -DestinationPath dist-pr\scan.zip -Force }
30+ else { Compress-Archive -Path * -DestinationPath dist-pr\scan.zip -Force }
31+ - name : Windows Defender scan (PR)
32+ shell : pwsh
33+ run : |
34+ $mp = (Get-Command MpCmdRun.exe -ErrorAction SilentlyContinue).Source
35+ if (-not $mp) { $mp = "$env:ProgramFiles\Windows Defender\MpCmdRun.exe" }
36+ if (-not (Test-Path $mp)) { throw 'MpCmdRun.exe not found' }
37+ & $mp -Scan -ScanType 3 -File (Resolve-Path 'dist-pr\scan.zip')
38+ - name : Upload PR scan results
39+ uses : actions/upload-artifact@v4
40+ with :
41+ name : defender-pr-scan-input
42+ path : dist-pr/scan.zip
43+
1944 defender-scan :
2045 if : github.event_name == 'release' || github.event_name == 'workflow_dispatch'
2146 name : Windows Defender scan (release assets)
2752 - name : Prepare download dir
2853 shell : pwsh
2954 run : New-Item -ItemType Directory -Force -Path dist-release | Out-Null
30-
3155 - name : Resolve release tag
3256 id : resolve_tag
3357 shell : pwsh
@@ -39,18 +63,15 @@ jobs:
3963 if (-not $tag) { $tag = (gh release list --limit 1 --json tagName -q ".[0].tagName") }
4064 if (-not $tag) { throw 'No release tag found' }
4165 "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
42-
4366 - name : Download assets for this release
4467 shell : pwsh
4568 env :
4669 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4770 run : |
4871 gh release download "${{ steps.resolve_tag.outputs.tag }}" --dir dist-release --clobber
49-
5072 - name : List assets
5173 shell : pwsh
5274 run : Get-ChildItem -File dist-release | Select-Object FullName, Length | Format-Table | Out-String | Tee-Object -FilePath dist-release\asset-list.txt
53-
5475 - name : Scan each asset with Defender
5576 shell : pwsh
5677 run : |
6283 & $mp -Scan -ScanType 3 -File $_.FullName
6384 Start-Sleep -Seconds 3
6485 }
65- # Collect recent detections (last 30 minutes) and only for our folder
6686 $since = (Get-Date).AddMinutes(-30)
6787 $recent = Get-MpThreatDetection | Where-Object {
6888 $_.InitialDetectionTime -ge $since -and
7292 $recent | ConvertTo-Json -Depth 5 | Out-File dist-release\defender-detections.json -Encoding UTF8
7393 Write-Error "Windows Defender found detections. See artifact."
7494 } else {
75- '{"status": "clean"}' | Out-File dist-release\defender-detections.json -Encoding UTF8
95+ '{\ "status\":\ "clean\ "}' | Out-File dist-release\defender-detections.json -Encoding UTF8
7696 }
77-
7897 - name : Upload scan results
7998 uses : actions/upload-artifact@v4
8099 with :
0 commit comments