Skip to content

Commit f7cfac3

Browse files
committed
Refactor dynamic plugins script to consolidate filtering logic for dynamic plugins and updated temporary file handling based on comments
1 parent b23dea8 commit f7cfac3

File tree

1 file changed

+71
-51
lines changed

1 file changed

+71
-51
lines changed

modules/dynamic-plugins/rhdh-supported-plugins.sh

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ titlecase() {
6767
case $f in
6868
aap) echo -n "Ansible Automation Platform (AAP) ";;
6969
# UPPERCASE these exceptions
70-
acr) echo -n "ACR ";;
71-
cd) echo -n "CD ";;
72-
ocm) echo -n "OCM ";;
73-
rbac) echo -n "RBAC ";;
70+
acr|cd|ocm|rbac) echo -n "$(echo "$f" | tr '[:lower:]' '[:upper:]') ";;
7471
# MixedCase exceptions
7572
argocd) echo -n "Argo CD ";;
7673
github) echo -n "GitHub ";;
@@ -132,7 +129,7 @@ for y in $yamls; do
132129
Name=$(yq -r '.metadata.name' "$y")
133130
Plugin_Title=$(yq -r '.metadata.title' "$y")
134131

135-
# Use the actual packageName from spec, fallback to name
132+
# Use .spec.packageName, or if not set use .metadata.name
136133
Plugin=$(yq -r '.spec.packageName // .metadata.name' "$y")
137134

138135
# If Plugin is still not a proper npm package name, try to construct it
@@ -158,16 +155,19 @@ for y in $yamls; do
158155
Path="${Path/-dynamic-dynamic/-dynamic}"
159156
fi
160157

