|
1 | | -name: VBScript Syntax Check |
| 1 | +name: VBScript Syntax Validation |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
|
14 | 14 | workflow_dispatch: |
15 | 15 |
|
16 | 16 | jobs: |
17 | | - vbscript-lint: |
18 | | - name: 🧪 VBScript Syntax Validation (Wine + Ubuntu) |
| 17 | + vbscript-syntax-check: |
| 18 | + name: 🔍 VBScript Lint with Line Detection |
19 | 19 | runs-on: ubuntu-latest |
20 | 20 |
|
21 | 21 | steps: |
22 | | - - name: 📦 Checkout Repository (short path to prevent long file issues) |
| 22 | + - name: 📦 Checkout repository (short path to avoid filename issues) |
23 | 23 | uses: actions/checkout@v4 |
24 | 24 | with: |
25 | | - path: src |
| 25 | + path: repo |
26 | 26 |
|
27 | | - - name: 🍷 Install Wine and VBScript Runtime |
| 27 | + - name: 🍷 Setup Wine |
28 | 28 | 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 |
37 | 34 | run: | |
38 | 35 | 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." |
40 | 37 |
|
41 | | - - name: 🧠 Analyze and Validate VBScript Files |
42 | | - working-directory: ./src |
| 38 | + - name: 🧪 VBScript Syntax Validation with SARIF |
| 39 | + working-directory: ./repo |
43 | 40 | 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 |
46 | 45 |
|
47 | 46 | while IFS= read -r file; do |
48 | | - echo "Checking: $file" |
| 47 | + echo "🔍 Checking: $file" |
49 | 48 |
|
| 49 | + # Skip HTA files that start with HTML or lack VBScript blocks |
50 | 50 | 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)" |
53 | 57 | continue |
54 | 58 | fi |
55 | 59 | fi |
56 | 60 |
|
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 |
60 | 66 |
|
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" |
65 | 76 | 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 |
66 | 92 | fi |
67 | 93 | done < vbscript-files.txt |
68 | 94 |
|
69 | | - sed -i '$ s/},$/}]/' sarif/results.sarif |
70 | | - echo '}]}]' >> sarif/results.sarif |
| 95 | + echo ']}]}' >> vbscript-results.sarif |
| 96 | + exit $exit_code |
71 | 97 |
|
72 | | - - name: 📤 Upload SARIF Results |
| 98 | + - name: 📁 Upload SARIF Artifact |
73 | 99 | uses: actions/upload-artifact@v4 |
74 | 100 | 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 |
78 | 103 |
|
79 | | - - name: 🚨 Upload to GitHub Code Scanning (optional) |
| 104 | + - name: 🛰️ Upload SARIF to GitHub Code Scanning |
80 | 105 | uses: github/codeql-action/upload-sarif@v3 |
81 | 106 | with: |
82 | | - sarif_file: src/sarif/results.sarif |
| 107 | + sarif_file: repo/vbscript-results.sarif |
0 commit comments