-
Notifications
You must be signed in to change notification settings - Fork 1
/
antq.sh
484 lines (479 loc) · 31.5 KB
/
antq.sh
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#!/bin/bash
update_package () {
if [[ $3 == "project.clj" ]]; then
clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}}' -M -m antq.core --upgrade --force --directory "$1" --focus="$2" --skip=clojure-cli
else
clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}}' -M -m antq.core --upgrade --force --directory "$1" --focus="$2" --skip=leiningen
fi
git checkout -b "dependabot/clojure${1/$GITHUB_WORKSPACE}/$4-$5-$3-$6"
git add "$3"
git commit -m "Bump $2"
git push --set-upstream origin "dependabot/clojure${1/$GITHUB_WORKSPACE}/$4-$5-$3-$6"
echo "Bump $2 $7 to $5"
if [[ $8 != "null" ]]; then
gh pr create -B "$INPUT_MAIN_BRANCH" --title "Bump $2 from $7 to $5" -b "Bumps **$2** from $7 to $5.</br>*Changelog:* $8.$9</br></br>---</br></br>Pull request generated by Github Action \"Dependabot for Clojure projects\". Auto-rebase is currently not supported, so it is recommended to rebase before merging to prevent conflicts." -l "$INPUT_LABELS" -r "$INPUT_REVIEWERS"
else
gh pr create -B "$INPUT_MAIN_BRANCH" --title "Bump $2 from $7 to $5" -b "Bumps **$2** from $7 to $5.$9</br></br>---</br></br>Pull request generated by Github Action \"Dependabot for Clojure projects\". Auto-rebase is currently not supported, so it is recommended to rebase before merging to prevent conflicts." -l "$INPUT_LABELS" -r "$INPUT_REVIEWERS"
fi
git checkout "$INPUT_MAIN_BRANCH"
}
# https://gist.github.com/jonlabelle/6691d740f404b9736116c22195a8d706
version_ge() {
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1";
}
version_gt() {
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1";
}
high_critical_check_security_fix () {
newDependencies=()
tempGhAlerts=("$@")
cd "$2" || exit
for alertGh in "${tempGhAlerts[@]:2}"
do
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "newDependencies array: ${newDependencies[*]}"
echo "Checking the first-level dep $1"
echo "$alertGh"
fi
IFS='|' read -r -a array_alertGh <<< "$alertGh"
if [[ "$INPUT_UPDATE_OMITTED" == false ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Update omitted packages: false"
fi
if [[ "${array_alertGh[4]}" == "$1" ]]; then
afterUpdateVersion=$(mvn -ntp dependency:tree -DoutputType=dot -Dincludes="${array_alertGh[0]}" | grep -e "->" | cut -d ">" -f 2 | cut -d '"' -f 2 | grep -e "${array_alertGh[0]}" | cut -d ":" -f 4)
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Checking available security updates for ${array_alertGh[0]}. Current: ${array_alertGh[3]} Latest: $afterUpdateVersion"
fi
if version_ge "$afterUpdateVersion" "${array_alertGh[3]}"; then
if [[ ! "${newDependencies[*]}" == *"${array_alertGh[0]}|$afterUpdateVersion|"* ]]; then
newDependencies+=("${array_alertGh[0]}|$afterUpdateVersion|")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]}|$afterUpdateVersion|"
fi
fi
fi
if [ -z "$afterUpdateVersion" ]; then
if [[ ! "${newDependencies[*]}" == *"${array_alertGh[0]}|removed|"* ]]; then
newDependencies+=("${array_alertGh[0]}|removed|")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]}|removed|"
fi
fi
fi
fi
else
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Update omitted packages: true"
fi
tempDependencyTree=$(mvn -ntp dependency:tree -Dincludes="${array_alertGh[0]}" -Dverbose)
tempFirstLevelDependencies=$(echo "$tempDependencyTree" | grep -e "\\\-" -e "\+\-" | grep -v -e "\s\s\\\-" -e "\s\s+\-" | cut -d "-" -f 2-100)
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Checking available security updates for ${array_alertGh[0]}. First patched version: ${array_alertGh[3]}"
echo "First-level dependencies for ${array_alertGh[0]}"
echo "$tempFirstLevelDependencies"
fi
IFS=$'\n' read -d '' -r -a firstLevelDependencies <<< "$tempFirstLevelDependencies"
if [[ "${array_alertGh[5]}" == *"$1"* ]]; then
if [[ "${firstLevelDependencies[*]}" == *"$1"* ]]; then
for ii in "${!firstLevelDependencies[@]}"; do
if [[ "${firstLevelDependencies[$ii]}" == *"$1"* ]]; then
if [[ ${ii} -eq ${#firstLevelDependencies[@]} ]]; then
firstLevDep=$(cut -d':' -f1-2 <<<"${firstLevelDependencies[$ii]}")
tempAfterUpdateVersions=$(echo "$tempDependencyTree" | sed -n "/$firstLevDep/,//p" | grep -e "\\\-" -e "\+\-" | grep -e "${array_alertGh[0]}" | awk -F "${array_alertGh[0]}:jar:" '{print $2; printf $100}' | cut -f1 -d ":")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Versions after update for ${array_alertGh[0]} in $1"
echo "$tempAfterUpdateVersions"
fi
IFS=$'\n' read -d '' -r -a AfterUpdateVersions <<< "$tempAfterUpdateVersions"
for jj in "${!AfterUpdateVersions[@]}"; do
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]} version_ge (AfterUpdateVersions > first_patched_version): ${AfterUpdateVersions[$jj]} >= ${array_alertGh[3]}"
fi
if (version_ge "${AfterUpdateVersions[$jj]}" "${array_alertGh[3]}" && [[ ! "${newDependencies[*]}" == *"${array_alertGh[0]}|${AfterUpdateVersions[$j]}|"* ]]); then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "version_ge() passed"
fi
tempPreviousDependencyTree=$(cd previous || exit; mvn -ntp dependency:tree -Dincludes="${array_alertGh[0]}" -Dverbose)
tempPreviousFirstLevelDependencies=$(echo "$tempPreviousDependencyTree" | grep -e "\\\-" -e "\+\-" | grep -v -e "\s\s\\\-" -e "\s\s+\-" | cut -d "-" -f 2-100)
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "First-level dependencies for ${array_alertGh[0]} in /previous/pom.xml."
echo "$tempPreviousFirstLevelDependencies"
fi
IFS=$'\n' read -d '' -r -a previousFirstLevelDependencies <<< "$tempPreviousFirstLevelDependencies"
for kk in "${!previousFirstLevelDependencies[@]}"; do
if [[ "$INPUT_VERBOSE" == true ]]; then
previousFirstLevDep=$(cut -d':' -f1-2 <<<"${previousFirstLevelDependencies[$kk]}")
echo "previousFirstLevelDependencies: $previousFirstLevDep"
echo "firstLevelDependencies: $firstLevDep"
fi
if [[ "$previousFirstLevDep" == "$firstLevDep" ]]; then
if [[ ${kk} -eq ${#previousFirstLevelDependencies[@]} ]]; then
tempBeforeUpdateVersions=$(echo "$tempPreviousDependencyTree" | sed -n "/$previousFirstLevDep/,//p" | grep -e "\\\-" -e "\+\-" | grep -e "${array_alertGh[0]}" | awk -F "${array_alertGh[0]}:jar:" '{print $2; printf $100}' | cut -f1 -d ":")
else
previousFirstLevDepNext=$(cut -d':' -f1-2 <<<"${previousFirstLevelDependencies[(( $kk+1 ))]}")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "firstLevelDependenciesNext: $previousFirstLevDepNext"
fi
tempBeforeUpdateVersions=$(echo "$tempPreviousDependencyTree" | sed -n "/$previousFirstLevDep/,/$previousFirstLevDepNext/p" | sed '$d' | grep -e "\\\-" -e "\+\-" | grep -e "${array_alertGh[0]}" | awk -F "${array_alertGh[0]}:jar:" '{print $2; printf $100}' | cut -f1 -d ":")
fi
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Versions for ${array_alertGh[0]} in $1 in previous/pom.xml"
echo "$tempBeforeUpdateVersions"
fi
IFS=$'\n' read -d '' -r -a BeforeUpdateVersions <<< "$tempBeforeUpdateVersions"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Length BeforeUpdateVersions: ${#BeforeUpdateVersions[@]}"
echo "Length AfterUpdateVersions: ${#AfterUpdateVersions[@]}"
fi
if [[ ${#BeforeUpdateVersions[@]} -eq ${#AfterUpdateVersions[@]} ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]} version_gt (first_patched_version > BeforeUpdateVersions): ${array_alertGh[3]} > ${BeforeUpdateVersions[$jj]}"
fi
if version_gt "${array_alertGh[3]}" "${BeforeUpdateVersions[$jj]}"; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "version_gt() passed"
fi
newDependencies+=("${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|"
fi
break 2
fi
else
newDependencies+=("${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|"
fi
break 2
fi
fi
done
fi
done
else
firstLevDep=$(cut -d':' -f1-2 <<<"${firstLevelDependencies[$ii]}")
firstLevDepNext=$(cut -d':' -f1-2 <<<"${firstLevelDependencies[(( $ii+1 ))]}")
tempAfterUpdateVersions=$(echo "$tempDependencyTree" | sed -n "/$firstLevDep/,/$firstLevDepNext/p" | sed '$d' | grep -e "\\\-" -e "\+\-" | grep -e "${array_alertGh[0]}" | awk -F "${array_alertGh[0]}:jar:" '{print $2; printf $100}' | cut -f1 -d ":")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Versions after update for ${array_alertGh[0]} in $1"
echo "$tempAfterUpdateVersions"
fi
IFS=$'\n' read -d '' -r -a AfterUpdateVersions <<< "$tempAfterUpdateVersions"
for jj in "${!AfterUpdateVersions[@]}"; do
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]} version_ge (AfterUpdateVersions > first_patched_version): ${AfterUpdateVersions[$jj]} >= ${array_alertGh[3]}"
fi
if (version_ge "${AfterUpdateVersions[$jj]}" "${array_alertGh[3]}" && [[ ! "${newDependencies[*]}" == *"${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|"* ]]); then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "version_ge() passed"
fi
tempPreviousDependencyTree=$(cd previous || exit; mvn -ntp dependency:tree -Dincludes="${array_alertGh[0]}" -Dverbose)
tempPreviousFirstLevelDependencies=$(echo "$tempPreviousDependencyTree" | grep -e "\\\-" -e "\+\-" | grep -v -e "\s\s\\\-" -e "\s\s+\-" | cut -d "-" -f 2-100)
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "First-level dependencies for ${array_alertGh[0]} in /previous/pom.xml."
echo "$tempPreviousFirstLevelDependencies"
fi
IFS=$'\n' read -d '' -r -a previousFirstLevelDependencies <<< "$tempPreviousFirstLevelDependencies"
for kk in "${!previousFirstLevelDependencies[@]}"; do
if [[ "$INPUT_VERBOSE" == true ]]; then
previousFirstLevDep=$(cut -d':' -f1-2 <<<"${previousFirstLevelDependencies[$kk]}")
echo "previousFirstLevelDependencies: $previousFirstLevDep"
echo "firstLevelDependencies: $firstLevDep"
fi
if [[ "$previousFirstLevDep" == "$firstLevDep" ]]; then
if [[ ${kk} -eq ${#previousFirstLevelDependencies[@]} ]]; then
tempBeforeUpdateVersions=$(echo "$tempPreviousDependencyTree" | sed -n "/$previousFirstLevDep/,//p" | grep -e "\\\-" -e "\+\-" | grep -e "${array_alertGh[0]}" | awk -F "${array_alertGh[0]}:jar:" '{print $2; printf $100}' | cut -f1 -d ":")
else
previousFirstLevDepNext=$(cut -d':' -f1-2 <<<"${previousFirstLevelDependencies[(( $kk+1 ))]}")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "firstLevelDependenciesNext: $previousFirstLevDepNext"
fi
tempBeforeUpdateVersions=$(echo "$tempPreviousDependencyTree" | sed -n "/$previousFirstLevDep/,/$previousFirstLevDepNext/p" | sed '$d' | grep -e "\\\-" -e "\+\-" | grep -e "${array_alertGh[0]}" | awk -F "${array_alertGh[0]}:jar:" '{print $2; printf $100}' | cut -f1 -d ":")
fi
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Versions for ${array_alertGh[0]} in $1 in previous/pom.xml"
echo "$tempBeforeUpdateVersions"
fi
IFS=$'\n' read -d '' -r -a BeforeUpdateVersions <<< "$tempBeforeUpdateVersions"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Length BeforeUpdateVersions: ${#BeforeUpdateVersions[@]}"
echo "Length AfterUpdateVersions: ${#AfterUpdateVersions[@]}"
fi
if [[ ${#BeforeUpdateVersions[@]} -eq ${#AfterUpdateVersions[@]} ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]} version_gt (first_patched_version > BeforeUpdateVersions): ${array_alertGh[3]} > ${BeforeUpdateVersions[$jj]}"
fi
if version_gt "${array_alertGh[3]}" "${BeforeUpdateVersions[$jj]}"; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "version_gt() passed"
fi
newDependencies+=("${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|"
fi
break 2
fi
else
newDependencies+=("${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]}|${AfterUpdateVersions[$jj]}|"
fi
break 2
fi
fi
done
fi
done
fi
fi
done
else
if [[ ! "${newDependencies[*]}" == *"${array_alertGh[0]}|removed|"* ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${array_alertGh[0]}|removed|"
fi
newDependencies+=("${array_alertGh[0]}|removed|")
fi
fi
fi
fi
done
}
vulnerability_fix_pr () {
tempNewDependencies=("$@")
if [ ${#tempNewDependencies[@]} -eq 0 ]; then
securityUpdatesPrBody=""
else
securityUpdatesPrBody="</br></br>**Security updates**"
for newDep in "${tempNewDependencies[@]}"
do
IFS='|' read -r -a array_newDep <<< "$newDep"
if [[ "${array_newDep[1]}" == "removed" ]]; then
securityUpdatesPrBody+="</br>Removed dependency ${array_newDep[0]}"
else
securityUpdatesPrBody+="</br>Updated dependency ${array_newDep[0]} to version ${array_newDep[1]}"
fi
done
fi
}
# $1 - "project.clj" or "deps.edn"
if [[ -n $INPUT_DIRECTORY ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Moving to $GITHUB_WORKSPACE$INPUT_DIRECTORY"
fi
cd "$GITHUB_WORKSPACE$INPUT_DIRECTORY" || exit
fi
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Finding all $1 files"
fi
mapfile -t array < <(find . -name "$1")
if [[ $1 == "project.clj" ]]; then
echo "## Outdated Dependencies" >> "$GITHUB_STEP_SUMMARY"
fi
if [[ $INPUT_INCLUDE_SUBDIRECTORIES != true ]]; then
if [[ $1 == "project.clj" ]] && [[ "${array[*]}" == *"./project.clj"* ]]; then
array=("./project.clj")
elif [[ $1 == "deps.edn" ]] && [[ "${array[*]}" == *"./deps.edn"* ]]; then
array=("./deps.edn")
else
array=()
fi
fi
for i in "${array[@]}"
do
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Working on $i"
fi
summaryOutput=0
counterDuplicate=""
i=${i/.}
cljdir=$GITHUB_WORKSPACE$INPUT_DIRECTORY${i//\/$1}
cd "$cljdir" || exit
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Creating antq-report.json"
fi
clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}}' -M -m antq.core --reporter="json" > /tmp/antq-report.json || true
length=$(jq '. | length' /tmp/antq-report.json)
length=$((length-1))
githubAlerts=()
vul_page=$(cat /tmp/dependabot_alerts.json)
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "$vul_page"
fi
if [[ $1 == "project.clj" ]]; then
pomManifestPath="$cljdir/projectclj" || exit
else
pomManifestPath="$cljdir/depsedn" || exit
fi
mkdir "/${pomManifestPath:1}/previous"
cp "/${pomManifestPath:1}/pom.xml" "/${pomManifestPath:1}/previous/pom.xml"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Copy pom.xml to folder 'previous'"
ls "/${pomManifestPath:1}/previous"
fi
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Checking GitHub Security alerts for $i"
fi
mapfile -t tempGithubAlerts < <(jq -r --arg MANIFEST "${pomManifestPath:1}/pom.xml" '.[] | select(.dependency.manifest_path == $MANIFEST and .state == "open") | .security_vulnerability.package.name + "|" + .security_vulnerability.severity + "|" + .security_advisory.ghsa_id + "|" + .security_vulnerability.first_patched_version.identifier + "|"' <<< "${vul_page}")
for vulPackage in "${tempGithubAlerts[@]}"
do
IFS='|' read -r -a array_vulnPackage <<< "$vulPackage"
if [[ $INPUT_SEVERITY == "low" ]]; then
severityLevel="low|medium|high|critical"
elif [[ $INPUT_SEVERITY == "medium" ]]; then
severityLevel="medium|high|critical"
elif [[ $INPUT_SEVERITY == "high" ]]; then
severityLevel="high|critical"
elif [[ $INPUT_SEVERITY == "critical" ]]; then
severityLevel="critical"
else
severityLevel="medium|high|critical"
fi
if [[ "$severityLevel" == *"${array_vulnPackage[1]}"* ]]; then
cd "$pomManifestPath" || exit
dep_level=$(mvn -ntp dependency:tree -DoutputType=dot -Dincludes="${array_vulnPackage[0]}" | grep -e "->" | cut -d ">" -f 2 | cut -d '"' -f 2 | cut -d ":" -f 1-2)
IFS=' ' read -r -a dependency_level <<< "$dep_level"
vulPackage+="${dependency_level[0]}|"
tempFirstLevelDependencies=$(mvn -ntp dependency:tree -Dincludes="${array_vulnPackage[0]}" -Dverbose | grep -e "\\\-" -e "\+\-" | grep -v -e "\s\s\\\-" -e "\s\s+\-" | cut -d "-" -f 2-100)
IFS=$'\n' read -d '' -r -a firstLevelDependencies <<< "$tempFirstLevelDependencies"
vulPackage+="${firstLevelDependencies[*]}|"
githubAlerts+=("$vulPackage")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "$vulPackage"
fi
fi
done
cd "$cljdir" || exit
# required for high_critical_check_security_fix() to not duplicate operations
clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}}' -M -m antq.core --upgrade --force --skip=clojure-cli --skip=leiningen --directory="$pomManifestPath"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Checking available security updates for $i"
fi
for j in $(seq 0 $length);
do
fileType=$(jq -r ".[$j] .file" /tmp/antq-report.json)
if [[ $fileType == "$1" ]]; then
name=$(jq -r ".[$j] .name" /tmp/antq-report.json)
version=$(jq -r ".[$j] .version" /tmp/antq-report.json)
latestVersion=$(jq -r ".[$j] .\"latest-version\"" /tmp/antq-report.json)
changesUrl=$(jq -r ".[$j] .\"changes-url\"" /tmp/antq-report.json)
time=$(date +%s)
escapedName=$(echo "$name" | tr "/" "-")
namePom=$(echo "$name" | tr "/" ":")
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Package: $name Current: $version Latest: $latestVersion"
fi
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Running high_critical_check_security_fix()"
fi
high_critical_check_security_fix "$namePom" "$pomManifestPath" "${githubAlerts[@]}"
cd "$cljdir" || exit
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "${newDependencies[*]}"
fi
if [ ${#newDependencies[@]} -eq 0 ]; then
securityUpdate=""
else
securityUpdate="⬆️"
fi
prefix="dependabot/clojure${cljdir/$GITHUB_WORKSPACE}/$escapedName-$latestVersion-$1-"
if [[ "$summaryOutput" -eq 0 ]]; then
{
echo "### $INPUT_DIRECTORY$i"
echo "<details>"
echo ""
echo "| Dependency | From | To | Changelog | Security |"
echo "| --- | --- | --- | --- | --- |"
} >> "$GITHUB_STEP_SUMMARY"
summaryOutput=1
fi
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Adding info to GitHub Summary"
fi
if [[ $counterDuplicate != *"| $name | $version | $latestVersion | [🔗 Changelog]($changesUrl) | $securityUpdate |"* ]]; then
if [[ $changesUrl == "null" ]]; then
echo "| $name | $version | $latestVersion | | $securityUpdate |" >> "$GITHUB_STEP_SUMMARY"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo echo "| $name | $version | $latestVersion | | $securityUpdate |"
fi
else
echo "| $name | $version | $latestVersion | [🔗 Changelog]($changesUrl) | $securityUpdate |" >> "$GITHUB_STEP_SUMMARY"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "| $name | $version | $latestVersion | [🔗 Changelog]($changesUrl) | $securityUpdate |"
fi
fi
counterDuplicate+="| $name | $version | $latestVersion | [🔗 Changelog]($changesUrl) | $securityUpdate |"
fi
if [[ $INPUT_AUTO_PULL_REQUEST == true ]] && [[ ! "$INPUT_IGNORE_DEPENDENCY" == *"$name"* ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Running vulnerability_fix_pr()"
fi
vulnerability_fix_pr "${newDependencies[@]}"
if [[ $INPUT_SECURITY_UPDATES_ONLY == true ]]; then
if [ -n "$securityUpdate" ]; then
git fetch
mapfile -t branches < <(git branch -r | grep "$prefix")
if [[ ${branches[*]} ]]; then
prTime=()
for k in "${branches[@]}"
do
prTime+=("${k//origin\/$prefix/}")
done
IFS=" " read -r -a lastBranch <<< "$(echo "${prTime[*]}" | xargs -n1 | sort -nr | xargs)"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Checking if the security update PR already exists"
fi
statusPr=$(gh pr list --head "$prefix${lastBranch[0]}" --state open --json title | jq ". | length")
if [[ $statusPr -lt 1 ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Create the security PR dependabot/clojure${cljdir/$GITHUB_WORKSPACE}/$escapedName-$latestVersion-$1-$time"
fi
update_package "$cljdir" "$name" "$1" "$escapedName" "$latestVersion" "$time" "$version" "$changesUrl" "$securityUpdatesPrBody"
else
git checkout "$INPUT_MAIN_BRANCH"
fi
else
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Create the security PR dependabot/clojure${cljdir/$GITHUB_WORKSPACE}/$escapedName-$latestVersion-$1-$time"
fi
update_package "$cljdir" "$name" "$1" "$escapedName" "$latestVersion" "$time" "$version" "$changesUrl" "$securityUpdatesPrBody"
fi
fi
else
git fetch
mapfile -t branches < <(git branch -r | grep "$prefix")
if [[ ${branches[*]} ]]; then
prTime=()
for k in "${branches[@]}"
do
prTime+=("${k//origin\/$prefix/}")
done
IFS=" " read -r -a lastBranch <<< "$(echo "${prTime[*]}" | xargs -n1 | sort -nr | xargs)"
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Checking if the security update PR already exists"
fi
statusPr=$(gh pr list --head "$prefix${lastBranch[0]}" --state open --json title | jq ". | length")
if [[ $statusPr -lt 1 ]]; then
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Create the security PR dependabot/clojure${cljdir/$GITHUB_WORKSPACE}/$escapedName-$latestVersion-$1-$time"
fi
update_package "$cljdir" "$name" "$1" "$escapedName" "$latestVersion" "$time" "$version" "$changesUrl" "$securityUpdatesPrBody"
else
git checkout "$INPUT_MAIN_BRANCH"
fi
else
if [[ "$INPUT_VERBOSE" == true ]]; then
echo "Create the security PR dependabot/clojure${cljdir/$GITHUB_WORKSPACE}/$escapedName-$latestVersion-$1-$time"
fi
update_package "$cljdir" "$name" "$1" "$escapedName" "$latestVersion" "$time" "$version" "$changesUrl" "$securityUpdatesPrBody"
fi
fi
fi
fi
done
if [[ "$summaryOutput" -eq 1 ]]; then
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
fi
done