Skip to content

Commit

Permalink
Merge pull request #28 from smartcitiesdata/pre_commit
Browse files Browse the repository at this point in the history
Add pre commit hook script to check credo, format, and deps versions
  • Loading branch information
dickthedev authored Jul 1, 2019
2 parents fe9a12d + f3fb768 commit 2b7041d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install:
script:
- mix format --check-formatted
- mix credo
- mix hex.outdated
- mix hex.outdated || true
- mix test
deploy:
skip_cleanup: true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To add to your mix dependencies, add the following block to your mix.exs deps:
```elixir
def deps do
[
{:streaming_metrics, "~> 2.1.7"}
{:streaming_metrics, "~> 2.1.9"}
]
end
```
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config

config :husky,
pre_commit: "mix format --check-formatted && mix credo && mix hex.outdated"
pre_commit: "./scripts/git_pre_commit_hook.sh"
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule StreamingMetrics.MixProject do
def project do
[
app: :streaming_metrics,
version: "2.1.8",
version: "2.1.9",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
38 changes: 38 additions & 0 deletions scripts/git_pre_commit_hook.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions scripts/set_release_number.sh

This file was deleted.

0 comments on commit 2b7041d

Please sign in to comment.