Flutterコードをpushする前に静的解析チェックをする

by dicekest,

Flutterアプリのリポジトリにflutter analyze, flutter formatをチェックするCIを設定したのでコードpushする前にチェックしておきたい。

.git/hooks/pre-push にこんな感じのスクリプトを置いてpush前にチェックすることにした。

#!/bin/sh

prePush() {
  runFlutterAnalyze
  runFlutterDartFormat
}
runFlutterAnalyze() {
  flutter analyze
  status=$?
  if [[ $status = 0 ]]; then
   echo '[info] Pass flutter analyze'
  else
   echo '[error] Not pass flutter analyze, are you sure to push? [y/N]'
   exec < /dev/tty
   read answer

   case $answer in
    'y' | 'yes') echo '[info] continue to push';;
    * ) echo '[error] stop pushing';exit 1;;
   esac
  fi
}

runFlutterDartFormat() {
  flutter format --set-exit-if-changed --dry-run .
  status=$?
  if [[ $status = 0 ]]; then
   echo '[info] Pass flutter format'
  else
   echo '[error] Not pass flutter format, are you sure to push? [y/N]'
   exec < /dev/tty
   read answer

   case $answer in
    'y' | 'yes') echo '[info] continue to push';;
    * ) echo '[error] stop pushing';exit 1;;
   esac
  fi
}

prePush
exit 0