#!/bin/bash
set -e

luacheck ./openwisp-monitoring/ -a

# will be 1 by default when run through github actions
CI=${CI:-0}

if [ "$CI" -eq "1" ]; then
	# copy files in github actions so that shell formatter can check for them
	cp openwisp-monitoring/files/monitoring.agent monitoring_agent
	cp openwisp-monitoring/files/monitoring.init monitoring_init
else
	# check scripts formaating
	shellcheck \
		install-dev.sh \
		qa-format \
		run-qa-checks \
		runbuild \
		runtests \
		./openwisp-monitoring/files/monitoring.init \
		./openwisp-monitoring/files/monitoring.agent \
		./openwisp-monitoring/files/netjson-monitoring

	shfmt -d .
	shfmt -d openwisp-monitoring/files/monitoring.agent
	shfmt -d openwisp-monitoring/files/monitoring.init
fi

openwisp-qa-check \
	--skip-checkmigrations \
	--skip-isort \
	--skip-flake8 \
	--skip-black
