-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
323 lines (275 loc) · 15.2 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
# Copyright (c) IncQuery Labs cPlc.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
name: IncQuery Validator for Enterprise Architect
description: This action downloads and installs the IncQuery Validator for Enterprise Architect, then runs a validation on the given model with the given ruleset.
inputs:
model_file_path:
description: "Path to the model file."
required: true
analysis_suite:
description: "Name of the analysis suite (ruleset) to validate with."
required: true
incquery_username:
description: "Username to https://artifacts.incquery.io/. Not required if the validator is already installed on the runner."
required: false
incquery_password:
description: "Password to https://artifacts.incquery.io/. Not required if the validator is already installed on the runner."
required: false
license:
description: "The contents of the supplied license file."
required: true
comment_on_pr:
description: "Comment on the pull request with the result of the analysis."
required: false
default: 'false'
fail_on:
description: "Fail the workflow if there are any findings with the level equal or greater to the specified. Possible values are: 'none' (don't fail on anything), 'debug', 'info', 'warning', 'error', 'fatal'."
required: false
default: 'warning'
mdgtPaths:
description: "Path(s) to the folder(s) where the MDG Technology descriptor XML files are located. Paths are separated by \";\". Only required when using Structural validation."
required: false
default: ''
runs:
using: "composite"
steps:
- name: Determining if IncQuery Validator for Enterprise Architect needs to be installed or not
id: validator-state
shell: pwsh
run: |
if (Test-Path -Path 'C:/Program Files/IncQuery Labs/IncQuery Validator for Enterprise Architect/CI/run_validation.ps1' -PathType Leaf )
{
echo "IncQuery Validator for Enterprise Architect is already installed."
echo "need_to_install=false" >> $env:GITHUB_OUTPUT
}
else
{
echo "IncQuery Validator for Enterprise Architect will be installed."
echo "need_to_install=true" >> $env:GITHUB_OUTPUT
echo "download_url=https://build.incquerylabs.com/nexus/repository/lieberlieber-collaboration-raw/validator-for-ea/release-2024.2.0/IncQuery%20Validator%20for%20Enterprise%20Architect%202024.2.0%20Setup.exe" >> $env:GITHUB_OUTPUT
echo "installer_path=${{ runner.temp }}/IncQuery Validator for Enterprise Architect Setup.exe" >> $env:GITHUB_OUTPUT
}
- name: Restore the IncQuery Validator for Enterprise Architect installer from cache
id: cache-installer-restore
uses: actions/cache/restore@v4
if: ${{ steps.validator-state.outputs.need_to_install == 'true' }}
with:
path: ${{ steps.validator-state.outputs.installer_path }}
key: ${{ steps.validator-state.outputs.download_url }}
- name: Download the IncQuery Validator for Enterprise Architect installer
shell: pwsh
if: ${{ ( steps.cache-installer-restore.outputs.cache-hit != 'true' ) && ( steps.validator-state.outputs.need_to_install == 'true' ) }}
run: |
$user = "${{ inputs.incquery_username }}"
$pass= "${{ inputs.incquery_password }}"
if ( $user.Length -eq 0 ) { exit 1 }
if ( $pass.Length -eq 0 ) { exit 1 }
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
Invoke-WebRequest ${{ steps.validator-state.outputs.download_url }} -Credential $credential -OutFile '${{ steps.validator-state.outputs.installer_path }}'
- name: Cache the IncQuery Validator for Enterprise Architect installer
id: cache-installer-save
if: ${{ ( steps.cache-installer-restore.outputs.cache-hit != 'true' ) && ( steps.validator-state.outputs.need_to_install == 'true' ) }}
uses: actions/cache/save@v4
with:
path: ${{ steps.validator-state.outputs.installer_path }}
key: ${{ steps.validator-state.outputs.download_url }}
- name: Install IncQuery Validator for Enterprise Architect
shell: pwsh
if: ${{ steps.validator-state.outputs.need_to_install == 'true' }}
run: |
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if($isAdmin -ne $true)
{
$msg = "IncQuery Validator for Enterprise Architect is not installed on the runner, and since the current user is not an administrator the action can't install it."
echo $msg
echo $msg | Out-File -FilePath $env:GITHUB_STEP_SUMMARY
exit 1
}
$installResult = Start-Process -FilePath '${{ steps.validator-state.outputs.installer_path }}' -ArgumentList @("/install", "/quiet") -Wait -PassThru
exit $installResult.ExitCode
- name: Create the license file
shell: pwsh
run: |
echo '${{ inputs.license }}' | Out-File -FilePath '${{ runner.temp }}/IncQueryValidatorLicense.lic'
- name: Run validation
shell: pwsh
run: |
& 'C:\Program Files\IncQuery Labs\IncQuery Validator for Enterprise Architect\CI\run_validation.ps1' -model '${{ inputs.model_file_path }}' -licenseFile '${{ runner.temp }}/IncQueryValidatorLicense.lic' -outputPath '${{ runner.temp }}/validation_result' -analysisSuite '${{ inputs.analysis_suite }}' -mdgtPaths '${{ inputs.mdgtPaths }}'
- name: "Archive analysis result"
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.analysis_suite }} analysis result"
path: ${{ runner.temp }}/validation_result/
- name: "Process result summary, create PR comment content"
shell: pwsh
id: process_summary
run: |
# import results
$result = Import-Csv -Path "${{ runner.temp }}/validation_result/kpi_summary.csv" -Header level,number
$summary_csv = Import-Csv -Path "${{ runner.temp }}/validation_result/summary.csv"
$numRules = $summary_csv.Count
$msg = "# ![validator_icon](https://user-images.githubusercontent.com/39518109/262674793-7db6c023-9bae-4e68-ad43-ca92ba84d0e6.svg) IncQuery Validator for Enterprise Architect `r`n"
$msg += "Analysis were executed on **${{ inputs.model_file_path }}** with the **${{ inputs.analysis_suite }}** ruleset containing $numRules rules.`r`n`r`n"
$fatals = $result | where { $_.level.StartsWith("fatal error") }
$errors = $result | where { $_.level.StartsWith("errors") }
$warnings = $result | where { $_.level.StartsWith("warnings") }
$infos = $result | where { $_.level.StartsWith("info") }
$debugs = $result | where { $_.level.StartsWith("debug") }
$fatals = if ($fatals) { [int]$fatals.number } else { [int]0 }
$errors = if ($errors) { [int]$errors.number } else { [int]0 }
$warnings = if ($warnings) { [int]$warnings.number } else { [int]0 }
$infos = if ($infos) { [int]$infos.number } else { [int]0 }
$debugs = if ($debugs) { [int]$debugs.number } else { [int]0 }
$sumMinFatals = $fatals
$sumMinErrors = $sumMinFatals + $errors
$sumMinWarnings = $sumMinErrors + $warnings
$sumMinInfos = $sumMinWarnings + $infos
$sumMinDebugs = $sumMinInfos + $debugs
if ( $sumMinDebugs -gt 0 )
{
$msg += "The following type of issues were detected:`r`n"
$msg += "| | Level | Findings |`r`n"
$msg += "| --- | ------------- | ------------- |`r`n"
if ( $fatals -ne 0 ) { $msg += "| :no_entry: | Fatal | $fatals |`r`n" }
if ( $errors -ne 0 ) { $msg += "| :no_entry_sign: | Error | $errors |`r`n" }
if ( $warnings -ne 0 ) { $msg += "| :warning: | Warning | $warnings |`r`n" }
if ( $infos -ne 0 ) { $msg += "| :information_source: | Info | $infos |`r`n" }
if ( $debugs -ne 0 ) { $msg += "| :grey_question: | Debug | $debugs |`r`n" }
$msg += "`r`n"
$numRulesWithFindings = ($summary_csv.Where{$_.Findings -gt 0}).Count
$numRulesWithoutFindings = $numRules - $numRulesWithFindings
if ( $numRules -eq $numRulesWithFindings )
{
$msg += "All ($numRules) rules have findings in the model.`r`n"
}
else
{
$msg += "Out of the $numRules rules, $numRulesWithFindings have findings.`r`n"
}
}
else
{
$msg += "No issues found. :+1:`r`n"
}
$needToFail = "false"
$checkMsg = ":heavy_check_mark: The model passed the validation criteria."
if ( ("${{ inputs.fail_on }}" -eq "fatal") -and ($sumMinFatals -gt 0) )
{
echo "Failing build, because there are fatal errors in the model."
$needToFail = "true"
$checkMsg = ":x: The model failed the validation criteria, there should be no fatal errors."
}
if ( ("${{ inputs.fail_on }}" -eq "error") -and ($sumMinErrors -gt 0) )
{
echo "Failing build, because there are errors or fatal errors in the model."
$needToFail = "true"
$checkMsg = ":x: The model failed the validation criteria, there should be no errors or fatal errors."
}
if ( ("${{ inputs.fail_on }}" -eq "warning") -and ($sumMinWarnings -gt 0) )
{
echo "Failing build, because there are warnings or above in the model."
$needToFail = "true"
$checkMsg = ":x: The model failed the validation criteria, there should be no warnings, errors or fatal errors."
}
if ( ("${{ inputs.fail_on }}" -eq "info") -and ($sumMinInfos -gt 0) )
{
echo "Failing build, because there are infos or above in the model."
$needToFail = "true"
$checkMsg = ":x: The model failed the validation criteria, there should be no infos, warnings, errors or fatal errors."
}
if ( ("${{ inputs.fail_on }}" -eq "debug") -and ($sumMinDebugs -gt 0) )
{
echo "Failing build, because there are debug findings or above in the model."
$needToFail = "true"
$checkMsg = ":x: The model failed the validation criteria, there should be no issues detected."
}
echo "need_to_fail=$needToFail" >> $env:GITHUB_OUTPUT
$msg += "`r`n" + $checkMsg + "`r`n"
$msg += "`r`nTo view the full report download the *${{ inputs.analysis_suite }} analysis result* artifacts from [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts)."
$msg | Out-File -FilePath '${{ runner.temp }}/pr_comment.txt'
echo $msg
# create the run summary message
$summary_message = "`r`n`r`n## Per rule breakdown`r`n`r`n"
if ( "${{ inputs.fail_on }}" -ne "none" )
{
$summary_message += ">The pass/fail display (:green_circle:/:red_circle:) depends on the configured quality gate (currently its set to fail on ${{ inputs.fail_on }} or more severe).`r`n"
$summary_message += ">`r`n"
}
$summary_message += ">Only the rules with findings are shown.`r`n`r`n"
if ( "${{ inputs.fail_on }}" -eq "none" )
{
$summary_message += "| Severity | Findings | Rule name | Description |`r`n"
$summary_message += "| -------- | ----------- | --------- | ----------- |`r`n"
}
else
{
$summary_message += "| | Severity | Findings | Rule name | Description |`r`n"
$summary_message += "| --- | -------- | ----------- | --------- | ----------- |`r`n"
}
foreach ($rule in $summary_csv)
{
$severity = $rule.Severity
$numFindings = $rule.Findings
$description = $rule.Description
$ruleName = $rule.'Rule name'
if ( $numFindings -gt 0 )
{
switch ($severity) {
"FATAL" { $severityNumeric = 5 }
"ERROR" { $severityNumeric = 4 }
"WARNING" { $severityNumeric = 3 }
"INFO" { $severityNumeric = 2 }
"DEBUG" { $severityNumeric = 1 }
Default { $severityNumeric = 0 }
}
$marker = ":green_circle:"
if ( ( ("${{ inputs.fail_on }}" -eq "fatal" ) -and ($severityNumeric -ge 5 ) ) -or
( ("${{ inputs.fail_on }}" -eq "error" ) -and ($severityNumeric -ge 4 ) ) -or
( ("${{ inputs.fail_on }}" -eq "warning") -and ($severityNumeric -ge 3 ) ) -or
( ("${{ inputs.fail_on }}" -eq "info" ) -and ($severityNumeric -ge 2 ) ) -or
( ("${{ inputs.fail_on }}" -eq "debug" ) -and ($severityNumeric -ge 1 ) ) )
{
$marker = ":red_circle:"
}
$summary_message += "| "
if ( "${{ inputs.fail_on }}" -ne "none" )
{
$summary_message += " $marker |"
}
$summary_message += " $severity | $numFindings | $ruleName | $description |`r`n"
}
}
$summary_message += "`r`n"
# write out the summary message
echo $msg | Out-File -FilePath $env:GITHUB_STEP_SUMMARY
# only write per rule breakdown if there is any findings
if ( $sumMinDebugs -gt 0 )
{
echo $summary_message | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
}
- name: Find Pull Request
if: ${{ inputs.comment_on_pr == 'true' }}
uses: juliangruber/find-pull-request-action@v1
id: find-pull-request
with:
branch: ${{ github.head_ref || github.ref_name }}
- name: Comment on PR
if: ${{ (inputs.comment_on_pr == 'true') && (steps.find-pull-request.outputs.number > 0) }}
continue-on-error: true
uses: thollander/actions-comment-pull-request@v2
with:
filePath: '${{ runner.temp }}/pr_comment.txt'
pr_number: '${{ steps.find-pull-request.outputs.number }}'
- name: Check build result
if: ${{ steps.process_summary.outputs.need_to_fail == 'true' }}
shell: pwsh
run: |
echo "Failing build, because there are issues detected above the set threshold."
exit 1
branding:
icon: 'box'
color: 'blue'