From 3e2f63478c4fdce18816de34d5406a328387d237 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Mon, 24 Jul 2023 18:37:03 +0200 Subject: [PATCH] feat: Add the check-pr script --- flake.nix | 15 +++++++++++++++ src/flutter/check-pr.sh | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/flutter/check-pr.sh diff --git a/flake.nix b/flake.nix index 1950992..3bf223a 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,18 @@ ''; }; flutter-build-raw = pkgs.callPackage flutterBuildRaw {}; + + checkPr = {stdenv}: stdenv.mkDerivation { + pname = "check-pr"; + version = "0.1.0"; + src = ./.; + + installPhase = '' + mkdir -p $out/bin + + install --mode 555 src/flutter/check-pr.sh $out/bin/check-pr + ''; + }; in { packages = { # The raw flutter-build script @@ -31,6 +43,9 @@ --notify-send ${pkgs.libnotify}/bin/notify-send \ $@ ''; + + # A script for checking if a PR is okay + checkPr = pkgs.callPackage checkPr {}; }; }); } diff --git a/src/flutter/check-pr.sh b/src/flutter/check-pr.sh new file mode 100644 index 0000000..4713c70 --- /dev/null +++ b/src/flutter/check-pr.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Run before merging a PR. Checks if the formatting is correct. +# Check if there are any formatting issues +echo "Checking formatting..." +dart_format_result=$(dart format --output none --set-exit-if-changed .) +if [[ ! "$?" = "0" ]]; then + echo "Error: dart format indicates that format the code is not formatted properly" + echo + echo "dart format output:" + echo "$dart_format_result" + exit 1 +fi + +# Check if the linter has any issues +echo "Checking linter..." +flutter_analyze_result=$(flutter analyze) +if [[ ! "$?" = "0" ]]; then + echo "Error: flutter analyze indicates that there are lint issues" + echo + echo "flutter analyze output:" + echo "${flutter_analyze_result}" + exit 1 +fi + +echo "PR looks good!"