Skip to content

Commit 45ff7cb

Browse files
authored
clean up or ignore shellcheck errors (RHIDP-9067) (#89)
* add optional --track-dynamic-manifest-and-lock-file flag if INPUTS_INCLUDE_LOCK_FILE is 1; also clean up or ignore shellcheck errors (RHIDP-9067) Assisted-by: cursor Signed-off-by: Nick Boldt <nboldt@redhat.com> * now David says this won't work so instead this PR is just to clean up all the various shellcheck complaints Signed-off-by: Nick Boldt <nboldt@redhat.com> --------- Signed-off-by: Nick Boldt <nboldt@redhat.com>
1 parent 0538b45 commit 45ff7cb

1 file changed

Lines changed: 32 additions & 36 deletions

File tree

export-dynamic/export-dynamic.sh

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ errors=()
44
images=()
55
IFS=$'\n'
66

7-
workspaceOverlayFolder="$(dirname ${INPUTS_PLUGINS_FILE})"
7+
workspaceOverlayFolder="$(dirname "${INPUTS_PLUGINS_FILE}")"
88
skipWorkspace=false
99

1010
INPUTS_CLI_PACKAGE=${INPUTS_CLI_PACKAGE:="@red-hat-developer-hub/cli"}
@@ -49,30 +49,33 @@ else
4949
if [ -f "${optionalPatch}" ]
5050
then
5151
echo " applying patch on plugin sources"
52-
patch <${optionalPatch}
52+
patch <"${optionalPatch}"
5353
fi
5454

55-
for plugin in $(cat ${INPUTS_PLUGINS_FILE})
55+
while IFS= read -r plugin
5656
do
57-
if [[ "$(echo $plugin | sed 's/ *//')" == "" ]]
58-
then
57+
# Skip empty lines
58+
if [[ -z "${plugin// /}" ]]; then
5959
echo "Skip empty line"
6060
continue
6161
fi
62-
if [[ "$(echo $plugin | sed 's/^#.*//')" == "" ]]
63-
then
62+
# Skip commented lines
63+
# shellcheck disable=SC2001
64+
if [[ "$(echo "$plugin" | sed 's/^#.*//')" == "" ]]; then
6465
echo "Skip commented line"
6566
continue
6667
fi
67-
pluginPath=$(echo $plugin | sed 's/^\(^[^:]*\): *\(.*\)$/\1/')
68-
args=$(echo $plugin | sed 's/^\(^[^:]*\): *\(.*\)$/\2/')
68+
# shellcheck disable=SC2001
69+
pluginPath=$(echo "$plugin" | sed 's/^\(^[^:]*\): *\(.*\)$/\1/')
70+
# shellcheck disable=SC2001
71+
args=$(echo "$plugin" | sed 's/^\(^[^:]*\): *\(.*\)$/\2/')
6972

70-
pushd $pluginPath > /dev/null
73+
pushd "$pluginPath" > /dev/null
7174

7275
if [[ "$(grep -e '"role" *: *"frontend-plugin' package.json)" != "" ]]
7376
then
7477
pluginType=frontend
75-
optionalScalprumConfigFile="$(dirname ${INPUTS_PLUGINS_FILE})/${pluginPath}/${INPUTS_SCALPRUM_CONFIG_FILE_NAME}"
78+
optionalScalprumConfigFile="${workspaceOverlayFolder}/${pluginPath}/${INPUTS_SCALPRUM_CONFIG_FILE_NAME}"
7679
if [ -f "${optionalScalprumConfigFile}" ]
7780
then
7881
args="$args --scalprum-config ${optionalScalprumConfigFile}"
@@ -83,18 +86,16 @@ else
8386

8487
echo "========== Exporting $pluginType plugin $pluginPath =========="
8588

86-
optionalSourceOverlay="$(dirname ${INPUTS_PLUGINS_FILE})/${pluginPath}/${INPUTS_SOURCE_OVERLAY_FOLDER_NAME}"
89+
optionalSourceOverlay="${workspaceOverlayFolder}/${pluginPath}/${INPUTS_SOURCE_OVERLAY_FOLDER_NAME}"
8790
if [ -d "${optionalSourceOverlay}" ]
8891
then
8992
echo " copying source overlay"
90-
cp -Rfv ${optionalSourceOverlay}/* .
93+
cp -Rfv "${optionalSourceOverlay}"/* .
9194
fi
9295

9396
set +e
94-
echo " running the '${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION} ${EXPORT_COMMAND[@]}' command with args: $args"
95-
echo "$args" | xargs npx --yes ${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION} "${EXPORT_COMMAND[@]}"
96-
if [ $? -ne 0 ]
97-
then
97+
echo " running the '${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION} ${EXPORT_COMMAND[*]}' command with args: $args"
98+
if ! echo "$args" | xargs npx --yes "${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION}" "${EXPORT_COMMAND[@]}"; then
9899
errors+=("${pluginPath}")
99100
set -e
100101
popd > /dev/null
@@ -109,16 +110,12 @@ else
109110
PLUGIN_CONTAINER_TAG="${INPUTS_IMAGE_REPOSITORY_PREFIX}/${PLUGIN_NAME}:${PLUGIN_VERSION}"
110111

111112
echo "========== Packaging Container ${PLUGIN_CONTAINER_TAG} =========="
112-
echo " running the '${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION} ${PACKAGE_COMMAND[@]}' command"
113-
npx --yes ${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION} "${PACKAGE_COMMAND[@]}" --tag "${PLUGIN_CONTAINER_TAG}"
114-
if [ $? -eq 0 ]
115-
then
113+
echo " running the '${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION} ${PACKAGE_COMMAND[*]}' command"
114+
if npx --yes "${INPUTS_CLI_PACKAGE}@${INPUTS_CLI_VERSION}" "${PACKAGE_COMMAND[@]}" --tag "${PLUGIN_CONTAINER_TAG}"; then
116115
if [[ "${INPUTS_PUSH_CONTAINER_IMAGE}" == "true" ]]
117116
then
118117
echo "========== Publishing Container ${PLUGIN_CONTAINER_TAG} =========="
119-
podman push $PLUGIN_CONTAINER_TAG
120-
if [ $? -eq 0 ]
121-
then
118+
if podman push "$PLUGIN_CONTAINER_TAG"; then
122119
images+=("${PLUGIN_CONTAINER_TAG}")
123120
else
124121
echo " Error pushing container image"
@@ -138,12 +135,10 @@ else
138135
echo "========== Moving $pluginType plugin $pluginPath archive into ${INPUTS_DESTINATION} =========="
139136

140137
packDestination=${INPUTS_DESTINATION}
141-
mkdir -pv ${packDestination}
138+
mkdir -pv "${packDestination}"
142139

143140
echo " running npm pack on the exported './dist-dynamic' sub-folder"
144-
json=$(npm pack ./dist-dynamic --pack-destination $packDestination --json)
145-
if [ $? -ne 0 ]
146-
then
141+
if ! json=$(npm pack ./dist-dynamic --pack-destination "$packDestination" --json); then
147142
errors+=("${pluginPath}")
148143
set -e
149144
popd > /dev/null
@@ -153,8 +148,8 @@ else
153148

154149
filename=$(echo "$json" | jq -r '.[0].filename')
155150
integrity=$(echo "$json" | jq -r '.[0].integrity')
156-
echo "$integrity" > $packDestination/${filename}.integrity
157-
optionalConfigFile="$(dirname ${INPUTS_PLUGINS_FILE})/${pluginPath}/${INPUTS_APP_CONFIG_FILE_NAME}"
151+
echo "$integrity" > "$packDestination/${filename}.integrity"
152+
optionalConfigFile="${workspaceOverlayFolder}/${pluginPath}/${INPUTS_APP_CONFIG_FILE_NAME}"
158153
if [ -f "${optionalConfigFile}" ]
159154
then
160155
echo " copying default app-config"
@@ -163,24 +158,25 @@ else
163158
fi
164159
set -e
165160
popd > /dev/null
166-
done
167-
echo "Plugins with failed exports: $errors"
161+
done < "${INPUTS_PLUGINS_FILE}"
162+
echo "Plugins with failed exports: ${errors[*]}"
168163
fi
169164

170165
FAILED_EXPORTS_OUTPUT=${FAILED_EXPORTS_OUTPUT:-"failed-exports-output"}
171-
touch $FAILED_EXPORTS_OUTPUT
166+
touch "$FAILED_EXPORTS_OUTPUT"
172167
for error in "${errors[@]}"
173168
do
174-
echo "$error" >> $FAILED_EXPORTS_OUTPUT
169+
echo "$error" >> "$FAILED_EXPORTS_OUTPUT"
175170
done
176171

177172
PUBLISHED_EXPORTS_OUTPUT=${PUBLISHED_EXPORTS_OUTPUT:-"published-exports-output"}
178-
touch $PUBLISHED_EXPORTS_OUTPUT
173+
touch "$PUBLISHED_EXPORTS_OUTPUT"
179174
for image in "${images[@]}"
180175
do
181-
echo "$image" >> $PUBLISHED_EXPORTS_OUTPUT
176+
echo "$image" >> "$PUBLISHED_EXPORTS_OUTPUT"
182177
done
183178

179+
# shellcheck disable=SC2129 disable=SC2086
184180
if [[ "$GITHUB_OUTPUT" != "" ]]
185181
then
186182
echo "FAILED_EXPORTS<<EOF" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)