-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
400 lines (327 loc) · 14.6 KB
/
action.yml
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
name: "Setup CODESYS Installation"
author: powerIO GmbH
description: "Setup CODESYS Installation for headless CI/CD Jobs"
branding:
icon: "package"
color: "red"
inputs:
installer-version:
description: "The version of the installer to use to install the CODESYS installation."
required: false
default: 2.3.0
generation:
description: >
'This is the base generation you want to install. For example `3.5.19.0`.
Even if you want to install the version `3.5.19.6` you have to define the generation as `3.5.19.0`.
The patch version is defined by the `patch` input.'
required: false
default: 3.5.20.0
architecture:
description: "The installation architecture of CODESYS. Allowed inputs: `32` and `64`."
required: false
default: 64
patch:
description: "The patch of the CODESYS version to install."
required: false
default: 0
hotfix:
description: "The hotfix of the CODESYS version to install."
required: false
default: 0
build:
description: "The build of the CODESYS version to install."
required: false
default: 0
installation-directory:
description: >
'This can be used to define a custom installation directory.
If this input is empty, the installation path is set based on the architecture and installation version.
For example - bit `64`, generation `3.5.20.0` and patch `3`:
`C:\Program Files\CODESYS 3.5.20.3`
For example - bit `32`, generation `3.5.17.0` and patch `2`:
`C:\Program Files (x86)\CODESYS 3.5.17.2`'
required: false
default: ""
auto-update-installer:
description: "If set to `true`, the installer will be updated before the installation."
required: false
default: true
install-add-ons:
description: "If set to `true`, the installer will install the CODESYS AddOns."
required: false
default: false
add-ons-list:
description: >
'A list of addons to install.
Given by the id and the version of the addon.
For example - Install Git `dd6c2da4-2ed2-4076-9bf7-52394db68819,1.4.0.0`
If you want to install multiple addons, create a new line for each addon.
For example - Install Git and Library dev package
```
dd6c2da4-2ed2-4076-9bf7-52394db68819,1.4.0.0
fb6f3506-d165-4e75-a1b9-98895d542cc8,4.5.0.0
```
'
required: false
default: ''
add-ons-from-file-list:
description: >
'A list of addons to install.
Given by the path to the *.package file'
required: false
default: ''
outputs:
codesys-path:
value: ${{ steps.parameter_validation.outputs.installation-path }}
description: "The path of the installed CODESYS version."
codesys-executable:
value: ${{ steps.parameter_validation.outputs.installation-path }}\CODESYS\Common\CODESYS.exe
description: "The path of the CODESYS executable."
installer-path:
value: ${{ steps.globals.outputs.INSTALLER_DIR }}
description: "The path of the installed CODESYS installer."
installer-cli-executable:
value: ${{ steps.globals.outputs.INSTALLER_DIR }}\APInstaller.CLI.exe
description: "The path of the CODESYS installer CLI executable."
installation-info-file-path:
value: ${{ steps.install_info.outputs.installation-info-file-path }}
description: "The path of the installation information file."
runs:
using: composite
steps:
- name: Check runner OS
if: runner.os != 'Windows'
shell: pwsh
run: | # powershell
Write-Host "::error::This action is only supported on Windows runners."
exit 1
- name: Set globals
id: globals
shell: pwsh
run: | # powershell
Write-Host "::group::Set Global variables for installation"
"BASE_URL_INSTALLER=https://store-archive.codesys.com/ftp_download/3S/Installer/000127" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
"INSTALLER_VERSION=${{ inputs.installer-version }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
"INSTALLER_DIR=C:\Program Files (x86)\CODESYS\APInstaller" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
Write-Host "::endgroup::"
- name: Download installer
shell: pwsh
run: | # powershell
Write-Host "::group::Download CODESYS installer"
$base_url = "${{ steps.globals.outputs.BASE_URL_INSTALLER }}"
$version = "${{ steps.globals.outputs.INSTALLER_VERSION }}"
$installer_url = "$base_url/$version/CODESYS%20Installer%20$version.exe"
$output_file = "installer.exe"
Write-Host "Downloading installer from $installer_url"
Invoke-WebRequest -Uri $installer_url -OutFile $output_file
Write-Host "::endgroup::"
- name: Install CODESYS installer
shell: pwsh
run: | # powershell
Write-Host "::group::Install CODESYS installer"
Write-Host "This process will take a few seconds. Please be patient."
Start-Process -FilePath "installer.exe" -ArgumentList "/S /v/qb" -Wait
Remove-Item -Path "installer.exe"
Write-Host "::endgroup::"
- if: ${{ inputs.auto-update-installer == 'true' }}
name: Update Installer
shell: pwsh
run: | # powershell
Write-Host "::group::Update CODESYS installer"
$exePath = "${{ steps.globals.outputs.INSTALLER_DIR }}\APInstaller.CLI.exe"
$process = Start-Process -FilePath $exePath -ArgumentList "--selfUpdate" -Wait -NoNewWindow -PassThru
if ($process.ExitCode -eq 1 -or $process.ExitCode -eq -1) {
exit 0
} elseif ($process.ExitCode -ne 0) {
throw "Update failed with exit code $($process.ExitCode)."
}
Write-Host "::endgroup::"
- name: Prepare and validate inputs
id: parameter_validation
shell: pwsh
run: | # powershell
Write-Host "::group::Validate inputs"
$generation = "${{ inputs.generation }}"
$architecture = "${{ inputs.architecture }}"
$patch = "${{ inputs.patch }}"
$hotfix = "${{ inputs.hotfix }}"
$build = "${{ inputs.build }}"
$installationDirectory = "${{ inputs.installation-directory }}"
if ($generation -notmatch '^\d+\.\d+\.\d+\.\d+$') {
Write-Host "Generation format is invalid. Must be X.X.X.X where X is a number."
exit 1
}
if ($architecture -ne "64" -and $architecture -ne "32") {
Write-Host "Architecture must be 64 or 32."
exit 1
}
if ($patch -notmatch '^\d+$' -or $hotfix -notmatch '^\d+$' -or $build -notmatch '^\d+$') {
Write-Host "Patch, Hotfix, and Build must be numeric."
exit 1
}
# Split the generation into parts
$version_parts = $generation -split '\.'
$length = $version_parts.Length
$last_index = $length - 1
$version_parts[$last_index] = $patch
$new_generation = $version_parts -join '.'
$installation_name = "CODESYS $new_generation"
if ([string]::IsNullOrWhiteSpace($installationDirectory)) {
if ($architecture -eq "64") {
$installation_path = "C:\Program Files\$installation_name"
} else {
$installation_path = "C:\Program Files (x86)\$installation_name"
}
} else {
$installation_path = $installationDirectory
}
Write-Host "Installation path set to: $installation_path"
"installation-path=$installation_path" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
"installation-name=$installation_name" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
Write-Host "::endgroup::"
- name: Install CODESYS
shell: pwsh
run: | # powershell
Write-Host "::group::Install CODESYS"
Write-Host "This process will take a few minutes. Please be patient."
$exePath = "${{ steps.globals.outputs.INSTALLER_DIR }}\APInstaller.CLI.exe"
$arguments = "--createInstallation " +
"--product CODESYS " +
"--generation `"${{ inputs.generation }}`" " +
"--bit `"${{ inputs.architecture }}`" " +
"--patch `"${{ inputs.patch }}`" " +
"--hotfix `"${{ inputs.hotfix }}`" " +
"--build `"${{ inputs.build }}`" " +
"--installationName `"${{ steps.parameter_validation.outputs.installation-name }}`" " +
"--destinationFolder `"${{ steps.parameter_validation.outputs.installation-path }}`""
Write-Host "Executing: $exePath $arguments"
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = $exePath
$startInfo.Arguments = $arguments
$startInfo.UseShellExecute = $true # Required for elevation
$startInfo.Verb = "runas" # Request elevation
try {
$process = Start-Process -FilePath $exePath -ArgumentList $arguments -Verb runas -Wait -PassThru
$exitCode = $process.ExitCode
Write-Host "Process completed with exit code: $exitCode"
if ($exitCode -eq 1 -or $exitCode -eq -1) {
Write-Host "Installation completed with expected exit code"
exit 0
} elseif ($exitCode -ne 0) {
throw "Installation failed with exit code $exitCode"
}
}
catch {
Write-Host "Error during installation: $_"
exit 1
}
Write-Host "Finished installation"
Write-Host "::endgroup::"
- name: Decide add-ons path
id: add_ons_path
shell: pwsh
run: | # powershell
Write-Host "::group::Show installation path"
$base_path = "${{ steps.parameter_validation.outputs.installation-path }}"
$installation_name = "${{ steps.parameter_validation.outputs.installation-name }}"
$dir_add_ons = ''
if (Test-Path $base_path) {
$path1 = Join-Path $base_path "CODESYS\AdditionalFolders\$installation_name"
$path2 = Join-Path $base_path "CODESYS"
if (Test-Path $path1) {
$dir_add_ons = $path1
} elseif (Test-Path $path2) {
$dir_add_ons = $path2
} else {
Write-Host "Installation path does not exist"
exit 1
}
} else {
Write-Host "Installation path does not exist"
exit 1
}
Write-Host "Add-Ons directory: $dir_add_ons"
"directory=$dir_add_ons" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
Write-Host "::endgroup::"
- if: (inputs.install-add-ons == 'true' && inputs.add-ons-list != '')
name: Install Add-ons from text entry list
shell: pwsh
run: | # powershell
Write-Host "::group::Install AddOns"
$addonsToInstall = @()
$rawList = "${{ inputs.add-ons-list }}" -split "\r?\n"
foreach ($line in $rawList) {
if (-not [string]::IsNullOrWhiteSpace($line)) {
$addonsToInstall += $line.Trim()
}
}
foreach ($addon in $addonsToInstall) {
$details = $addon -split ","
$id = $details[0].Trim()
$version = $details[1].Trim()
Write-Host "Installing addon with ID: $id and Version: $version"
$exePath = "${{ steps.globals.outputs.INSTALLER_DIR }}\APInstaller.CLI.exe"
$arguments = "--installAddOn " +
"--location `"${{ steps.add_ons_path.outputs.directory }}`" " +
"--id `"${id}`" " +
"--version `"${version}`""
$process = Start-Process -FilePath $exePath -ArgumentList $arguments -Verb runas -Wait -PassThru
if ($process.ExitCode -eq 1 -or $process.ExitCode -eq -1) {
exit 0
} elseif ($process.ExitCode -ne 0) {
throw "AddOn installation failed with exit code $($process.ExitCode)."
}
}
Write-Host "Finished installing addons"
Write-Host "::endgroup::"
- if: (inputs.install-add-ons == 'true' && inputs.add-ons-from-file-list != '')
name: Install Add-ons from file list
shell: pwsh
run: | # powershell
Write-Host "::group::Install AddOns"
$packagesToInstall = @()
$rawList = "${{ inputs.add-ons-from-file-list }}" -split "\r?\n"
foreach ($line in $rawList) {
if (-not [string]::IsNullOrWhiteSpace($line)) {
# Properly handle paths with Join-Path
$packagePath = Join-Path $env:GITHUB_WORKSPACE $line.Trim()
$packagesToInstall += $packagePath
}
}
foreach ($packagePath in $packagesToInstall) {
Write-Host "Installing package from path: $packagePath"
$exePath = "${{ steps.globals.outputs.INSTALLER_DIR }}\APInstaller.CLI.exe"
$arguments = "--installAddOnFromFile " +
"--location `"${{ steps.add_ons_path.outputs.directory }}`" " +
"--sourcefile `"${packagePath}`""
$process = Start-Process -FilePath $exePath -ArgumentList $arguments -Verb runas -Wait -PassThru
if ($process.ExitCode -eq 1 -or $process.ExitCode -eq -1) {
exit 0
} elseif ($process.ExitCode -ne 0) {
throw "AddOn installation failed with exit code $($process.ExitCode)."
}
}
Write-Host "Finished installing addons"
Write-Host "::endgroup::"
- name: Show installation information
id: install_info
shell: pwsh
run: | # powershell
Write-Host "::group::Show installation information"
Write-Host "This process will take a few seconds. Please be patient."
$exePath = "${{ steps.globals.outputs.INSTALLER_DIR }}\APInstaller.CLI.exe"
$outputFile = Join-Path -Path $PWD -ChildPath "installation-info.json"
$arguments = "--getInstallation " +
"--location `"${{ steps.add_ons_path.outputs.directory }}`" " +
"--outputfile `"${outputFile}`""
$process = Start-Process -FilePath $exePath -ArgumentList $arguments -Wait -NoNewWindow -PassThru
if ($process.ExitCode -eq 1 -or $process.ExitCode -eq -1) {
exit 0
} elseif ($process.ExitCode -ne 0) {
throw "Information extraction failed with exit code $($process.ExitCode)."
}
"installation-info-file-path=$outputFile" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
Write-Host "Output file path: $outputFile"
Get-Content -Path "$outputFile" -Encoding UTF8
Write-Host "Finished installation information extraction"
Write-Host "::endgroup::"