github.com/vmware/go-vcloud-director/v2@v2.24.0/scripts/staticcheck.sh (about)

     1  #!/usr/bin/env bash
     2  scripts_dir=$(dirname $0)
     3  cd $scripts_dir
     4  scripts_dir=$PWD
     5  cd - > /dev/null
     6  
     7  sc_exit_code=0
     8  
     9  if [ ! -d ./govcd ]
    10  then
    11      echo "source directory ./govcd not found"
    12      exit 1
    13  fi
    14  
    15  function exists_in_path {
    16      what=$1
    17      for dir in $(echo $PATH | tr ':' ' ')
    18      do
    19          wanted=$dir/$what
    20          if [ -x $wanted ]
    21          then
    22              echo $wanted
    23              return
    24          fi
    25      done
    26  }
    27  
    28  function get_check_static {
    29      static_check=$(exists_in_path staticcheck)
    30      if [  -z "$staticcheck" -a -n "$GITHUB_ACTIONS" ]
    31      then
    32          # Variables found in staticcheck-config.sh
    33          # STATICCHECK_URL
    34          # STATICCHECK_VERSION
    35          # STATICCHECK_FILE
    36          if [ -f $scripts_dir/staticcheck-config.sh ]
    37          then
    38              source $scripts_dir/staticcheck-config.sh
    39          else
    40              echo "File $scripts_dir/staticcheck-config.sh not found - Skipping check"
    41              exit 0
    42          fi
    43          download_name=$STATICCHECK_URL/$STATICCHECK_VERSION/$STATICCHECK_FILE
    44          wget=$(exists_in_path wget)
    45          if [ -z "$wget" ]
    46          then
    47              echo "'wget' executable not found - Skipping check"
    48              exit 0
    49          fi
    50          $wget $download_name
    51          if [ -n "$STATICCHECK_FILE" ]
    52          then
    53              tar -xzf $STATICCHECK_FILE
    54              executable=$PWD/staticcheck/staticcheck
    55              if [ ! -f $executable ]
    56              then
    57                  echo "Extracted executable not available - Skipping check"
    58              fi
    59              chmod +x $executable
    60              static_check=$executable
    61          fi
    62      fi
    63      if [ -n "$static_check" ]
    64      then
    65          echo "## Found $static_check"
    66          echo -n "## "
    67          $static_check -version
    68      else
    69          echo "*** staticcheck executable not found - Check skipped"
    70          exit 0
    71      fi
    72  }
    73  
    74  function check_static {
    75      dir=$1
    76      if [ -n "$static_check" ]
    77      then
    78          cd $dir
    79          echo "## Checking $dir"
    80          $static_check -tags ALL .
    81          exit_code=$?
    82          if [ "$exit_code" != "0" ]
    83          then
    84              sc_exit_code=$exit_code
    85          fi
    86          cd - > /dev/null
    87      fi
    88      echo ""
    89  }
    90  
    91  get_check_static
    92  echo ""
    93  
    94  check_static govcd
    95  check_static types/v56
    96  check_static util
    97  echo "Exit code: $sc_exit_code"
    98  exit $sc_exit_code
    99