Skip to content

Commit c830fc9

Browse files
Update vbscript-syntax-check.yml
Signed-off-by: LUIZ HAMILTON ROBERTO DA SILVA <[email protected]>
1 parent 6b6ffb5 commit c830fc9

1 file changed

Lines changed: 62 additions & 37 deletions

File tree

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: VBScript Syntax Check
1+
name: VBScript Syntax Validation
22

33
on:
44
push:
@@ -14,69 +14,94 @@ on:
1414
workflow_dispatch:
1515

1616
jobs:
17-
vbscript-lint:
18-
name: 🧪 VBScript Syntax Validation (Wine + Ubuntu)
17+
vbscript-syntax-check:
18+
name: 🔍 VBScript Lint with Line Detection
1919
runs-on: ubuntu-latest
2020

2121
steps:
22-
- name: 📦 Checkout Repository (short path to prevent long file issues)
22+
- name: 📦 Checkout repository (short path to avoid filename issues)
2323
uses: actions/checkout@v4
2424
with:
25-
path: src
25+
path: repo
2626

27-
- name: 🍷 Install Wine and VBScript Runtime
27+
- name: 🍷 Setup Wine
2828
run: |
29-
sudo dpkg --add-architecture i386
30-
sudo apt update
31-
sudo apt install -y wine64 wine32 cabextract unzip
32-
mkdir -p ~/.wine/drive_c/windows/system32
33-
echo "[✔️] Wine installed successfully"
34-
35-
- name: 📂 Find .vbs and .hta Files
36-
working-directory: ./src
29+
sudo apt-get update
30+
sudo apt-get install -y wine64
31+
32+
- name: 🔎 Locate .vbs and .hta Files
33+
working-directory: ./repo
3734
run: |
3835
find . -type f \( -iname "*.vbs" -o -iname "*.hta" \) > vbscript-files.txt
39-
cat vbscript-files.txt || echo "No VBS or HTA files found"
36+
cat vbscript-files.txt || echo "No .vbs or .hta files found."
4037
41-
- name: 🧠 Analyze and Validate VBScript Files
42-
working-directory: ./src
38+
- name: 🧪 VBScript Syntax Validation with SARIF
39+
working-directory: ./repo
4340
run: |
44-
mkdir -p sarif
45-
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/results.sarif
41+
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":[' > vbscript-results.sarif
42+
43+
exit_code=0
44+
first=true
4645
4746
while IFS= read -r file; do
48-
echo "Checking: $file"
47+
echo "🔍 Checking: $file"
4948
49+
# Skip HTA files that start with HTML or lack VBScript blocks
5050
if [[ "$file" == *.hta ]]; then
51-
if ! grep -qi '<script[^>]*language="VBScript"' "$file"; then
52-
echo "Skipping non-VBScript HTA: $file"
51+
if grep -iqE '^\s*<(html|!doctype)' "$file"; then
52+
echo "::notice file=$file::Skipped HTA (HTML content)"
53+
continue
54+
fi
55+
if ! grep -iq '<script[^>]*language=["'\''"]vbscript["'\''"]' "$file"; then
56+
echo "::notice file=$file::Skipped HTA (no VBScript block)"
5357
continue
5458
fi
5559
fi
5660
57-
if file "$file" | grep -qi text; then
58-
wine cscript.exe //nologo "$file" 2> stderr.txt
59-
exitCode=$?
61+
# Run VBScript under Wine
62+
if ! wine cscript.exe //nologo "$file" 2> error.log; then
63+
echo "::error file=$file::Syntax error in VBScript."
64+
[[ "$first" == false ]] && echo "," >> vbscript-results.sarif
65+
first=false
6066
61-
if [ $exitCode -ne 0 ]; then
62-
msg=$(<stderr.txt)
63-
msg=${msg//\"/\\\"}
64-
echo "{\"level\": \"error\", \"message\": {\"text\": \"$msg\"}, \"locations\": [{\"physicalLocation\": {\"artifactLocation\": {\"uri\": \"$file\"}}}]}," >> sarif/results.sarif
67+
# Extract first useful line number using grep -n
68+
match_line=$(grep -in "Error" error.log | head -n 1)
69+
line_number=$(echo "$match_line" | cut -d: -f1)
70+
message=$(echo "$match_line" | cut -d: -f2- | sed 's/"/'\''/g')
71+
72+
# fallback if grep fails
73+
if [[ -z "$line_number" ]]; then
74+
line_number=1
75+
message="Syntax error in VBScript"
6576
fi
77+
78+
echo "❌ Line $line_number: $message"
79+
80+
echo '{' >> vbscript-results.sarif
81+
echo ' "level": "error",' >> vbscript-results.sarif
82+
echo ' "message": { "text": "'"${message}"'" },' >> vbscript-results.sarif
83+
echo ' "locations": [{' >> vbscript-results.sarif
84+
echo ' "physicalLocation": {' >> vbscript-results.sarif
85+
echo ' "artifactLocation": { "uri": "'"${file#./}"'" },' >> vbscript-results.sarif
86+
echo ' "region": { "startLine": '"$line_number"' }' >> vbscript-results.sarif
87+
echo ' }' >> vbscript-results.sarif
88+
echo ' }]' >> vbscript-results.sarif
89+
echo '}' >> vbscript-results.sarif
90+
91+
exit_code=1
6692
fi
6793
done < vbscript-files.txt
6894
69-
sed -i '$ s/},$/}]/' sarif/results.sarif
70-
echo '}]}]' >> sarif/results.sarif
95+
echo ']}]}' >> vbscript-results.sarif
96+
exit $exit_code
7197
72-
- name: 📤 Upload SARIF Results
98+
- name: 📁 Upload SARIF Artifact
7399
uses: actions/upload-artifact@v4
74100
with:
75-
name: vbscript-syntax-results
76-
path: src/sarif/results.sarif
77-
if-no-files-found: warn
101+
name: vbscript-lint-report
102+
path: repo/vbscript-results.sarif
78103

79-
- name: 🚨 Upload to GitHub Code Scanning (optional)
104+
- name: 🛰️ Upload SARIF to GitHub Code Scanning
80105
uses: github/codeql-action/upload-sarif@v3
81106
with:
82-
sarif_file: src/sarif/results.sarif
107+
sarif_file: repo/vbscript-results.sarif

0 commit comments

Comments
 (0)