# vim: filetype=perl expandtab
use strict;
use FindBin;
use DateTime;
use TBBTestSuite::TestSuite::TorBrowserBuild;

my $date = DateTime->now->ymd;
my $tbb_version = 'tbb-nightly.' . DateTime->now->ymd('.');
my $name = "tor-browser-$date";

if (-d "$options->{'reports-dir'}/r/$name") {
    print "Doing nothing: $name already done\n";
    return ( args => [] );
}

my $testsuite = TBBTestSuite::TestSuite::TorBrowserBuild->new({
        tbb_version => $tbb_version,
        publish_dir => "$FindBin::Bin/tor-browser-builds/$tbb_version",
        publish_url => "{{ nightly_build_url }}/tor-browser-builds/$tbb_version",
        rbm_local_conf => "$FindBin::Bin/rbm-config/tbb-nightly.rbm.local.conf",
        make_clean => 1,
    });

my %res = (
    name => $name,
    args => [ $testsuite ],
    tags => [ 'nightly' ],
    'reports-url' => '{{ nightly_build_url }}/reports/',
    'email-subject' => '[build result: [% success ? "ok" : "failed" %]] [% options.name %]',
    {% if nightly_build_email_to is defined %}'email-report' => 1,{% endif %}
    {% if nightly_build_email_to is defined %}'email-to' => {{ nightly_build_email_to }}{% endif %}
    {% if nightly_build_email_from is defined %}'email-from' => {{ nightly_build_email_from }}{% endif %}
);
%res;
