|
18 | 18 | jobs: |
19 | 19 | vbscript-lint: |
20 | 20 | name: VBScript Syntax Validation |
21 | | - runs-on: ubuntu-latest |
| 21 | + runs-on: windows-latest |
22 | 22 |
|
23 | 23 | steps: |
24 | | - - name: 📦 Checkout Repository (short path to avoid path errors) |
| 24 | + - name: 📦 Checkout Repository |
25 | 25 | uses: actions/checkout@v4 |
26 | 26 | with: |
27 | 27 | path: repo |
28 | 28 |
|
29 | | - - name: 🔍 Locate .vbs and .hta Files |
| 29 | + - name: 🔍 Locate VBS and HTA Files (with filtering) |
30 | 30 | working-directory: ./repo |
| 31 | + shell: pwsh |
31 | 32 | run: | |
32 | | - find . -type f \( -iname "*.vbs" -o -iname "*.hta" \) > vbscript-files.txt |
33 | | - cat vbscript-files.txt || echo "No .vbs or .hta files found." |
| 33 | + Get-ChildItem -Recurse -Include *.vbs,*.hta | ForEach-Object { |
| 34 | + if ($_.Extension -eq ".hta") { |
| 35 | + $content = Get-Content $_.FullName -Raw |
| 36 | + if ($content -match '<script\s+language=["'']?VBScript["'']?' -or $content -match '<script\s+type=["'']?text/vbscript["'']?') { |
| 37 | + $_.FullName |
| 38 | + } |
| 39 | + } |
| 40 | + elseif ($_.Extension -eq ".vbs") { |
| 41 | + $_.FullName |
| 42 | + } |
| 43 | + } > vbscript-files.txt |
34 | 44 |
|
35 | | - - name: ✅ Heuristic Check and SARIF Generation |
| 45 | + - name: ✅ Run cscript Syntax Validation and Generate SARIF |
36 | 46 | working-directory: ./repo |
| 47 | + shell: pwsh |
37 | 48 | run: | |
38 | | - mkdir -p sarif-output |
39 | | - echo '{"version":"2.1.0","runs":[{"tool":{"driver":{"name":"VBScript Syntax Check","informationUri":"https://learn.microsoft.com/en-us/previous-versions//d1wf56tt(v=vs.85)","rules":[]}},"results":[' > sarif-output/vbscript-results.sarif |
40 | | -
|
41 | | - first=true |
42 | | - while IFS= read -r file; do |
43 | | - if [ -f "$file" ]; then |
44 | | - echo "🔍 Checking: $file" |
45 | | - if file "$file" | grep -qi "text"; then |
46 | | - echo "✔️ Valid text file: $file" |
47 | | - else |
48 | | - echo "::warning file=$file::Not a valid text-based VBScript or HTA file." |
49 | | - if [ "$first" = false ]; then echo "," >> sarif-output/vbscript-results.sarif; fi |
50 | | - echo "{ |
51 | | - \"ruleId\": \"non-text-vbs\", |
52 | | - \"level\": \"warning\", |
53 | | - \"message\": {\"text\": \"File is not a valid text-based VBScript or HTA file.\"}, |
54 | | - \"locations\": [{ |
55 | | - \"physicalLocation\": { |
56 | | - \"artifactLocation\": {\"uri\": \"${file#./}\"}, |
57 | | - \"region\": {\"startLine\": 1} |
58 | | - } |
59 | | - }] |
60 | | - }" >> sarif-output/vbscript-results.sarif |
61 | | - first=false |
62 | | - fi |
63 | | - fi |
64 | | - done < vbscript-files.txt |
65 | | -
|
66 | | - echo "]}]}" >> sarif-output/vbscript-results.sarif |
| 49 | + $sarifPath = "sarif-output" |
| 50 | + New-Item -ItemType Directory -Path $sarifPath -Force | Out-Null |
| 51 | + $sarif = @{ |
| 52 | + version = "2.1.0" |
| 53 | + runs = @(@{ |
| 54 | + tool = @{ |
| 55 | + driver = @{ |
| 56 | + name = "cscript.exe VBScript Syntax Checker" |
| 57 | + informationUri = "https://learn.microsoft.com/en-us/previous-versions//d1wf56tt(v=vs.85)" |
| 58 | + rules = @() |
| 59 | + } |
| 60 | + } |
| 61 | + results = @() |
| 62 | + }) |
| 63 | + } |
| 64 | +
|
| 65 | + $files = Get-Content vbscript-files.txt | Where-Object { Test-Path $_ } |
| 66 | +
|
| 67 | + foreach ($file in $files) { |
| 68 | + Write-Host "🔍 Checking: $file" |
| 69 | +
|
| 70 | + $output = cmd /c "cscript.exe //nologo `"$file`"" 2>&1 |
| 71 | + $exitCode = $LASTEXITCODE |
| 72 | +
|
| 73 | + if ($exitCode -ne 0) { |
| 74 | + Write-Warning "❌ Syntax Error in $file" |
| 75 | +
|
| 76 | + # Attempt to extract line number |
| 77 | + $lineNum = 1 |
| 78 | + if ($output -match "line (\d+)" -or $output -match "Line:(\d+)") { |
| 79 | + $lineNum = [int]($matches[1]) |
| 80 | + } |
| 81 | +
|
| 82 | + # Heuristic severity |
| 83 | + $severity = if ($output -match "Expected|Syntax error|Invalid") { |
| 84 | + "error" |
| 85 | + } elseif ($output -match "unterminated|not defined") { |
| 86 | + "warning" |
| 87 | + } else { |
| 88 | + "note" |
| 89 | + } |
| 90 | +
|
| 91 | + $sarif.runs[0].results += @{ |
| 92 | + ruleId = "vbscript-syntax-error" |
| 93 | + level = $severity |
| 94 | + message = @{ text = $output.Trim() } |
| 95 | + locations = @(@{ |
| 96 | + physicalLocation = @{ |
| 97 | + artifactLocation = @{ uri = $file.Replace('\','/') } |
| 98 | + region = @{ startLine = $lineNum } |
| 99 | + } |
| 100 | + }) |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +
|
| 105 | + $sarif | ConvertTo-Json -Depth 10 | Set-Content "$sarifPath/vbscript-results.sarif" -Encoding UTF8 |
67 | 106 |
|
68 | 107 | - name: 📤 Upload SARIF Artifact |
69 | 108 | uses: actions/upload-artifact@v4 |
70 | 109 | with: |
71 | 110 | name: vbscript-sarif-results |
72 | 111 | path: repo/sarif-output/vbscript-results.sarif |
73 | 112 |
|
74 | | - - name: 📡 Publish SARIF to GitHub Code Scanning Alerts |
75 | | - uses: github/codeql-action/upload-sarif@v2 |
| 113 | + - name: 📡 Publish SARIF to GitHub Code Scanning |
| 114 | + uses: github/codeql-action/upload-sarif@v3 |
76 | 115 | with: |
77 | 116 | sarif_file: repo/sarif-output/vbscript-results.sarif |
0 commit comments