#!/usr/bin/make -f

UPSTREAM_GIT := https://github.com/openstack-infra/jenkins-job-builder.git
include /usr/share/openstack-pkg-tools/pkgos.make

LAST_CHANGE = $(shell dpkg-parsechangelog -S Date)
BUILD_DATE  = $(shell LC_ALL=C date -u "+%B %d, %Y" -d "$(LAST_CHANGE)")
SPHINXOPTS := -D html_last_updated_fmt="$(BUILD_DATE)"

%:
	dh $@ --with python2,python3,sphinxdoc

override_dh_clean:
	rm -rf doc/build build .testrepository

override_dh_installman:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	sphinx-build $(SPHINXOPTS) -b man doc/source doc/build/man
endif

override_dh_auto_install:
	pkgos-dh_auto_install

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test 'tests\.(?!(.*TestCaseModuleBuilders\.test_yaml_snippet.*|.*TestCaseModulePublishers\.test_yaml_snippet.*|.*builder\.test_builder\.TestCaseTestBuilder\.test_plugins_list.*|.*builder\.test_builder\.TestCaseTestBuilder\.test_plugins_list_from_jenkins.*|.*localyaml\.test_localyaml\.TestCaseLocalYamlIncludeAnchors\.test_multiple_same_anchor_in_multiple_toplevel_yaml.*))'
endif

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. sphinx-build $(SPHINXOPTS) -b html doc/source debian/jenkins-job-builder-doc/usr/share/doc/jenkins-job-builder-doc/html
	dh_sphinxdoc -O--buildsystem=python_distutils
endif

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
