Skip to content

Commit 7ee7e75

Browse files
committed
ci: enable PR/push AV scans (no releases required)
- Add PR/push jobs for ClamAV (Linux) and Windows Defender (Windows) - Keep release/workflow_dispatch jobs for scanning published assets - No secret usage in PR/push jobs; uses repo/build outputs or repo archive - Upload PR scan payload/logs as artifacts
1 parent 1761693 commit 7ee7e75

2 files changed

Lines changed: 59 additions & 22 deletions

File tree

.github/workflows/clam-av-scan.yml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
11
name: av-clamav
22
on:
33
workflow_dispatch:
4-
inputs:
5-
tag:
6-
description: 'Release tag to scan (e.g., v0.15.16)'
7-
required: false
84
release:
95
types: [published]
106
pull_request:
11-
branches: [dev]
7+
push:
128
schedule:
13-
- cron: "0 3 * * 1" # weekly, 03:00 UTC Mondays
9+
- cron: "0 3 * * 1"
1410
permissions:
1511
contents: read
1612

1713
jobs:
14+
clamav-pr:
15+
if: github.event_name == 'pull_request' || github.event_name == 'push'
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Install ClamAV
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y clamav
23+
sudo freshclam || true
24+
- name: Prepare PR scan payload
25+
run: |
26+
mkdir -p dist-pr
27+
if [ -d dist ]; then tar -czf dist-pr/scan.tgz -C dist .; \
28+
elif [ -d build ]; then tar -czf dist-pr/scan.tgz -C build .; \
29+
else tar -czf dist-pr/scan.tgz --exclude=.git --exclude=.github .; fi
30+
- name: ClamAV scan (PR)
31+
run: |
32+
clamscan -ri --scan-archive=yes dist-pr | tee clamav-pr.log
33+
! grep -q "Infected files: [1-9]" clamav-pr.log
34+
- name: Upload PR scan results
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: clamav-pr-scan-results
38+
path: |
39+
clamav-pr.log
40+
dist-pr/scan.tgz
41+
1842
clamav-scan:
1943
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
20-
name: ClamAV scan (release assets)
2144
runs-on: ubuntu-latest
2245
permissions:
2346
contents: read
@@ -27,7 +50,6 @@ jobs:
2750
sudo apt-get update
2851
sudo apt-get install -y clamav
2952
sudo freshclam || true
30-
3153
- name: Resolve release tag
3254
id: resolve_tag
3355
env:
@@ -38,20 +60,16 @@ jobs:
3860
if [ -z "$tag" ]; then tag="$(gh release list --limit 1 --json tagName -q '.[0].tagName')"; fi
3961
if [ -z "$tag" ]; then echo "No release tag found" >&2; exit 1; fi
4062
echo "tag=$tag" >> "$GITHUB_OUTPUT"
41-
4263
- name: Download assets
4364
env:
4465
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4566
run: |
4667
mkdir -p dist-release
4768
gh release download "${{ steps.resolve_tag.outputs.tag }}" --dir dist-release --clobber
48-
49-
- name: Scan with ClamAV
69+
- name: Scan with ClamAV (release assets)
5070
run: |
5171
clamscan -ri dist-release | tee clamav.log
52-
# Fail if infected found
5372
! grep -q "Infected files: [1-9]" clamav.log
54-
5573
- name: Upload scan results
5674
uses: actions/upload-artifact@v4
5775
with:

.github/workflows/windows-defender-scan.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,39 @@ on:
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

1515
permissions:
1616
contents: read
1717

1818
jobs:
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)
@@ -27,7 +52,6 @@ jobs:
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: |
@@ -62,7 +83,6 @@ jobs:
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
@@ -72,9 +92,8 @@ jobs:
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

Comments
 (0)