|
1 | | -name: VBScript Syntax Check with SARIF |
| 1 | +name: VBScript Syntax Check |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: [main, develop] |
6 | 6 | paths: |
7 | 7 | - '**/*.vbs' |
8 | 8 | - '**/*.hta' |
| 9 | + |
9 | 10 | pull_request: |
10 | 11 | branches: [main, develop] |
11 | 12 | paths: |
12 | 13 | - '**/*.vbs' |
13 | 14 | - '**/*.hta' |
| 15 | + |
14 | 16 | workflow_dispatch: |
15 | 17 |
|
16 | 18 | jobs: |
17 | 19 | vbscript-lint: |
18 | 20 | name: VBScript Syntax Validation |
19 | 21 | runs-on: ubuntu-latest |
20 | 22 |
|
21 | | - outputs: |
22 | | - sarif-report-path: ${{ steps.sarif-output.outputs.sarif-path }} |
23 | | - |
24 | 23 | steps: |
25 | 24 | - name: 📦 Checkout Repository (short path to avoid path errors) |
26 | 25 | uses: actions/checkout@v4 |
27 | 26 | with: |
28 | 27 | path: repo |
29 | 28 |
|
30 | | - - name: 🔍 Locate VBS and HTA Files |
31 | | - id: locate-files |
| 29 | + - name: 🔍 Locate .vbs and .hta Files |
32 | 30 | working-directory: ./repo |
33 | 31 | run: | |
34 | 32 | find . -type f \( -iname "*.vbs" -o -iname "*.hta" \) > vbscript-files.txt |
35 | 33 | cat vbscript-files.txt || echo "No .vbs or .hta files found." |
36 | 34 |
|
37 | | - - name: ✅ Heuristic Content Check |
38 | | - id: heuristic-check |
| 35 | + - name: ✅ Heuristic Check and SARIF Generation |
39 | 36 | working-directory: ./repo |
40 | 37 | run: | |
41 | 38 | mkdir -p sarif-output |
42 | | - echo '{"version":"2.1.0","runs":[{"tool":{"driver":{"name":"VBScript Syntax Check","informationUri":"https://docs.microsoft.com/en-us/previous-versions//d1wf56tt(v=vs.85)","rules":[]}},"results":[]}]}' > sarif-output/vbscript-syntax-check.sarif |
| 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 |
43 | 40 |
|
| 41 | + first=true |
44 | 42 | while IFS= read -r file; do |
45 | | - echo "🔍 Checking: $file" |
46 | | - if file "$file" | grep -qi "text"; then |
47 | | - head -n 5 "$file" |
48 | | - else |
49 | | - echo "::warning file=$file::Not a valid text-based VBS or HTA file." |
50 | | - jq \ |
51 | | - --arg uri "$file" \ |
52 | | - '.runs[0].results += [{"ruleId": "vbscript-text-check", "message": {"text": "Not a valid text-based file"}, "locations": [{"physicalLocation": {"artifactLocation": {"uri": $uri}}]}]' \ |
53 | | - sarif-output/vbscript-syntax-check.sarif > temp.sarif && mv temp.sarif sarif-output/vbscript-syntax-check.sarif |
| 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 |
54 | 63 | fi |
55 | 64 | done < vbscript-files.txt |
56 | 65 |
|
57 | | - - name: 📤 Upload SARIF Output |
58 | | - id: sarif-output |
| 66 | + echo "]}]}" >> sarif-output/vbscript-results.sarif |
| 67 | +
|
| 68 | + - name: 📤 Upload SARIF Artifact |
59 | 69 | uses: actions/upload-artifact@v4 |
60 | 70 | with: |
61 | | - name: vbscript-syntax-check-sarif |
62 | | - path: repo/sarif-output/vbscript-syntax-check.sarif |
| 71 | + name: vbscript-sarif-results |
| 72 | + path: repo/sarif-output/vbscript-results.sarif |
63 | 73 |
|
64 | | - - name: 📊 Upload SARIF to GitHub Code Scanning (optional) |
65 | | - uses: github/codeql-action/upload-sarif@v3 |
| 74 | + - name: 📡 Publish SARIF to GitHub Code Scanning Alerts |
| 75 | + uses: github/codeql-action/upload-sarif@v2 |
66 | 76 | with: |
67 | | - sarif_file: repo/sarif-output/vbscript-syntax-check.sarif |
| 77 | + sarif_file: repo/sarif-output/vbscript-results.sarif |
0 commit comments