-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yaml
247 lines (221 loc) · 9.15 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: AutoHotkey Build
description: This is a GitHub Action that builds AutoHotkey scripts for you
author: nukdokplex
inputs:
version:
description: The version of AutoHotkey to be used (must be the version from the official AutoHotkey repository, e.g. "v1.1.29.01"). Defaults to latest.
required: false
default: latest
x64:
description: Specifies whether to compile the 64-bit version. Defaults to true.
required: false
default: "true"
x86:
description: Specifies whether to compile the 32-bit version. Defaults to false.
required: false
default: "false"
x64_suffix:
description: Specifies suffix for the 64-bit version out file. Defaults to "_x64".
required: false
default: "_x64"
x86_suffix:
description: Specifies suffix for the 32-bit version out file. Defaults to "_x86".
required: false
default: "_x86"
compression:
description: Specifies which compression method to use. "none" - do not use compression, "upx" - use UPX compression. There is no MPRESS 'cause it's discontinued. Don't try to use it, it won't work. Defaults to "none".
required: false
default: "none"
in:
description: Specifies a folder with scripts or a single script to be compiled. If you specify a folder, files with the extensions ".ahk", ".ahk2" will be taken. Recursive search in folder is not present. Defaults to CWD.
required: false
default: ""
out:
description: Specifies the folder for output files. Defaults to "build".
required: false
default: "build"
icon:
description: Specifies icon file to use. Defaults to nothing.
required: false
default: ""
runs:
using: composite
steps:
- name: "Download latest AutoHotkey release"
uses: "robinraju/[email protected]"
if: ${{ inputs.version == 'latest' }}
with:
repository: AutoHotkey/AutoHotkey
latest: true
filename: "*.exe"
tarBall: false
zipBall: false
out-file-path: "._ahk/installer"
- name: "Download specific AutoHotkey release"
uses: "robinraju/[email protected]"
if: ${{ inputs.version != 'latest' }}
with:
repository: AutoHotkey/AutoHotkey
latest: false
tag: ${{ inputs.version }}
filename: "*.exe"
tarBall: false
zipBall: false
out-file-path: "._ahk/installer"
- name: "Download latest AHK2Exe release"
uses: "robinraju/[email protected]"
with:
repository: AutoHotkey/Ahk2Exe
latest: true
filename: "*.zip"
tarBall: false
zipBall: false
out-file-path: "._ahk/ahk2exe"
- name: "Download latest UPX release"
uses: "robinraju/[email protected]"
if: ${{ inputs.compression == 'upx' }}
with:
repository: upx/upx
latest: true
filename: "*win64.zip"
tarBall: false
zipBall: false
out-file-path: "._ahk/upx"
- name: "Install AHK"
shell: pwsh
run: |
$cwd = (Get-Location).Path
$ahk = "$cwd\._ahk"
Write-Output "Preparing installer..."
Get-ChildItem -Path "$ahk\installer" -Filter *.exe -Recurse | ForEach-Object {
Move-Item -Path $_.FullName -Destination "$ahk\installer\installer.exe" -Force
}
Write-Output "Preparing AHK2Exe..."
Get-ChildItem -Path "$ahk\ahk2exe" -Filter *.zip | ForEach-Object {
Expand-Archive -Path $_.FullName -DestinationPath "$ahk\ahk2exe"
}
Get-ChildItem -Path "$ahk\ahk2exe" -Filter *.exe -Recurse | ForEach-Object {
Move-Item -Path $_.FullName -Destination "$ahk\ahk2exe\ahk2exe.exe" -Force
}
if ("upx" -eq "${{ inputs.compression }}") {
Write-Output "Preparing UPX..."
Get-ChildItem -Path "$ahk\upx" -Filter *.zip | ForEach-Object {
Expand-Archive -Path $_.FullName -DestinationPath "$ahk\upx"
}
Get-ChildItem -Path "$ahk\upx" -Filter *.exe -Recurse | ForEach-Object {
Move-Item -Path $_.FullName -Destination "$ahk\ahk2exe\upx.exe" -Force
}
}
$ahkDist = "$ahk\installation"
if ("${{ inputs.version }}" -like "v1.1.*") {
# Version 1.1.x
Write-Output "Performing AHK v1.1.x install..."
Invoke-Expression "$ahk\installer\installer.exe /S /D=$ahkDist /E"
} elseif ("${{ inputs.version }}" -like "v2.*") {
# Version 2.x
Write-Output "Performing AHK v2.x install..."
Invoke-Expression "$ahk\installer\installer.exe /silent /installto $ahkDist"
} else {
# Incompatible version
throw "Incompatible version ${{ inputs.version }} of AHK!"
}
Write-Output "AHK ${{ inputs.version }} installation completed! Ready to build!"
- name: Build
shell: pwsh
run: |
$cwd = (Get-Location).Path
$ahk = "$cwd\._ahk"
$files = [System.Collections.ArrayList]@()
$icons = [System.Collections.ArrayList]@()
$iconType = Get-Item "$cwd\${{ inputs.icon }}"
if ((Get-Item "$cwd\${{ inputs.in }}") -is [System.IO.DirectoryInfo]) {
Write-Output "Input is directory, searching files..."
$fileSpecs = ForEach-Object{("$cwd\${{ inputs.in }}\*.ahk"), $("$cwd\${{ inputs.in }}\*.ahk2")}
Get-ChildItem -Path $fileSpecs | ForEach-Object {
$files.Add($_.FullName)
}
} elseif ((Get-Item "$cwd\${{ inputs.in }}") -is [System.IO.FileInfo]) {
Write-Output "Input is file, adding it..."
$files.Add("$cwd\${{ inputs.in }}")
} else {
throw "Input doesn't exist!"
}
if ("${{ inputs.icon }}" -ne ""){
if ($iconType -is [System.IO.DirectoryInfo]) {
Write-Output "Icon is directory, searching files..."
$fileSpecs = ForEach-Object{("$cwd\${{ inputs.icon }}\*.ico")}
Get-ChildItem -Path $fileSpecs | ForEach-Object {
$icons.Add($_.FullName)
}
} elseif ($iconType -is [System.IO.FileInfo]) {
Write-Output "Icon is file, adding it..."
$icons.Add("$cwd\${{ inputs.icon }}")
} else {
Write-Output "Icon doesn't exist. Skipping."
}
} else {
Write-Output "Icon is empty. Skipping."
}
if (Test-Path -Path "$cwd\${{ inputs.out }}") {
Write-Output "Output dir already exists."
} else {
Write-Output "Output dir doesn't exist. Creating..."
mkdir -p "$cwd\${{ inputs.out }}"
}
$x64BasePath = "$ahk\installation"
$x86BasePath = "$ahk\installation"
if ("${{ inputs.version }}" -like "v1.1.*"){
Write-Output "Compiling using AHK ${{ inputs.version }}..."
$x64BasePath += "\Compiler\Unicode 64-bit.bin"
$x86BasePath += "\Compiler\Unicode 32-bit.bin"
} elseif ("${{ inputs.version }}" -like "v2.*") {
Write-Output "Compiling using AHK ${{ inputs.version }}..."
$x64BasePath += "\v2\AutoHotkey64.exe"
$x86BasePath += "\v2\AutoHotkey32.exe"
} else {
throw "Incompatible version ${{ inputs.version }}!"
}
$ahk2exe = "$ahk\ahk2exe\ahk2exe.exe"
foreach($file in $files) {
$fileNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($file)
$command = "$ahk2exe"
$command += " /silent verbose"
$command += " /in $file"
if ("${{ inputs.icon }}" -ne "") {
if ($iconType -is [System.IO.DirectoryInfo]){
foreach ($icon in $icons){
if ($fileNameWithoutExtension -eq [System.IO.Path]::GetFileNameWithoutExtension($icon)){
$command += " /icon $icon"
break
}
}
} elseif ($iconType -is [System.IO.FileInfo]){
$command += " /icon " + $iconType.FullName
}
}
if ("$compression" -eq "upx") {
$command += " /compress 2"
} else {
$command += " /compress 0"
}
if ("${{ inputs.x64 }}" -like "true"){
Write-Output ("Invoking " + $command + ' /base "'+$x64BasePath+'"' + " /out $cwd\${{ inputs.out }}\" + $fileNameWithoutExtension + "${{ inputs.x64_suffix }}.exe")
Invoke-Expression ($command + ' /base "'+$x64BasePath+'"' + " /out $cwd\${{ inputs.out }}\" + $fileNameWithoutExtension + "${{ inputs.x64_suffix }}.exe")
}
if ("${{ inputs.x86 }}" -like "true"){
Write-Output ("Invoking " + $command + ' /base "'+$x64BasePath+'"' + " /out $cwd\${{ inputs.out }}\" + $fileNameWithoutExtension + "${{ inputs.x86_suffix }}.exe")
Invoke-Expression ($command + ' /base "'+$x64BasePath+'"' + " /out $cwd\${{ inputs.out }}\" + $fileNameWithoutExtension + "${{ inputs.x86_suffix }}.exe")
}
}
Write-Output "Build completed!"
- name: Clean
shell: pwsh
run: |
$cwd = (Get-Location).Path
$ahk = "$cwd\._ahk"
Write-Output "Cleaning $ahk"
Remove-Item $ahk -Recurse -Force
Write-Output "Cleaning complete!"
branding:
icon: code
color: green