Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort files when capturing user_dir contents for populateValuesYAML fu… #716

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

gsmith-sas
Copy link
Member

…nction

Copy link
Contributor

sh-checker report

To get the full details, please check in the job output.

shellcheck errors

'shellcheck -e SC1004' returned error 1 finding the following syntactical issues:

----------

In bin/version-include.sh line 1:
# Copyright © 2021, SAS Institute Inc., Cary, NC, USA.  All Rights Reserved.
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.


In bin/version-include.sh line 23:
      echo '"user_dir":' >> "$v4mValuesYAML"
      ^-- SC2129 (style): Consider using { cmd1; cmd2; } >> file instead of individual redirects.


In bin/version-include.sh line 26:
      l=($(find "$USER_DIR" -type f|sort))
         ^-- SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting).


In bin/version-include.sh line 37:
      cat "$USER_DIR/user.env" | sed 's/^/      /' >> "$v4mValuesYAML"
          ^------------------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In bin/version-include.sh line 42:
      cat "$USER_DIR/monitoring/user.env" | sed 's/^/      /' >> "$v4mValuesYAML"
          ^-----------------------------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In bin/version-include.sh line 47:
      cat "$USER_DIR/logging/user.env" | sed 's/^/      /' >> "$v4mValuesYAML"
          ^--------------------------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In bin/version-include.sh line 77:
    --values $valuesYAML \
             ^---------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    --values "$valuesYAML" \


In bin/version-include.sh line 78:
    $releaseName ./v4m-chart
    ^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
    "$releaseName" ./v4m-chart


In bin/version-include.sh line 91:
  if [ ! -z $(helm list -n "$NS" --filter "^$releaseName\$" -q) ]; then
       ^-- SC2236 (style): Use -n instead of ! -z.
            ^-- SC2046 (warning): Quote this to prevent word splitting.


In bin/version-include.sh line 108:
  IFS=$'\n' v4mHelmVersionLines=($(helm list -n "$NS" --filter "^$releaseName\$" -o yaml))
                                 ^-- SC2207 (warning): Prefer mapfile or read -a to split command output (or quote to avoid splitting).


In bin/version-include.sh line 110:
  if [ -z "$v4mHelmVersionLines" ]; then
           ^------------------^ SC2128 (warning): Expanding an array without an index only gives the first element.

For more information:
  https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y...
  https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
  https://www.shellcheck.net/wiki/SC2128 -- Expanding an array without an ind...
----------

You can address the above issues in one of three ways:
1. Manually correct the issue in the offending shell script;
2. Disable specific issues by adding the comment:
  # shellcheck disable=NNNN
above the line that contains the issue, where NNNN is the error code;
3. Add '-e NNNN' to the SHELLCHECK_OPTS setting in your .yml action file.



shfmt errors

'shfmt -s' returned error 1 finding the following formatting issues:

