|
1 | | -name: AutoHotkey Lint, Format & Compile |
| 1 | +name: AHK Lint & Format |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: [ main, master ] |
6 | | - paths: |
7 | | - - '**.ahk' |
8 | | - - '.github/workflows/ahk-lint-format-compile.yml' |
| 5 | + branches: [main, master] |
| 6 | + paths: ['**.ahk', '.github/workflows/ahk-lint-format-compile.yml'] |
9 | 7 | pull_request: |
10 | | - branches: [ main, master ] |
11 | | - paths: |
12 | | - - '**.ahk' |
13 | | - - '.github/workflows/ahk-lint-format-compile.yml' |
| 8 | + branches: [main, master] |
| 9 | + paths: ['**.ahk', '.github/workflows/ahk-lint-format-compile.yml'] |
14 | 10 | workflow_dispatch: |
15 | 11 |
|
16 | 12 | permissions: |
17 | | - contents: write |
| 13 | + contents: read |
18 | 14 |
|
19 | 15 | jobs: |
20 | | - lint-format-compile: |
21 | | - name: Lint, Format & Compile AHK Scripts |
| 16 | + lint: |
22 | 17 | runs-on: windows-latest |
23 | | - |
24 | 18 | steps: |
25 | | - - name: Checkout Repository |
26 | | - uses: actions/checkout@v4 |
27 | | - with: |
28 | | - fetch-depth: 0 |
| 19 | + - uses: actions/checkout@v4 |
29 | 20 |
|
30 | 21 | - name: Install AutoHotkey |
31 | 22 | run: | |
32 | | - # Download and install AutoHotkey v1.1 |
33 | | - $ahkUrl = "https://www.autohotkey.com/download/ahk-install.exe" |
34 | | - $installer = "$env:TEMP\ahk-install.exe" |
35 | | - Invoke-WebRequest -Uri $ahkUrl -OutFile $installer |
36 | | - Start-Process -FilePath $installer -ArgumentList "/S" -Wait |
37 | | - |
38 | | - # Verify installation |
39 | | - if (Test-Path "C:\Program Files\AutoHotkey\AutoHotkey.exe") { |
40 | | - Write-Host "AutoHotkey installed successfully" |
41 | | - & "C:\Program Files\AutoHotkey\AutoHotkey.exe" //version |
42 | | - } else { |
43 | | - Write-Error "AutoHotkey installation failed" |
44 | | - exit 1 |
45 | | - } |
46 | | - shell: pwsh |
47 | | - |
48 | | - - name: Setup Formatter |
49 | | - run: | |
50 | | - # Note: For security, we're using built-in format checking instead of downloading external scripts |
51 | | - # The format checking is done in PowerShell in the next step |
52 | | - Write-Host "Format checking will be performed using built-in PowerShell validation" |
| 23 | + $url = "https://www.autohotkey.com/download/ahk-install.exe" |
| 24 | + $inst = "$env:TEMP\ahk-install.exe" |
| 25 | + iwr -Uri $url -OutFile $inst |
| 26 | + Start-Process -FilePath $inst -ArgumentList "/S" -Wait |
| 27 | + if (!(Test-Path "C:\Program Files\AutoHotkey\AutoHotkey.exe")) { exit 1 } |
53 | 28 | shell: pwsh |
54 | 29 |
|
55 | | - - name: Syntax Check All AHK Scripts |
56 | | - id: syntax-check |
| 30 | + - name: Syntax Check |
57 | 31 | run: | |
58 | | - $ahkExe = "C:\Program Files\AutoHotkey\AutoHotkey.exe" |
59 | 32 | $compiler = "C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" |
| 33 | + $tempDir = New-Item -ItemType Directory -Force -Path "$env:TEMP\ahk-check-$(Get-Random)" |
60 | 34 | $errors = @() |
61 | 35 | $checked = 0 |
62 | | - $failed = 0 |
63 | 36 | |
64 | | - Write-Host "Starting syntax check of all .ahk files..." |
65 | | - Write-Host "=" * 60 |
66 | | - |
67 | | - # Create a temporary directory for syntax checking |
68 | | - $tempDir = New-Item -ItemType Directory -Force -Path "$env:TEMP\ahk-syntax-check-$(Get-Random)" |
69 | | - |
70 | | - Get-ChildItem -Path . -Filter "*.ahk" -Recurse | ForEach-Object { |
71 | | - $file = $_.FullName |
72 | | - $relativePath = $_.FullName.Replace((Get-Location).Path + "\", "") |
| 37 | + Get-ChildItem -Recurse -Filter "*.ahk" | ForEach-Object { |
73 | 38 | $checked++ |
| 39 | + $tempExe = Join-Path $tempDir "$([System.IO.Path]::GetRandomFileName()).exe" |
| 40 | + $rel = $_.FullName.Replace("$(Get-Location)\", "") |
74 | 41 | |
75 | | - Write-Host "`nChecking: $relativePath" |
76 | | - |
77 | | - # Use the compiler in syntax-check mode (compile without actually creating exe) |
78 | | - # This is more reliable than trying to run the script |
79 | | - $tempExe = Join-Path $tempDir "temp_$([System.IO.Path]::GetRandomFileName()).exe" |
80 | | - |
81 | | - try { |
82 | | - $result = & $compiler /in $file /out $tempExe 2>&1 |
83 | | - |
84 | | - # Check if compilation was successful (even if we don't need the exe) |
85 | | - if ($LASTEXITCODE -eq 0 -or (Test-Path $tempExe)) { |
86 | | - Write-Host " ✓ OK" -ForegroundColor Green |
87 | | - # Clean up the temp exe |
88 | | - if (Test-Path $tempExe) { |
89 | | - Remove-Item $tempExe -Force -ErrorAction SilentlyContinue |
90 | | - } |
91 | | - } else { |
92 | | - $failed++ |
93 | | - $errorMsg = "Syntax error in ${relativePath}: $result" |
94 | | - Write-Host " ❌ FAILED" -ForegroundColor Red |
95 | | - Write-Host " $result" -ForegroundColor Red |
96 | | - $errors += $errorMsg |
97 | | - } |
98 | | - } catch { |
99 | | - $failed++ |
100 | | - $errorMsg = "Error checking ${relativePath}: $_" |
101 | | - Write-Host " ❌ FAILED: $_" -ForegroundColor Red |
102 | | - $errors += $errorMsg |
| 42 | + & $compiler /in $_.FullName /out $tempExe 2>&1 | Out-Null |
| 43 | + if ($LASTEXITCODE -eq 0 -and (Test-Path $tempExe)) { |
| 44 | + Write-Host "✓ $rel" -ForegroundColor Green |
| 45 | + Remove-Item $tempExe -Force -ErrorAction SilentlyContinue |
| 46 | + } else { |
| 47 | + Write-Host "❌ $rel" -ForegroundColor Red |
| 48 | + $errors += $rel |
103 | 49 | } |
104 | 50 | } |
105 | 51 | |
106 | | - # Clean up temp directory |
107 | 52 | Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue |
108 | | - |
109 | | - Write-Host "`n" + ("=" * 60) |
110 | | - Write-Host "Syntax Check Summary:" |
111 | | - Write-Host " Total scripts checked: $checked" |
112 | | - Write-Host " Passed: $($checked - $failed)" |
113 | | - Write-Host " Failed: $failed" |
114 | | - |
115 | | - if ($errors.Count -gt 0) { |
116 | | - Write-Host "`nErrors found:" -ForegroundColor Red |
117 | | - $errors | ForEach-Object { Write-Host " - $_" -ForegroundColor Red } |
118 | | - Write-Host "`nNote: The build will continue, but please review and fix these errors." -ForegroundColor Yellow |
119 | | - # Don't fail the build for syntax errors - let compilation step handle it |
120 | | - } else { |
121 | | - Write-Host "`n✓ All scripts passed syntax check!" -ForegroundColor Green |
122 | | - } |
| 53 | + Write-Host "`nChecked: $checked | Failed: $($errors.Count)" |
| 54 | + if ($errors.Count -gt 0) { exit 1 } |
123 | 55 | shell: pwsh |
124 | | - continue-on-error: true |
125 | 56 |
|
126 | | - - name: Format Check AHK Scripts |
127 | | - id: format |
128 | | - if: success() |
| 57 | + - name: Format Check |
129 | 58 | run: | |
130 | | - Write-Host "Running basic format checks..." |
131 | | - Write-Host "=" * 60 |
132 | | - |
133 | 59 | $issues = @() |
134 | | - $checked = 0 |
135 | 60 | |
136 | | - Get-ChildItem -Path . -Filter "*.ahk" -Recurse | ForEach-Object { |
137 | | - $file = $_.FullName |
138 | | - $relativePath = $_.FullName.Replace((Get-Location).Path + "\", "") |
139 | | - $checked++ |
140 | | - |
141 | | - $content = Get-Content $file -Raw |
| 61 | + Get-ChildItem -Recurse -Filter "*.ahk" | ForEach-Object { |
| 62 | + $content = Get-Content $_.FullName -Raw |
| 63 | + $rel = $_.FullName.Replace("$(Get-Location)\", "") |
| 64 | + $problems = @() |
142 | 65 | |
143 | | - # Check for common formatting issues |
144 | | - $hasTabsAndSpaces = ($content -match "(?m)^\t" -and $content -match "(?m)^ ") |
145 | | - $hasTrailingWhitespace = ($content -match "[ \t]+`r?`n") |
146 | | - $hasMixedLineEndings = (($content -match "`r`n") -and ($content -match "(?<!`r)`n")) |
147 | | - |
148 | | - if ($hasTabsAndSpaces -or $hasTrailingWhitespace -or $hasMixedLineEndings) { |
149 | | - $issues += $relativePath |
150 | | - Write-Host "`n⚠ $relativePath" -ForegroundColor Yellow |
151 | | - if ($hasTabsAndSpaces) { Write-Host " - Mixed tabs and spaces" -ForegroundColor Yellow } |
152 | | - if ($hasTrailingWhitespace) { Write-Host " - Trailing whitespace" -ForegroundColor Yellow } |
153 | | - if ($hasMixedLineEndings) { Write-Host " - Mixed line endings" -ForegroundColor Yellow } |
| 66 | + if (($content -match "(?m)^\t") -and ($content -match "(?m)^ ")) { |
| 67 | + $problems += "mixed indentation" |
| 68 | + } |
| 69 | + if ($content -match "[ \t]+`r?`n") { |
| 70 | + $problems += "trailing whitespace" |
| 71 | + } |
| 72 | + if (($content -match "`r`n") -and ($content -match "(?<!`r)`n")) { |
| 73 | + $problems += "mixed line endings" |
154 | 74 | } |
155 | | - } |
156 | | - |
157 | | - Write-Host "`n" + ("=" * 60) |
158 | | - Write-Host "Format Check Summary:" |
159 | | - Write-Host " Total scripts checked: $checked" |
160 | | - Write-Host " Scripts with format issues: $($issues.Count)" |
161 | | - |
162 | | - if ($issues.Count -gt 0) { |
163 | | - Write-Host "`n⚠ Some scripts have formatting issues (non-critical)" -ForegroundColor Yellow |
164 | | - } else { |
165 | | - Write-Host "`n✓ No formatting issues found!" -ForegroundColor Green |
166 | | - } |
167 | | - shell: pwsh |
168 | | - continue-on-error: true |
169 | | - |
170 | | - - name: Compile AHK Scripts |
171 | | - id: compile |
172 | | - if: success() |
173 | | - run: | |
174 | | - $ahkExe = "C:\Program Files\AutoHotkey\AutoHotkey.exe" |
175 | | - $compilerPath = "C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" |
176 | | - |
177 | | - # Create output directory for compiled executables |
178 | | - $outputDir = "compiled" |
179 | | - New-Item -ItemType Directory -Force -Path $outputDir | Out-Null |
180 | | - |
181 | | - Write-Host "Starting compilation of AHK scripts..." |
182 | | - Write-Host "=" * 60 |
183 | | - |
184 | | - $compiled = 0 |
185 | | - $failed = 0 |
186 | | - |
187 | | - # Get all .ahk files |
188 | | - $ahkFiles = Get-ChildItem -Path . -Filter "*.ahk" -Recurse | Where-Object { |
189 | | - # Exclude the formatter script if it exists |
190 | | - $_.FullName -notlike "*\formatter.ahk" |
191 | | - } |
192 | | - |
193 | | - foreach ($file in $ahkFiles) { |
194 | | - $relativePath = $file.FullName.Replace((Get-Location).Path + "\", "") |
195 | | - $fileName = $file.BaseName |
196 | | - |
197 | | - # Create subdirectory structure in output |
198 | | - $relativeDir = Split-Path -Parent $relativePath |
199 | | - $outSubDir = Join-Path $outputDir $relativeDir |
200 | | - New-Item -ItemType Directory -Force -Path $outSubDir | Out-Null |
201 | | - |
202 | | - $outputExe = Join-Path $outSubDir "$fileName.exe" |
203 | | - |
204 | | - Write-Host "`nCompiling: $relativePath" |
205 | | - Write-Host " Output: $outputExe" |
206 | 75 | |
207 | | - try { |
208 | | - # Use Ahk2Exe to compile the script |
209 | | - $compileArgs = @( |
210 | | - "/in", $file.FullName, |
211 | | - "/out", $outputExe |
212 | | - ) |
213 | | - |
214 | | - & $compilerPath $compileArgs |
215 | | - |
216 | | - if (Test-Path $outputExe) { |
217 | | - $compiled++ |
218 | | - Write-Host " ✓ Compiled successfully" -ForegroundColor Green |
219 | | - } else { |
220 | | - $failed++ |
221 | | - Write-Host " ❌ Compilation failed" -ForegroundColor Red |
222 | | - } |
223 | | - } catch { |
224 | | - $failed++ |
225 | | - Write-Host " ❌ Error: $_" -ForegroundColor Red |
| 76 | + if ($problems.Count -gt 0) { |
| 77 | + Write-Host "⚠ $rel : $($problems -join ', ')" -ForegroundColor Yellow |
| 78 | + $issues += $rel |
226 | 79 | } |
227 | 80 | } |
228 | 81 | |
229 | | - Write-Host "`n" + ("=" * 60) |
230 | | - Write-Host "Compilation Summary:" |
231 | | - Write-Host " Total scripts: $($ahkFiles.Count)" |
232 | | - Write-Host " Compiled: $compiled" |
233 | | - Write-Host " Failed: $failed" |
234 | | - |
235 | | - if ($failed -gt 0) { |
236 | | - Write-Host "`n⚠ Some scripts failed to compile" -ForegroundColor Yellow |
| 82 | + if ($issues.Count -gt 0) { |
| 83 | + Write-Host "`n$($issues.Count) file(s) with format issues" -ForegroundColor Yellow |
237 | 84 | } else { |
238 | | - Write-Host "`n✓ All scripts compiled successfully!" -ForegroundColor Green |
| 85 | + Write-Host "✓ All files formatted correctly" -ForegroundColor Green |
239 | 86 | } |
240 | 87 | shell: pwsh |
241 | | - continue-on-error: true |
242 | | - |
243 | | - - name: Upload Compiled Scripts |
244 | | - if: always() && steps.compile.outcome == 'success' |
245 | | - uses: actions/upload-artifact@v4 |
246 | | - with: |
247 | | - name: compiled-ahk-scripts |
248 | | - path: compiled/**/*.exe |
249 | | - if-no-files-found: warn |
250 | | - retention-days: 30 |
251 | | - |
252 | | - - name: Workflow Summary |
253 | | - if: always() |
254 | | - run: | |
255 | | - Write-Host "`n" + ("=" * 60) |
256 | | - Write-Host "WORKFLOW SUMMARY" |
257 | | - Write-Host "=" * 60 |
258 | | - |
259 | | - Write-Host "`nStep Results:" |
260 | | - Write-Host " Syntax Check: ${{ steps.syntax-check.outcome }}" |
261 | | - Write-Host " Formatting: ${{ steps.format.outcome }}" |
262 | | - Write-Host " Compilation: ${{ steps.compile.outcome }}" |
263 | | - |
264 | | - Write-Host "`n✓ Workflow completed!" -ForegroundColor Green |
265 | | - Write-Host "`nNote: Check the individual step outputs above for any warnings or errors." |
266 | | - shell: pwsh |
0 commit comments