Skip to content

Commit 241dc22

Browse files
Update vbscript-syntax-check.yml
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <[email protected]>
1 parent 9a36fb9 commit 241dc22

1 file changed

Lines changed: 76 additions & 37 deletions

File tree

.github/workflows/vbscript-syntax-check.yml

Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,60 +18,99 @@ on:
1818
jobs:
1919
vbscript-lint:
2020
name: VBScript Syntax Validation
21-
runs-on: ubuntu-latest
21+
runs-on: windows-latest
2222

2323
steps:
24-
- name: 📦 Checkout Repository (short path to avoid path errors)
24+
- name: 📦 Checkout Repository
2525
uses: actions/checkout@v4
2626
with:
2727
path: repo
2828

29-
- name: 🔍 Locate .vbs and .hta Files
29+
- name: 🔍 Locate VBS and HTA Files (with filtering)
3030
working-directory: ./repo
31+
shell: pwsh
3132
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
3444
35-
- name: Heuristic Check and SARIF Generation
45+
- name: Run cscript Syntax Validation and Generate SARIF
3646
working-directory: ./repo
47+
shell: pwsh
3748
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
67106
68107
- name: 📤 Upload SARIF Artifact
69108
uses: actions/upload-artifact@v4
70109
with:
71110
name: vbscript-sarif-results
72111
path: repo/sarif-output/vbscript-results.sarif
73112

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
76115
with:
77116
sarif_file: repo/sarif-output/vbscript-results.sarif

0 commit comments

Comments
 (0)