----------
diff bin/version-include.sh.orig bin/version-include.sh
--- bin/version-include.sh.orig
+++ bin/version-include.sh
@@ -2,153 +2,152 @@
 # SPDX-License-Identifier: Apache-2.0
 
 function populateValuesYAML() {
-  v4mValuesYAML=$1
-  rm -f "$v4mValuesYAML"
-  touch "$v4mValuesYAML"
-
-  # Attempt to obtain current git commit hash
-  gitCommit=$(git rev-parse --short HEAD 2>/dev/null)
-  if [ -n "$gitCommit" ]; then
-    echo "gitCommit: $gitCommit" >> "$v4mValuesYAML"
-    gitStatus=$(git status -s | sed 's/^ M/M/' | sed 's/^/  /')
-    if [ -n "$gitStatus" ]; then
-      echo "gitStatus: |" >> "$v4mValuesYAML"
-      echo "$gitStatus" >> "$v4mValuesYAML"
-    fi
-  fi
-
-  # List contents of USER_DIR
-  if ! [[ "$USER_DIR" -ef "$(pwd)" ]]; then
-    if [ -d "$USER_DIR" ]; then
-      echo '"user_dir":' >> "$v4mValuesYAML"
-      echo "  path: $USER_DIR" >> "$v4mValuesYAML"
-      echo '  files: |' >> "$v4mValuesYAML"
-      l=($(find "$USER_DIR" -type f|sort))
-      for (( i=0; i<${#l[@]}; i++ )); do
-        fullPath=${l[i]}
-        path=${fullPath#"$USER_DIR/"}
-        echo "      $path" >> "$v4mValuesYAML"
-      done
-    fi
-    
-    # Top-level user.env contents
-    if [ -f "$USER_DIR/user.env" ]; then
-      echo '  "user.env": |' >> "$v4mValuesYAML"
-      cat "$USER_DIR/user.env" | sed 's/^/      /' >> "$v4mValuesYAML"
-    fi
-    # Monitoring user.env contents
-    if [ -f "$USER_DIR/monitoring/user.env" ]; then
-      echo '  "monitoring_user.env": |' >> "$v4mValuesYAML"
-      cat "$USER_DIR/monitoring/user.env" | sed 's/^/      /' >> "$v4mValuesYAML"
-    fi
-    # Logging user.env contents
-    if [ -f "$USER_DIR/logging/user.env" ]; then
-      echo '  "logging_user.env": |' >> "$v4mValuesYAML"
-      cat "$USER_DIR/logging/user.env" | sed 's/^/      /' >> "$v4mValuesYAML"
-    fi
-  fi
-
-  # Encrypt passwords stored in V4M Helm Chart
-  if echo "$OSTYPE" | grep 'darwin' > /dev/null 2>&1; then
-    sed -i '' "s/GRAFANA_ADMIN_PASSWORD=.*/GRAFANA_ADMIN_PASSWORD=***/g" "$v4mValuesYAML"
-    sed -i '' "s/ES_ADMIN_PASSWD=.*/ES_ADMIN_PASSWD=***/g" "$v4mValuesYAML"
-    sed -i '' "s/LOG_LOGADM_PASSWD=.*/LOG_LOGADM_PASSWD=***/g" "$v4mValuesYAML"
-  else
-    sed -i "s/GRAFANA_ADMIN_PASSWORD=.*/GRAFANA_ADMIN_PASSWORD=***/g" "$v4mValuesYAML"
-    sed -i "s/ES_ADMIN_PASSWD=.*/ES_ADMIN_PASSWD=***/g" "$v4mValuesYAML"
-    sed -i "s/LOG_LOGADM_PASSWD=.*/LOG_LOGADM_PASSWD=***/g" "$v4mValuesYAML"
-  fi
+	v4mValuesYAML=$1
+	rm -f "$v4mValuesYAML"
+	touch "$v4mValuesYAML"
+
+	# Attempt to obtain current git commit hash
+	gitCommit=$(git rev-parse --short HEAD 2>/dev/null)
+	if [ -n "$gitCommit" ]; then
+		echo "gitCommit: $gitCommit" >>"$v4mValuesYAML"
+		gitStatus=$(git status -s | sed 's/^ M/M/' | sed 's/^/  /')
+		if [ -n "$gitStatus" ]; then
+			echo "gitStatus: |" >>"$v4mValuesYAML"
+			echo "$gitStatus" >>"$v4mValuesYAML"
+		fi
+	fi
+
+	# List contents of USER_DIR
+	if ! [[ $USER_DIR -ef "$(pwd)" ]]; then
+		if [ -d "$USER_DIR" ]; then
+			echo '"user_dir":' >>"$v4mValuesYAML"
+			echo "  path: $USER_DIR" >>"$v4mValuesYAML"
+			echo '  files: |' >>"$v4mValuesYAML"
+			l=($(find "$USER_DIR" -type f | sort))
+			for ((i = 0; i < ${#l[@]}; i++)); do
+				fullPath=${l[i]}
+				path=${fullPath#"$USER_DIR/"}
+				echo "      $path" >>"$v4mValuesYAML"
+			done
+		fi
+
+		# Top-level user.env contents
+		if [ -f "$USER_DIR/user.env" ]; then
+			echo '  "user.env": |' >>"$v4mValuesYAML"
+			cat "$USER_DIR/user.env" | sed 's/^/      /' >>"$v4mValuesYAML"
+		fi
+		# Monitoring user.env contents
+		if [ -f "$USER_DIR/monitoring/user.env" ]; then
+			echo '  "monitoring_user.env": |' >>"$v4mValuesYAML"
+			cat "$USER_DIR/monitoring/user.env" | sed 's/^/      /' >>"$v4mValuesYAML"
+		fi
+		# Logging user.env contents
+		if [ -f "$USER_DIR/logging/user.env" ]; then
+			echo '  "logging_user.env": |' >>"$v4mValuesYAML"
+			cat "$USER_DIR/logging/user.env" | sed 's/^/      /' >>"$v4mValuesYAML"
+		fi
+	fi
+
+	# Encrypt passwords stored in V4M Helm Chart
+	if echo "$OSTYPE" | grep 'darwin' >/dev/null 2>&1; then
+		sed -i '' "s/GRAFANA_ADMIN_PASSWORD=.*/GRAFANA_ADMIN_PASSWORD=***/g" "$v4mValuesYAML"
+		sed -i '' "s/ES_ADMIN_PASSWD=.*/ES_ADMIN_PASSWD=***/g" "$v4mValuesYAML"
+		sed -i '' "s/LOG_LOGADM_PASSWD=.*/LOG_LOGADM_PASSWD=***/g" "$v4mValuesYAML"
+	else
+		sed -i "s/GRAFANA_ADMIN_PASSWORD=.*/GRAFANA_ADMIN_PASSWORD=***/g" "$v4mValuesYAML"
+		sed -i "s/ES_ADMIN_PASSWD=.*/ES_ADMIN_PASSWD=***/g" "$v4mValuesYAML"
+		sed -i "s/LOG_LOGADM_PASSWD=.*/LOG_LOGADM_PASSWD=***/g" "$v4mValuesYAML"
+	fi
 }
 
 function deployV4MInfo() {
-  NS=$1
-  releaseName=${2:-'v4m'}
-  if [ -z "$NS" ]; then
-    log_error "No namespace specified for deploying SAS Viya Monitoring for Kubernetes version information"
-    return 1
-  fi
-
-  valuesYAML=$TMP_DIR/v4mValues.yaml
-  populateValuesYAML "$valuesYAML"
-
-  log_info "Updating SAS Viya Monitoring for Kubernetes version information"
-  helm upgrade --install \
-    -n "$NS" \
-    --values $valuesYAML \
-    $releaseName ./v4m-chart
-
-  getHelmReleaseVersion "$NS" "$releaseName"
+	NS=$1
+	releaseName=${2:-'v4m'}
+	if [ -z "$NS" ]; then
+		log_error "No namespace specified for deploying SAS Viya Monitoring for Kubernetes version information"
+		return 1
+	fi
+
+	valuesYAML=$TMP_DIR/v4mValues.yaml
+	populateValuesYAML "$valuesYAML"
+
+	log_info "Updating SAS Viya Monitoring for Kubernetes version information"
+	helm upgrade --install \
+		-n "$NS" \
+		--values $valuesYAML \
+		$releaseName ./v4m-chart
+
+	getHelmReleaseVersion "$NS" "$releaseName"
 }
 
 function removeV4MInfo() {
-  NS=$1
-  releaseName=${2:-'v4m'}
-  if [ -z "$NS" ]; then
-    log_error "No namespace specified for removing SAS Viya Monitoring for Kubernetes version information"
-    return 1
-  fi
- 
-  if [ ! -z $(helm list -n "$NS" --filter "^$releaseName\$" -q) ]; then
-    log_info "Removing SAS Viya Monitoring for Kubernetes version information"
-    helm uninstall -n "$NS" "$releaseName"
-  fi
+	NS=$1
+	releaseName=${2:-'v4m'}
+	if [ -z "$NS" ]; then
+		log_error "No namespace specified for removing SAS Viya Monitoring for Kubernetes version information"
+		return 1
+	fi
+
+	if [ ! -z $(helm list -n "$NS" --filter "^$releaseName\$" -q) ]; then
+		log_info "Removing SAS Viya Monitoring for Kubernetes version information"
+		helm uninstall -n "$NS" "$releaseName"
+	fi
 }
 
 function getHelmReleaseVersion() {
-  NS=$1
-  releaseName=${2:-'v4m'}
-
-  releaseVersionFull=""
-  releaseVersionMajor=""
-  releaseVersionMinor=""
-  releaseVersionPatch=""
-  releaseStatus=""
-
-  origIFS=$IFS
-  IFS=$'\n' v4mHelmVersionLines=($(helm list -n "$NS" --filter "^$releaseName\$" -o yaml))
-  IFS=$origIFS
-  if [ -z "$v4mHelmVersionLines" ]; then
-    log_debug "No [$releaseName] release found in [$NS]"
-  else
-    for (( i=0; i<${#v4mHelmVersionLines[@]}; i++ )); do 
-      line=${v4mHelmVersionLines[$i]}
-      vre='app_version: (([0-9]+).([[0-9]+).([0-9]+)\.?(-.+)?)'
-      sre='status: (.+)'
-      if [[ $line =~ $vre ]]; then
-        # Set
-        releaseVersionFull=${BASH_REMATCH[1]}
-        releaseVersionMajor=${BASH_REMATCH[2]}
-        releaseVersionMinor=${BASH_REMATCH[3]}        
-        releaseVersionPatch=${BASH_REMATCH[4]}
-      elif [[ "$line" =~ $sre ]]; then
-        releaseStatus=${BASH_REMATCH[1]}
-      fi
-    done
-
-  fi
-  
-  export releaseVersionFull releaseVersionMajor releaseVersionMinor releaseVersionPatch releaseStatus
+	NS=$1
+	releaseName=${2:-'v4m'}
+
+	releaseVersionFull=""
+	releaseVersionMajor=""
+	releaseVersionMinor=""
+	releaseVersionPatch=""
+	releaseStatus=""
+
+	origIFS=$IFS
+	IFS=$'\n' v4mHelmVersionLines=($(helm list -n "$NS" --filter "^$releaseName\$" -o yaml))
+	IFS=$origIFS
+	if [ -z "$v4mHelmVersionLines" ]; then
+		log_debug "No [$releaseName] release found in [$NS]"
+	else
+		for ((i = 0; i < ${#v4mHelmVersionLines[@]}; i++)); do
+			line=${v4mHelmVersionLines[$i]}
+			vre='app_version: (([0-9]+).([[0-9]+).([0-9]+)\.?(-.+)?)'
+			sre='status: (.+)'
+			if [[ $line =~ $vre ]]; then
+				# Set
+				releaseVersionFull=${BASH_REMATCH[1]}
+				releaseVersionMajor=${BASH_REMATCH[2]}
+				releaseVersionMinor=${BASH_REMATCH[3]}
+				releaseVersionPatch=${BASH_REMATCH[4]}
+			elif [[ $line =~ $sre ]]; then
+				releaseStatus=${BASH_REMATCH[1]}
+			fi
+		done
+
+	fi
+
+	export releaseVersionFull releaseVersionMajor releaseVersionMinor releaseVersionPatch releaseStatus
 }
 
 if [ -z "$V4M_VERSION_INCLUDE" ]; then
-  getHelmReleaseVersion "$V4M_NS"
-  
-  V4M_CURRENT_VERSION_FULL=$releaseVersionFull
-  V4M_CURRENT_VERSION_MAJOR=$releaseVersionMajor
-  V4M_CURRENT_VERSION_MINOR=$releaseVersionMinor
-  V4M_CURRENT_VERSION_PATCH=$releaseVersionPatch
-  V4M_CURRENT_STATUS=$releaseStatus
-  
-  log_debug "V4M_CURRENT_VERSION_FULL=$V4M_CURRENT_VERSION_FULL"
-  log_debug "V4M_CURRENT_VERSION_MAJOR=$V4M_CURRENT_VERSION_MAJOR"
-  log_debug "V4M_CURRENT_VERSION_MINOR=$V4M_CURRENT_VERSION_MINOR"
-  log_debug "V4M_CURRENT_VERSION_PATCH=$V4M_CURRENT_VERSION_PATCH"
-  log_debug "V4M_CURRENT_STATUS=$V4M_CURRENT_STATUS"
-
-  export V4M_CURRENT_VERSION_FULL V4M_CURRENT_VERSION_MAJOR V4M_CURRENT_VERSION_MINOR V4M_CURRENT_VERSION_PATCH 
-  export V4M_CURRENT_STATUS
-
-  export -f deployV4MInfo removeV4MInfo getHelmReleaseVersion
-  export V4M_VERSION_INCLUDE=true
+	getHelmReleaseVersion "$V4M_NS"
+
+	V4M_CURRENT_VERSION_FULL=$releaseVersionFull
+	V4M_CURRENT_VERSION_MAJOR=$releaseVersionMajor
+	V4M_CURRENT_VERSION_MINOR=$releaseVersionMinor
+	V4M_CURRENT_VERSION_PATCH=$releaseVersionPatch
+	V4M_CURRENT_STATUS=$releaseStatus
+
+	log_debug "V4M_CURRENT_VERSION_FULL=$V4M_CURRENT_VERSION_FULL"
+	log_debug "V4M_CURRENT_VERSION_MAJOR=$V4M_CURRENT_VERSION_MAJOR"
+	log_debug "V4M_CURRENT_VERSION_MINOR=$V4M_CURRENT_VERSION_MINOR"
+	log_debug "V4M_CURRENT_VERSION_PATCH=$V4M_CURRENT_VERSION_PATCH"
+	log_debug "V4M_CURRENT_STATUS=$V4M_CURRENT_STATUS"
+
+	export V4M_CURRENT_VERSION_FULL V4M_CURRENT_VERSION_MAJOR V4M_CURRENT_VERSION_MINOR V4M_CURRENT_VERSION_PATCH
+	export V4M_CURRENT_STATUS
+
+	export -f deployV4MInfo removeV4MInfo getHelmReleaseVersion
+	export V4M_VERSION_INCLUDE=true
 fi
-
----------

You can reformat the above files to meet shfmt's requirements by typing:

  shfmt -s -w filename


@gsmith-sas gsmith-sas requested a review from ceelias February 12, 2025 19:12
@gsmith-sas gsmith-sas merged commit aba0afd into main Feb 12, 2025
1 of 2 checks passed
@gsmith-sas gsmith-sas deleted the sortfiles branch February 12, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants