# Use bash shell with pipefail option enabled so that the return status of a
# piped command is the value of the last (rightmost) commnand to exit with a
# non-zero status. This lets us pipe output into tee but still exit on test
# failures.
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -c

all: test lint

# wait for the device to be available before beginning the test
# A temporary volume is mounted at /build when 'make test' is executing.
# The following steps copy across useful output to this volume which can
# then be extracted to form the CI summary for the test procedure.
test:
	retry --max=10 -- tango_admin --ping-device mid_csp_cbf/sub_elt/master
	retry --max=10 -- tango_admin --ping-device mid_csp_cbf/sub_elt/subarray_01
	retry --max=10 -- tango_admin --ping-device mid_csp_cbf/sub_elt/subarray_02
	retry --max=10 -- tango_admin --ping-device common/elt/master
	retry --max=10 -- tango_admin --ping-device common/elt/subarray_01
	retry --max=10 -- tango_admin --ping-device common/elt/subarray_02
	cd /app && python setup.py test | tee setup_py_test.stdout
	mkdir -p /build/reports && \
        if [ -d /build ]; then \
                mv /app/setup_py_test.stdout /build/csp-lmc-common-setup-test.stdout; \
                mv /app/htmlcov /build/csp-lmc-common_htmlcov; \
                mv /app/coverage.xml /build; \
        fi;
lint:
	pip3 install pylint2junit; \
        mkdir -p /build/reports; \
        cd /app && pylint --output-format=parseable csp_lmc_common | tee /build/csp_lmc_common-code-analysis.stdout; \
        cd /app && pylint --output-format=pylint2junit.JunitReporter csp_lmc_common > /build/reports/csp-lmc-common-linting.xml;

.PHONY: all test lint

