forked from powerIO-GmbH/action-codesys-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
358 lines (296 loc) · 13 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
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.2.2
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.19.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.19.0` and patch `6`:
`C:\Program Files\CODESYS 3.5.19.6`
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: |
echo "::error::This action is only supported on Windows runners."
exit 1
- name: Set globals
id: globals
shell: pwsh
run: |
echo "::group::Set Global variables for installation"
echo "BASE_URL_INSTALLER=https://store-archive.codesys.com/ftp_download/3S/Installer/000127" >> $env:GITHUB_OUTPUT
echo "INSTALLER_VERSION=${{ inputs.installer-version }}" >> $env:GITHUB_OUTPUT
echo "INSTALLER_DIR=C:\Program Files (x86)\CODESYS\APInstaller" >> $env:GITHUB_OUTPUT
echo "::endgroup::"
- name: Download installer
shell: bash
run: |
echo "::group::Download CODESYS installer"
base_url=${{ steps.globals.outputs.BASE_URL_INSTALLER }}
version=${{ steps.globals.outputs.INSTALLER_VERSION }}
curl "${base_url}/${version}/CODESYS%20Installer%20${version}.exe" -o installer.exe
echo "::endgroup::"
- name: Install CODESYS installer
shell: pwsh
run: |
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: |
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: bash
run: |
echo "::group::Validate inputs"
if ! [[ ${{ inputs.generation }} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Generation format is invalid. Must be X.X.X.X where X is a number."
exit 1
fi
if [ "${{ inputs.architecture }}" != "64" ] && [ "${{ inputs.architecture }}" != "32" ]; then
echo "Architecture must be 64 or 32."
exit 1
fi
if ! [[ ${{ inputs.patch }} =~ ^[0-9]+$ ]] \
|| ! [[ ${{ inputs.hotfix }} =~ ^[0-9]+$ ]] \
|| ! [[ ${{ inputs.build }} =~ ^[0-9]+$ ]]; then
echo "Patch, Hotfix, and Build must be numeric."
exit 1
fi
IFS='.' read -ra version_parts <<< "${{ inputs.generation }}"
length=${#version_parts[@]}
let "last_index=length-1"
version_parts[$last_index]=${{ inputs.patch }}
new_generation="${version_parts[0]}"
for (( i=1; i<${#version_parts[@]}; i++ )); do
new_generation="$new_generation.${version_parts[$i]}"
done
installation_name="CODESYS $(echo "${new_generation}" | sed 's/ /./g')"
if [[ -z "${{ inputs.installation-directory }}" ]]; then
if [ "${{ inputs.architecture }}" == "64" ]; then
installation_path="C:\\Program Files\\${installation_name}"
else
installation_path="C:\\Program Files (x86)\\${installation_name}"
fi
else
installation_path="${{ inputs.installation-directory }}"
fi
echo "Installation path set to: $installation_path"
echo "installation-path=$installation_path" >> $GITHUB_OUTPUT
echo "installation-name=$installation_name" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: Install CODESYS
shell: pwsh
run: |
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 }}`""
$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 "Update failed with exit code $($process.ExitCode)."
}
Write-Host "Finished installation"
Write-Host "::endgroup::"
- name: Decide add-ons path
id: add_ons_path
shell: bash
run: |
echo "::group::Show installation path"
base_path="${{ steps.parameter_validation.outputs.installation-path }}"
dir_add_ons=''
if [[ -d "$base_path" ]]; then
if [[ -d "${base_path}\CODESYS\AdditionalFolders\${{ steps.parameter_validation.outputs.installation-name }}" ]]; then
dir_add_ons="${base_path}\CODESYS\AdditionalFolders\${{ steps.parameter_validation.outputs.installation-name }}"
else
if [[ -d "${base_path}\CODESYS" ]]; then
dir_add_ons="${base_path}\CODESYS"
else
echo "Installation path does not exist"
exit 1
fi
fi
else
echo "Installation path does not exist"
exit 1
fi
echo "Add-Ons directory: $dir_add_ons"
echo "directory=$dir_add_ons" >> $GITHUB_OUTPUT
echo "::endgroup::"
- if: (inputs.install-add-ons == 'true' && inputs.add-ons-list != '')
name: Install Add-ons from list
shell: pwsh
run: |
Write-Host "::group::Install AddOns"
$addonsToInstall = "${{ inputs.add-ons-list }}" -split "\r?\n"
foreach ($addon in $addonsToInstall) {
if (-not [string]::IsNullOrWhiteSpace($addon)) {
$details = $addon -split ","
$id = $details[0].Trim()
$version = $details[1].Trim()
echo "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 -Wait -NoNewWindow -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 list
shell: pwsh
run: |
echo "::group::Install AddOns"
$packagesToInstall = "${{ inputs.add-ons-from-file-list }}" -split "\r?\n"
foreach ($packagePath in $packagesToInstall) {
if (-not [string]::IsNullOrWhiteSpace($packagePath)) {
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 -Wait -NoNewWindow -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)."
}
}
}
echo "Finished installing addons"
echo "::endgroup::"
- name: Show installation information
id: install_info
shell: pwsh
run: |
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)."
}
Write-Host "installation-info-file-path=$outputFile" >> $env:GITHUB_OUTPUT
Write-Host "Output file path: $outputFile"
Get-Content -Path "$outputFile" -Encoding UTF8
Write-Host "Finished installation information extraction"
Write-Host "::endgroup::"