# 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 mid_csp/elt/master
	retry --max=10 -- tango_admin --ping-device mid_csp/elt/subarray_01
	retry --max=10 -- tango_admin --ping-device mid_csp/elt/subarray_02
	cd /app && python setup.py test --addopts='-k-acceptance_tests'| tee setup_py_test.stdout
	mkdir -p /build/reports && \
	if [ -d /build ]; then \
		mv /app/setup_py_test.stdout /build/csp-lmc-mid-setup-test.stdout; \
		mv /app/htmlcov /build/csp-lmc-mid_htmlcov; \
		cp /app/coverage.xml /build/coverage-csp-lmc-mid.xml; \
	fi;
	#cd /build && coverage combine csp-lmc-mid_coverage  csp-lmc-common_coverage && coverage xml
	#cd /build && mv coverage.xml ./reports/code-coverage.xml

lint:
	pip3 install pylint2junit; \
	mkdir -p /build/reports; \
	cd /app && pylint --output-format=parseable csp_lmc_mid | tee /build/csp-lmc-mid-code-analysis.stdout; \
	cd /app && pylint --output-format=pylint2junit.JunitReporter csp_lmc_mid > /build/reports/csp-lmc-mid-linting.xml;

.PHONY: all test lint