161-
# Filter 1: Only dynamic plugins (must contain "dynamic" in path)
162-
[[ $Path != *"dynamic"* ]] && continue
158+
# Filter 1: Only dynamic plugin artifacts under dist root (frontend or backend)
159+
# Accept both patterns:
160+
# - Frontend: ./dynamic-plugins/dist/<name>
161+
# - Backend: ./dynamic-plugins/dist/<name>-dynamic
162+
# this change was made since FE plugins were not being included in the .csv file
163+
[[ $Path == ./dynamic-plugins/dist/* ]] || continue
163164

164165
# Filter 2: Exclude oci:// paths
165166
[[ $Path == "oci://"* ]] && continue
166167

167168
# Filter 3: Exclude @redhat packages
168169
[[ $Plugin == "@redhat"* ]] && continue
169170

170-
# echo "Path = $Path"
171171
# shellcheck disable=SC2016
172172
found_in_default_config1=$(yq -r --arg Path "${Path%-dynamic}" '.plugins[] | select(.package == $Path)' /tmp/rhdh/dynamic-plugins.default.yaml)
173173
# shellcheck disable=SC2016
@@ -275,25 +275,20 @@ for y in $yamls; do
275275
# not currently used due to policy and support concern with upstream content linked from downstream doc
276276
# URL="https://www.npmjs.com/package/$Plugin"
277277

278-
# Use the title from YAML if available, otherwise derive from name
279-
if [[ "$Plugin_Title" != "null" && -n "$Plugin_Title" ]]; then
280-
PrettyName="$Plugin_Title"
281-
else
282-
# fallback to name processing
283-
Name="$(echo "${Name}" | sed -r \
284-
-e "s@(pagerduty)-.+@\1@g" \
285-
-e "s@.+(-plugin-scaffolder-backend-module|backstage-scaffolder-backend-module)-(.+)@\2@g" \
286-
-e "s@.+(-plugin-catalog-module|-plugin-catalog-backend-module)-(.+)@\2@g" \
287-
-e "s@.+(-scaffolder-backend-module|-plugin-catalog-backend-module)-(.+)@\2@g" \
288-
-e "s@.+(-scaffolder-backend-module|-scaffolder-backend|backstage-plugin)-(.+)@\2@g" \
289-
-e "s@(backstage-community-plugin-)@@g" \
290-
-e "s@(backstage-plugin)-(.+)@\2@g" \
291-
-e "s@(.+)(-backstage-plugin)@\1@g" \
292-
-e "s@-backend@@g" \
293-
)"
294-
Name="$(echo "${Name}" | sed -r -e "s/redhat-(.+)/\1-\(Red-Hat\)/")"
295-
PrettyName="$(titlecase "${Name//-/ }")"
296-
fi
278+
# get a human-readable name from yaml.name
279+
ProcessedName="$(echo "${Name}" | sed -r \
280+
-e "s@(pagerduty)-.+@\1@g" \
281+
-e "s@.+(-plugin-scaffolder-backend-module|backstage-scaffolder-backend-module)-(.+)@\2@g" \
282+
-e "s@.+(-plugin-catalog-module|-plugin-catalog-backend-module)-(.+)@\2@g" \
283+
-e "s@.+(-scaffolder-backend-module|-plugin-catalog-backend-module)-(.+)@\2@g" \
284+
-e "s@.+(-scaffolder-backend-module|-scaffolder-backend|backstage-plugin)-(.+)@\2@g" \
285+
-e "s@(backstage-community-plugin-)@@g" \
286+
-e "s@(backstage-plugin)-(.+)@\2@g" \
287+
-e "s@(.+)(-backstage-plugin)@\1@g" \
288+
-e "s@-backend@@g" \
289+
)"
290+
ProcessedName="$(echo "${ProcessedName}" | sed -r -e "s/redhat-(.+)/\1-\(Red-Hat\)/")"
291+
PrettyName="$(titlecase "${ProcessedName//-/ }")"
297292

298293
# useful console output
299294
if [[ $QUIET -eq 0 ]]; then
@@ -308,18 +303,18 @@ for y in $yamls; do
308303

309304
# TODO include missing data fields for Provider and Description - see https://issues.redhat.com/browse/RHIDP-3496 and https://issues.redhat.com/browse/RHIDP-3440
310305

311-
# Use temporary files instead of associative arrays
306+
# Use temporary files to allow sorting later
312307
key="$Name-$RoleSort-$Role-$Plugin"
313308
adoc_content="|$PrettyName |\`https://npmjs.com/package/$Plugin/v/$Version[$Plugin]\` |$Version \n|\`$Path\`\n\n$Required_Variables"
314309
csv_content="\"$PrettyName\",\"$Plugin\",\"$Role\",\"$Version\",\"$Support_Level\",\"$Lifecycle\",\"$Path\",\"${Required_Variables_CSV}\",\"$Default\""
315310

316311
# split into three tables based on support level
317312
if [[ ${Support_Level} == "Production" ]]; then
318-
echo "$key|$adoc_content" >> "$TEMP_DIR/adoc1.tmp"
313+
echo "$key|$adoc_content" >> "$TEMP_DIR/adoc.production.tmp"
319314
elif [[ ${Support_Level} == "Red Hat Tech Preview" ]]; then
320-
echo "$key|$adoc_content" >> "$TEMP_DIR/adoc2.tmp"
315+
echo "$key|$adoc_content" >> "$TEMP_DIR/adoc.tech-preview.tmp"
321316
else
322-
echo "$key|$adoc_content" >> "$TEMP_DIR/adoc3.tmp"
317+
echo "$key|$adoc_content" >> "$TEMP_DIR/adoc.community.tmp"
323318
fi
324319

325320
# NOTE: csv is not split into separate tables at this point - updated to include lifecycle
@@ -340,26 +335,51 @@ fi
340335
echo -e "\"Name\",\"Plugin\",\"Role\",\"Version\",\"Support Level\",\"Lifecycle\",\"Path\",\"Required Variables\",\"Default\"" > "${0/.sh/.csv}"
341336

342337
num_plugins=()
343-
# Process temporary files instead of associative arrays
344-
for i in 1 2 3; do
345-
temp_file="$TEMP_DIR/adoc${i}.tmp"
346-
out_file="${0/.sh/.ref-rh-supported-plugins}"
347-
if [[ $i -eq 2 ]]; then out_file="${0/.sh/.ref-rh-tech-preview-plugins}"; fi
348-
if [[ $i -eq 3 ]]; then out_file="${0/.sh/.ref-community-plugins}"; fi
349-
350-
rm -f "$out_file"
351-
count=0
352-
if [[ -f "$temp_file" ]]; then
353-
# Sort and process
354-
sort "$temp_file" | while IFS='|' read -r key content; do
355-
(( count = count + 1 ))
356-
if [[ $QUIET -eq 0 ]]; then echo " * [$count] $key [ ${out_file##*/} ]"; fi
357-
echo -e "$content" >> "$out_file"
358-
done
359-
count=$(wc -l < "$temp_file")
360-
fi
361-
num_plugins+=($count)
362-
done
338+
# Process temporary files
339+
# 1) Production
340+
temp_file="$TEMP_DIR/adoc.production.tmp"
341+
out_file="${0/.sh/.ref-rh-supported-plugins}"
342+
rm -f "$out_file"
343+
count=0
344+
if [[ -f "$temp_file" ]]; then
345+
sort "$temp_file" | while IFS='|' read -r key content; do
346+
(( count = count + 1 ))
347+
if [[ $QUIET -eq 0 ]]; then echo " * [$count] $key [ ${out_file##*/} ]"; fi
348+
echo -e "$content" >> "$out_file"
349+
done
350+
count=$(wc -l < "$temp_file")
351+
fi
352+
num_plugins+=($count)
353+
354+
# 2) Tech Preview
355+
temp_file="$TEMP_DIR/adoc.tech-preview.tmp"
356+
out_file="${0/.sh/.ref-rh-tech-preview-plugins}"
357+
rm -f "$out_file"
358+
count=0
359+
if [[ -f "$temp_file" ]]; then
360+
sort "$temp_file" | while IFS='|' read -r key content; do
361+
(( count = count + 1 ))
362+
if [[ $QUIET -eq 0 ]]; then echo " * [$count] $key [ ${out_file##*/} ]"; fi
363+
echo -e "$content" >> "$out_file"
364+
done
365+
count=$(wc -l < "$temp_file")
366+
fi
367+
num_plugins+=($count)
368+
369+
# 3) Community
370+
temp_file="$TEMP_DIR/adoc.community.tmp"
371+
out_file="${0/.sh/.ref-community-plugins}"
372+
rm -f "$out_file"
373+
count=0
374+
if [[ -f "$temp_file" ]]; then
375+
sort "$temp_file" | while IFS='|' read -r key content; do
376+
(( count = count + 1 ))
377+
if [[ $QUIET -eq 0 ]]; then echo " * [$count] $key [ ${out_file##*/} ]"; fi
378+
echo -e "$content" >> "$out_file"
379+
done
380+
count=$(wc -l < "$temp_file")
381+
fi
382+
num_plugins+=($count)
363383

364384
# Process CSV
365385
if [[ -f "$TEMP_DIR/csv.tmp" ]]; then

0 commit comments

Comments
 (0)