Просмотр исходного кода

Update shellcheck test (#3081)

* Show only "Failed" checks

- Add total files / failures

* Fix shell check errors installers

* Fix more shell check errors

* Use  ludeeus/action-shellcheck@master instead

* Update .github/workflows/lint.yml

Co-authored-by: Alec Rust <me@alecrust.com>

* Update lint.yml to use sha1 commit

Co-authored-by: Alec Rust <me@alecrust.com>
Jaap Marcus 3 лет назад
Родитель
Сommit
4708648fe6

+ 6 - 7
.github/workflows/lint.yml

@@ -11,14 +11,13 @@ jobs:
     name: ShellCheck
     runs-on: ubuntu-latest
     steps:
-      - name: Checkout code
-        uses: actions/checkout@v3
-
-      - name: Install ShellCheck
-        run: sudo apt-get install -y shellcheck
+    - name: Checkout code
+      uses: actions/checkout@v3
 
-      - name: Run ShellCheck script
-        run: ./test/shellcheck.sh
+    - name: Run ShellCheck
+      uses: ludeeus/action-shellcheck@6d3f514f44620b9d4488e380339edc0d9bbe2fba
+      with:
+        severity: error
 
   eslint:
     name: ESLint

+ 1 - 1
bin/v-add-web-php

@@ -48,7 +48,7 @@ if [ -f "$php_fpm" ] && [ -f "$HESTIA/data/templates/web/php-fpm/PHP-${version/\
 fi
 
 # Check if php version is supported
-if  [[ ! "$multiphp_v" =~ "$version" ]]; then
+if  [[ ! "$multiphp_v" =~ $version ]]; then
     echo "ERROR: Specified PHP version is not supported or does not exist."
     exit "$E_INVALID";
 fi

+ 1 - 1
bin/v-update-letsencrypt-ssl

@@ -82,7 +82,7 @@ for user in $($HESTIA/bin/v-list-sys-users plain); do
             # Loop through all crt aliases
             for alias in ${aliases//,/ } ; do
                 # Validate if the alias still exists in web.conf
-                if [[ ",$ALIAS," =~ ",$alias," ]]; then
+                if [[ ",$ALIAS," =~ ,$alias, ]]; then
                     f_aliases+="$alias,"
                 fi
             done

+ 2 - 2
install/hst-install-debian.sh

@@ -172,8 +172,8 @@ sort_config_file(){
 # Validate hostname according to RFC1178
 validate_hostname () {
     # remove extra .
-    servername = $(echo "$servername" |sed -e "s/[.]*$//g")
-    servername = $(echo "$domain" |sed -e "s/^[.]*//")
+    servername=$(echo "$servername" |sed -e "s/[.]*$//g")
+    servername=$(echo "$domain" |sed -e "s/^[.]*//")
     if [[ $(echo "$servername" | grep -o "\." | wc -l) -gt 1 ]] && [[ ! $servername =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
         # Hostname valid
         return 1

+ 2 - 2
install/hst-install-ubuntu.sh

@@ -170,8 +170,8 @@ sort_config_file(){
 # Validate hostname according to RFC1178
 validate_hostname () {
     # remove extra .
-    servername = $(echo "$servername" |sed -e "s/[.]*$//g")
-    servername = $(echo "$domain" |sed -e "s/^[.]*//")
+    servername=$(echo "$servername" |sed -e "s/[.]*$//g")
+    servername=$(echo "$domain" |sed -e "s/^[.]*//")
     if [[ $(echo "$servername" | grep -o "\." | wc -l) -gt 1 ]] && [[ ! $servername =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
         # Hostname valid
         return 1

+ 8 - 8
test/shellcheck.sh

@@ -24,20 +24,20 @@
 err=0;
 shellcheck --version
 
+i=0
+f=0
 files=$(grep -rlE '#!/bin/(bash|sh)' ./ | grep -vE '\.(git|j2$|md$)');
 for file in $files; do
-    echo "Linting: $file"
+    i=$(($i+1));
     shellcheck -x "$file" --severity="error"
+    # Only show failed checks
     if [ $? -gt 0 ]; then
+       f=$(($f+1));
+       echo "Linting: $file"
        printf "%s: \033[0;31m Fail \033[0m\n" "$file"
        err=1
-    else
-        # split loop in 2 parts allowing debuggin in earier stage
-       printf "%s: \033[0;32m Success \033[0m\n" "$file"
     fi
 done
+echo "$i files checked and $f errors"
 
-if [ $err == 1 ];
-then
-exit "$err";
-fi
+exit $err