From f6b80c1ef4cefa89cae4787e1aadb6aa370e70f3 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 28 Jun 2019 15:33:41 -0400 Subject: [PATCH] Add pre commit hook script to check credo, format, and deps versions co-authored-by: Scott Millard --- README.md | 2 +- config/dev.exs | 2 +- mix.exs | 2 +- mix.lock | 2 +- scripts/git_pre_commit_hook.sh | 38 ++++++++++++++++++++++++++++++++++ scripts/set_release_number.sh | 13 ------------ 6 files changed, 42 insertions(+), 17 deletions(-) create mode 100755 scripts/git_pre_commit_hook.sh delete mode 100755 scripts/set_release_number.sh diff --git a/README.md b/README.md index 1186d7a..f605d3c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The package can be installed by adding `divo` to your list of dependencies in `m ```elixir def deps() do [ - {:divo, "~> 1.1.5", only: [:dev, :integration]} + {:divo, "~> 1.1.9", only: [:dev, :integration]} ] end ``` diff --git a/config/dev.exs b/config/dev.exs index eb21d14..82ce7b9 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -23,4 +23,4 @@ config :divo, } config :husky, - pre_commit: "mix format --check-formatted && mix credo && mix hex.outdated" + pre_commit: "./scripts/git_pre_commit_hook.sh" diff --git a/mix.exs b/mix.exs index 597b76d..e21e083 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Divo.MixProject do def project do [ app: :divo, - version: "1.1.7", + version: "1.1.9", elixir: "~> 1.8", start_permanent: Mix.env() == :prod, deps: deps(), diff --git a/mix.lock b/mix.lock index fafb793..db160b9 100644 --- a/mix.lock +++ b/mix.lock @@ -10,6 +10,6 @@ "meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, "patiently": {:hex, :patiently, "0.2.0", "67eb139591e10c4b363ae0198e832552f191c58894731efd3bf124ec4722267a", [:mix], [], "hexpm"}, - "placebo": {:hex, :placebo, "1.2.1", "303ebb597279fd77b1f6d38ec377be4932f73246351f181d6128d0a58d3f74e9", [:mix], [{:meck, "~> 0.8.9", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, + "placebo": {:hex, :placebo, "1.2.2", "a3d47906b01844bfd04ab0351a605620619fdb8f011225e406696f96a88ff380", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, "temporary_env": {:hex, :temporary_env, "2.0.1", "d4b5e031837e5619485e1f23af7cba7e897b8fd546eaaa8b10c812d642ec4546", [:mix], [], "hexpm"}, } diff --git a/scripts/git_pre_commit_hook.sh b/scripts/git_pre_commit_hook.sh new file mode 100755 index 0000000..9843e47 --- /dev/null +++ b/scripts/git_pre_commit_hook.sh @@ -0,0 +1,38 @@ +#! /bin/bash +RED='\033[0;31m' +NC='\033[0m' # No Color +exit_code=0 + +#Check that version in README.md matches what is in mix.exs +build_output=$(mix hex.build) +current_version=$(echo "$build_output" | grep 'Version:' | awk '{print $2}') +app_name=$(echo "$build_output" | grep 'Building' | awk '{print $2}') +grep -q "{:$app_name, \"~> $current_version" README.md +if [ $? == 1 ]; then + echo -e "${RED}Update the version number in README.md to $current_version\r\n" + exit_code=1 +fi + +mix format + +echo -e "${NC}mix credo - compiling code there may be a delay" +compile_output=$(mix compile 2>/dev/null) ##Supress compile output and warnings + +credo_output=$(mix credo --format=oneline) +if [ $? != 0 ]; then + echo -e "${RED}$credo_output${NC}\r\n" + exit_code=1 +fi + +outdated_output=$(mix hex.outdated) +if [ $? == 1 ]; then + echo -e "${NC}Outdated dependencies" + echo -e "$outdated_output" | grep "Dependency" + echo -en "${RED}" + echo -e "$outdated_output" | grep " No" + echo -e "$outdated_output" | grep " Yes" + echo -e "${NC}" + exit_code=1 +fi + +exit $exit_code \ No newline at end of file diff --git a/scripts/set_release_number.sh b/scripts/set_release_number.sh deleted file mode 100755 index 8404ff4..0000000 --- a/scripts/set_release_number.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/bash -current_version=$(mix hex.build | grep 'Version:' | awk '{print $2}') -echo "Current Application Version is: " $current_version -read -p "Enter new version number: " new_version -files=( - mix.exs - README.md -) -for file in "${files[@]}"; do - sed -i '' "s/$current_version/$new_version/g" "$file" -done - -echo "You will need commit the changed files"