diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b447d07 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Test on a few operating systems +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test-on-ubuntu: + name: Test on Ubuntu + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: test/run.sh + + test-on-mac: + name: Test on MacOS + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - run: brew install erlang make + - run: PATH="$(brew --prefix)/opt/make/libexec/gnubin:$PATH" test/run.sh diff --git a/.gitignore b/.gitignore index 8e46d5a..d9cc189 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ ebin rel/example_project .concrete/DEV_MODE .rebar +test/test.d diff --git a/CHANGELOG.md b/CHANGELOG.md index ffddd53..0da4f8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ # Change Log + +## [1.1.2](https://github.com/inaka/elvis.mk/tree/1.1.2) (2022-10-13) +**Implemented enhancements:** + +- fix: some compatibily issues with non-GNU environments [\#17](https://github.com/inaka/elvis.mk/issues/17) +- perf: don't run `command -v rebar3` on each Elvis invocation + +## [1.1.1](https://github.com/inaka/elvis.mk/tree/1.1.1) (2022-08-23) +**Implemented enhancements:** + +- download Rebar3 (if not found locally) and use it to build Elvis [\#16](https://github.com/inaka/elvis.mk/issues/16) + ## [1.1.0](https://github.com/inaka/elvis.mk/tree/1.1.0) (2022-08-05) **Implemented enhancements:** diff --git a/README.md b/README.md index c01bbed..479ff75 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ following in your Makefile: ```make BUILD_DEPS = elvis_mk -dep_elvis_mk = git https://github.com/inaka/elvis.mk.git 1.1.1 +dep_elvis_mk = git https://github.com/inaka/elvis.mk.git 1.1.2 DEP_PLUGINS = elvis_mk ``` diff --git a/plugins.mk b/plugins.mk index a27655d..2f327c5 100644 --- a/plugins.mk +++ b/plugins.mk @@ -27,24 +27,21 @@ help:: distclean:: distclean-elvis +MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + # Plugin-specific targets. $(ELVIS): $(verbose) mkdir -p $(ELVIS_BUILD_DIR) -ifeq ($(shell command -v $(ELVIS_REBAR3)),) - $(verbose) echo "Downloading Rebar3 from: "$(ELVIS_REBAR3_URL) - $(verbose) $(call core_http_get,$(ELVIS_BUILD_DIR)/rebar3,$(ELVIS_REBAR3_URL)) - $(verbose) chmod +x $(ELVIS_BUILD_DIR)/rebar3 - $(eval ELVIS_REBAR3 := $(ELVIS_BUILD_DIR)/rebar3) -else - $(verbose) echo "Using Rebar3: "$(ELVIS_REBAR3) -endif $(verbose) echo "Downloading Elvis from: "$(ELVIS_URL) $(verbose) $(call core_http_get,$(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE),$(ELVIS_URL)) $(verbose) cd $(ELVIS_BUILD_DIR) && \ tar -xzf $(ELVIS_CODE_ARCHIVE) && \ cd elvis-$(ELVIS_VERSION) && \ - $(ELVIS_REBAR3) escriptize + export ELVIS_BUILD_DIR=$(ELVIS_BUILD_DIR) && \ + export ELVIS_REBAR3_URL=$(ELVIS_REBAR3_URL) && \ + export ELVIS_REBAR3=$(ELVIS_REBAR3) && \ + $(MAKEFILE_DIR)/rebar3.sh escriptize $(gen_verbose) cp $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/_build/default/bin/elvis $(ELVIS) $(gen_verbose) [ -e $(ELVIS_CONFIG) ] || \ cp -n $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/elvis.config $(ELVIS_CONFIG) @@ -52,7 +49,7 @@ endif $(verbose) rm -rf $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION) $(verbose) rm $(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE) $(verbose) rm -f $(ELVIS_BUILD_DIR)/rebar3 - $(if $(shell ls -A $(ELVIS_BUILD_DIR)/),,$(verbose) rmdir $(ELVIS_BUILD_DIR)) + $(verbose) find $(ELVIS_BUILD_DIR) -maxdepth 0 -empty -exec rmdir "{}" ";" elvis: $(ELVIS) $(verbose) $(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS) diff --git a/rebar3.sh b/rebar3.sh new file mode 100755 index 0000000..8d4c0b3 --- /dev/null +++ b/rebar3.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +if [ ! -x $ELVIS_REBAR3 ] && [ -z "$(command -v $ELVIS_REBAR3)" ]; then + mkdir -p "$ELVIS_BUILD_DIR" + echo "Downloading Rebar3 from: "$ELVIS_REBAR3_URL + curl -sLfo "$ELVIS_BUILD_DIR/rebar3" "$ELVIS_REBAR3_URL" + chmod +x "$ELVIS_BUILD_DIR/rebar3" + "$ELVIS_BUILD_DIR/rebar3" $@ +else + echo "Using Rebar3: "$ELVIS_REBAR3 + "$ELVIS_REBAR3" $@ +fi diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..694a380 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,6 @@ +PROJECT = test +PROJECT_DESCRIPTION = Test project +PROJECT_VERSION = 0.1.0 + +include erlang.mk +include ../plugins.mk diff --git a/test/run.sh b/test/run.sh new file mode 100755 index 0000000..bc2d188 --- /dev/null +++ b/test/run.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +set -e + +fail() { + echo -e "\033[31mError: $1\033[0m" + exit 1 +} + +prepare_test() { + rm -rf _build elvis elvis.config out.log + echo -e "--- \033[32mTest: $1 \033[0m ---" +} + +cleanup() { + rm -f rebar3 erlang.mk elvis elvis.config out.log + rm -rf _build .erlang.mk +} + +finished_test() { + echo -e "--- \033[32mTest passed\033[0m ---" +} + +cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null + +cleanup + +echo "Preparing ..." +echo -n "Downloading Erlang.mk ..." +curl -sLfo erlang.mk https://erlang.mk/erlang.mk +echo " OK" + +echo -n "Downloading Rebar3 ..." +curl -sLfo rebar3 https://s3.amazonaws.com/rebar3/rebar3 +chmod a+x rebar3 +echo " OK" + +echo "Doing the initial make ..." +make > /dev/null + +prepare_test "Local rebar3, no build dir, no elvis.config" +ELVIS_REBAR3=$(pwd)/rebar3 make elvis || fail "make failed, exit code $?" + +[ -x elvis ] || fail "Elvis executable not found" +[ -f elvis.config ] || fail "elvis.config not found" +[ -e _build ] && fail "build dir ('_build') not removed" + +cp test-elvis.config elvis.config +make elvis > out.log 2>&1 || fail "Elvis rock failed, exit code $?" +[ ! -s out.log ] || (echo "--- out.log ---" && \ + cat out.log && \ + echo "---" && \ + fail "Elvis rock output (out.log) not empty") +finished_test + +prepare_test "Remote rebar3, existing build dir, existing elvis.config" +mkdir -p _build/existing +export ELVIS_REBAR3=not-to-be-found +rm rebar3 +cp test-elvis.config elvis.config + +make elvis || fail "make failed, exit code $?" + +[ -x elvis ] || fail "Elvis executable not found" +cmp --silent test-elvis.config elvis.config || fail "elvis.config was overwritten" +[ -e _build ] || fail "build dir ('_build') removed" + +make elvis > out.log 2>&1 || fail "Elvis rock failed, exit code $?" +[ ! -s out.log ] || (echo "--- out.log ---" && \ + cat out.log && \ + echo "---" && \ + fail "Elvis rock output (out.log) not empty") +finished_test + +cleanup diff --git a/test/test-elvis.config b/test/test-elvis.config new file mode 100644 index 0000000..35d0d6f --- /dev/null +++ b/test/test-elvis.config @@ -0,0 +1,14 @@ +[ + { + elvis, + [ + {config, [ + #{ + dirs => ["."], + filter => "elvis.config", + ruleset => elvis_config + } + ]} + ] + } +].