JOBS = pgapt-jobs.yaml
JJB = jenkins-jobs

all: test lists

# we write to output.tmp first so output.{old,new} are left untouched in case
# JJB aborts
test:
	@echo "*** Testing $(JOBS) ***"
	rm -rf output.tmp
	mkdir output.tmp
	$(JJB) test --config-xml -o output.tmp $(JOBS)
	if test -d output.new; then rm -rf output.old; mv output.new output.old; fi
	mv output.tmp output.new
	test -d output.old && diff -urp output.old output.new || true

update:
	@echo "*** Updating Jenkins from $(JOBS) ***"
	$(JJB) update $(JOBS)

update-pgdgbuild:
	@echo "*** Updating Jenkins from $(JOBS) ***"
	$(JJB) --conf jenkins_jobs.ini update $(JOBS)

# package lists
lists: packages packages.modules packages.betatests packages.backports packages.backports_runtime
packages: pgapt-jobs.yaml
	perl -wle 'use YAML::Syck; $$y = LoadFile("pgapt-jobs.yaml"); foreach $$p (@$$y) { print $$p->{project}->{name} if $$p->{project}->{name} }' | grep -v '^upgrade-' | LC_ALL=C sort > $@
packages.modules: pgapt-jobs.yaml # packages that build PG modules for "beta"
	perl -wle 'use YAML::Syck; $$y = LoadFile("pgapt-jobs.yaml"); foreach $$p (@$$y) { print $$p->{project}->{name} if $$p->{project}->{name} and $$p->{project}->{jobs}->[0] =~ /[+-]beta/ }' | LC_ALL=C sort > $@
packages.betatests: pgapt-jobs.yaml # packages that build PG modules for "beta"
	perl -wle 'use YAML::Syck; $$y = LoadFile("pgapt-jobs.yaml"); foreach $$p (@$$y) { print $$p->{project}->{name} if $$p->{project}->{name} and $$p->{project}->{jobs}->[0] =~ /git/ and $$p->{project}->{jobs}->[0] !~ /-only/ }' | LC_ALL=C sort > $@
packages.%: pgapt-jobs.yaml
	perl -wle 'use YAML::Syck; $$y = LoadFile("pgapt-jobs.yaml"); foreach $$p (@$$y) { print $$p->{project}->{name} if $$p->{project}->{$*} or $$p->{project}->{"<<"}->{$*} }' | LC_ALL=C sort > $@

clean:
	rm -rf output output.old packages.backports*

# schroot config
install: /etc/schroot/chroot.d/sbuild.conf

/etc/schroot/chroot.d/sbuild.conf: ../pgapt.conf schroot-config.sh
	./schroot-config.sh | sudo tee $@
