Skip to content

Instantly share code, notes, and snippets.

@akyunus
Created October 6, 2022 11:48
Show Gist options
  • Select an option

  • Save akyunus/3b875df0d5b8070cb643c289ce3bfa8b to your computer and use it in GitHub Desktop.

Select an option

Save akyunus/3b875df0d5b8070cb643c289ce3bfa8b to your computer and use it in GitHub Desktop.
lintool is a bash script for flutter projects to automate checks before creating a Pull Request
#!/bin/bash
#minimum code coverage value
coverage_limit=70
exit_message () {
echo "\e[1;31m πŸ˜… Lintool failed.\n πŸͺ› Check the issues.\n 🐝 Run again.\e[0m"
exit 0
}
flutter format --set-exit-if-changed lib test || exit_message
flutter analyze lib test || exit_message
flutter test -j 4 --no-pub --coverage --test-randomize-ordering-seed random || exit_message
coverage_output=$(genhtml coverage/lcov.info -o coverage/)
regex="([0-9]+)\.[0-9]*%"
if [[ $coverage_output =~ $regex ]]
then
coverage_value="${BASH_REMATCH[1]}"
echo "Code Coverage is $coverage_value%"
if [ $coverage_value -lt $coverage_limit ]
then
echo "Code Coverage must be at least $coverage_limit%"
exit_message
fi
else
echo "πŸ˜… Can't detect Code Coverage Value. Check it yourself."
fi
echo "\e[1;32m Ready to push!\e[0m πŸš€"
@akyunus
Copy link
Author

akyunus commented Oct 6, 2022

Run the script at project root folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment