boklm pushed to branch main at The Tor Project / Applications / tor-browser-bundle-testsuite Commits: d7f73057 by Nicolas Vigier at 2026-07-30T17:00:17+02:00 Bug 40100: Add nightly pipelines status email - - - - - 9 changed files: - .gitignore - + TBBTestSuite/TestSuite/TorBrowserBuildGitlabPipelines.pm - TBBTestSuite/TestSuites.pm - config/tb-build-06.torproject.org - + config/tb-build-06.torproject.org-gitlab-pipelines - + tmpl/details_gitlab_pipeline.html - + tmpl/report_tor-browser_pipelines.txt - + tmpl/reports_index_tor-browser_pipelines.html - tools/tb-build-06-start-nightly-build Changes: ===================================== .gitignore ===================================== @@ -7,3 +7,4 @@ reports tmp bundle tools/.gitlab_trigger_token +gitlab-tokens ===================================== TBBTestSuite/TestSuite/TorBrowserBuildGitlabPipelines.pm ===================================== @@ -0,0 +1,140 @@ +package TBBTestSuite::TestSuite::TorBrowserBuildGitlabPipelines; + +use strict; +use parent 'TBBTestSuite::TestSuite'; + +use FindBin; +use TBBTestSuite::Common qw(run_to_file exit_error); +use TBBTestSuite::GitRepo; +use TBBTestSuite::Options qw($options); +use File::Copy; +use File::Slurp; +use IO::CaptureOutput qw(capture_exec); +use Path::Tiny; +use LWP::UserAgent; +use JSON; +use Data::Dump qw/dd/; + +sub description { + 'Tor Browser Build Gitlab Pipelines'; +} + +sub type { + 'tor-browser_pipelines'; +}; + +sub test_types { + return { + gitlab_pipeline => \&gitlab_pipeline, + } +} + +sub gitlab_access_token { + my $token_dir = "$FindBin::Bin/gitlab-tokens"; + my $token_file = "$token_dir/access-token"; + exit_error "File $token_file is missing" unless -f $token_file; + # Change permission on gitlab-tokens directory to make sure token files + # cannot be accessed by other users + chmod 0700, $token_dir; + my $token = read_file($token_file); + chomp $token; + return $token; +} + +sub get_ua { + my $token = gitlab_access_token; + my $ua = LWP::UserAgent->new; + $ua->default_header('PRIVATE-TOKEN' => $token); + return $ua; +} + +sub get_pipeline_status { + my ($pipeline_id) = @_; + my $ua = get_ua; + my $url = "https://gitlab.torproject.org/api/v4/projects/409/pipelines/$pipeline_id"; + my $count = 100; + while ($count) { + my $response = $ua->get($url); + if ($response->is_success) { + my $result = eval { decode_json $response->decoded_content }; + my %finished_status = map { $_ => 1 } + qw/success failed canceling canceled skipped/; + if (ref $result eq 'HASH' && $result->{status} + && $finished_status{$result->{status}}) { + return $result->{status}; + } + } + $count--; + sleep 60; + } + return 'timeout'; +} + +sub get_failed_jobs { + my ($pipeline_id) = @_; + my @res; + my $ua = get_ua; + my $url = "https://gitlab.torproject.org/api/v4/projects/409/pipelines/$pipeline_id/jobs?scope[]=failed"; + my $response = $ua->get($url); + return \@res unless $response->is_success; + my $result = eval { decode_json $response->decoded_content }; + return \@res unless ref $result eq 'ARRAY'; + foreach my $job (@$result) { + push @res, { + id => $job->{id}, + url => "https://gitlab.torproject.org/tpo/applications/tor-browser-bundle-testsuite/-/jobs/$job->{id}", + name => $job->{name}, + failure_reason => $job->{failure_reason}, + }; + } + return \@res; +} + +sub gitlab_pipeline { + my ($testsuite, $test) = @_; + $test->{results}{success} = 0; + my $pipeline_id; + $pipeline_id = $1 + if $test->{gitlab_pipeline_url} =~ m{https://gitlab.torproject.org/tpo/applications/tor-browser-bundle-testsuite/-/pipelines/(\d+)}; + return unless $pipeline_id; + my $status = get_pipeline_status($pipeline_id); + $test->{pipeline_status} = $status; + $test->{results}{success} = 1 if $status eq 'success'; + $test->{failed_jobs} = get_failed_jobs($pipeline_id) + if $status eq 'failed'; +} + +sub set_tests { + my ($testsuite) = @_; + exit_error "tbb_buildreport_dir option is missing" unless $testsuite->{tbb_buildreport_dir}; + $testsuite->{tests} = []; + my $tbb_buildreport = $testsuite->{tbb_buildreport_dir}; + return unless -d $tbb_buildreport; + foreach my $pipeline (path($tbb_buildreport)->children(qr/\.trigger-test-pipeline\.stdout\.txt\z/)) { + my $url = $pipeline->slurp_utf8; + my $name = $pipeline->basename; + if ($name =~ m/^(.+)\.trigger-test-pipeline\.stdout\.txt\z/) { + my $test_name = "pipeline-$1"; + push @{$testsuite->{tests}}, { + name => $test_name, + descr => $test_name, + type => 'gitlab_pipeline', + gitlab_pipeline_url => $url, + }; + } + } +} + +sub new { + my ($ts, $infos) = @_; + my $testsuite = { + %$infos, + type => $ts->type(), + filename => $ts->type(), + }; + bless $testsuite, $ts; + $testsuite->set_tests(); + return $testsuite; +} + +1; ===================================== TBBTestSuite/TestSuites.pm ===================================== @@ -7,11 +7,12 @@ use TBBTestSuite::TestSuite::BrowserBundleTests; use TBBTestSuite::TestSuite::BrowserUnitTests; use TBBTestSuite::TestSuite::RBMBuild; use TBBTestSuite::TestSuite::TorBrowserBuild; +use TBBTestSuite::TestSuite::TorBrowserBuildGitlabPipelines; use TBBTestSuite::TestSuite::BrowserBundleHardening; my @testsuite_list = qw(TestTestSuite BrowserBundleTests BrowserUnitTests RBMBuild TorBrowserBuild - BrowserBundleHardening); + TorBrowserBuildGitlabPipelines BrowserBundleHardening); my %testsuite_types; sub testsuite_types { return %testsuite_types if %testsuite_types; ===================================== config/tb-build-06.torproject.org ===================================== @@ -7,6 +7,7 @@ use File::Slurp; use TBBTestSuite::TestSuite::TorBrowserBuild; my $date = DateTime->now->ymd; +$date = $ENV{NIGHTLY_BUILD_DATE} if $ENV{NIGHTLY_BUILD_DATE}; my $tbb_version = 'tbb-nightly.' . DateTime->now->ymd('.'); my $name = "tor-browser-$date"; ===================================== config/tb-build-06.torproject.org-gitlab-pipelines ===================================== @@ -0,0 +1,45 @@ +# vim: filetype=perl expandtab +use strict; +use FindBin; +use DateTime; +use TBBTestSuite::TestSuite::TorBrowserBuildGitlabPipelines; + +my $date = DateTime->now->ymd; +$date = $ENV{NIGHTLY_BUILD_DATE} if $ENV{NIGHTLY_BUILD_DATE}; +my $name = "tor-browser-pipelines-$date"; + +my $builds_dir_root = '/home/tb-builder/nightly-builds'; +my $reports_dir = "$builds_dir_root/reports"; + +if (-d "$reports_dir/r/$name") { + print "Doing nothing: $name already done\n"; + return ( args => [] ); +} + +my $testsuite = TBBTestSuite::TestSuite::TorBrowserBuildGitlabPipelines->new({ + tbb_buildreport_dir => "$reports_dir/r/tor-browser-$date/results-tor-browser_build", + }); + +my %res = ( + name => $name, + args => [ $testsuite ], + tags => [ 'nightly' ], + 'default-retry' => 1, + 'reports-dir' => $reports_dir, + 'reports-url' => 'https://nightlies.tbb.torproject.org/nightly-builds/reports/', + 'email-subject' => '[pipelines result: [% tbbfile = "tor-browser_pipelines"; tbbfiles.$tbbfile.tests.size == 0 ? "skipped" : success ? "ok" : "failed" %]] [% options.name %]', + 'email-report' => 1, + 'email-to' => [ + 'bea@torproject.org', + 'boklm@torproject.org', + 'clairehurst@torproject.org', + 'dan@torproject.org', + 'henry@torproject.org', + 'jwilde@torproject.org', + 'ma1@torproject.org', + 'morgan@torproject.org', + 'pierov@torproject.org', + ], + 'email-from' => 'Tor Browser Nightly Builds <tb-builder@tb-build-06.torproject.org>', +); +%res; ===================================== tmpl/details_gitlab_pipeline.html ===================================== @@ -0,0 +1,11 @@ +<ul> +[% IF test.pipeline_status %] + <li>Status: [% test.pipeline_status %] +[% END %] + <li><a href="[% test.gitlab_pipeline_url %]">GitLab test pipeline</a></li> +[% IF test.failed_jobs %] + [% FOREACH job = test.failed_jobs %] + <li>Failed job: <a href="[% job.url %]">[% job.name %](#[% job.id %])</a> - [% job.failure_reason %]</li> + [% END %] +[% END %] +</ul> ===================================== tmpl/report_tor-browser_pipelines.txt ===================================== @@ -0,0 +1,20 @@ +Results +[% IF tbbfiles.$tbbfile.tests.size == 0 -%] + + No pipeline has been run in today's nightly builds. + +[% END -%] +[% FOREACH test IN tbbfiles.$tbbfile.tests -%] +[% IF test.results -%] + [% test.name %]: [% test.results.success ? 'ok' : 'failed (' _ test.fail_type _ ')' %] + + GitLab test pipeline: [% test.gitlab_pipeline_url ? test.gitlab_pipeline_url : 'failed run' %] +[% IF test.failed_jobs -%] + [%- FOREACH job = test.failed_jobs -%] + Failed job ([% job.failure_reason %]): [% job.url %] + [%- END -%] + +[% END -%] + +[% END -%] +[% END %] ===================================== tmpl/reports_index_tor-browser_pipelines.html ===================================== @@ -0,0 +1,61 @@ +[% USE date -%] +<html> + <head> + <title>Tests reports</title> + <style type="text/css"> + .test_ok { + color: #006600; + font-weight: bold; + } + .test_ok A { + color: #006600; + font-weight: bold; + } + .test_notok { + color: #FF0000; + font-weight: bold; + } + .test_notok A { + color: #FF0000; + } + .reportdate { + font-size: small; + } + </style> + </head> + <body> + <h1>[% title %]</h1> + <table> + <tr> + <th>Name</th> + <th>Date</th> + <th>Version</th> + <th>Result</th> + </tr> + [% FOREACH report IN reports_list %] + <tr> + <td valign="top"><a href="r/[% report %]/[% testsuite_type %].html">[% report %]</a></td> + <td valign="top">[% date.format(reports.$report.time, '%Y-%m-%d %H:%M') %]</td> + <td valign="top">[% IF reports.$report.options.tags %] + <a href="index-[% testsuite_type %]-[% reports.$report.options.tags.0 %].html">[% reports.$report.options.tags.0 %]</a> + [% END %] + </td> + <td valign="top"> + [% failed = 0 %] + [% SET tbbfile = reports.$report.tbbfiles.keys.0 -%] + [% FOREACH test IN reports.$report.tbbfiles.$tbbfile.tests %] + [% NEXT UNLESS test.results %] + [% IF test.results.success %] + <img src="static/ok-small.png" /> + <span class="test_ok"><a href="r/[% report %]/[% testsuite_type %].html">[% test.name %]</a></span> + [% ELSE -%] + <img src="static/failed-small.png" /> + <span class="test_notok"><a href="r/[% report %]/[% tbbfile %].html">[% test.name %]</a></span> + [% END -%] + [% END -%] + </td> + </tr> + [% END %] + </table> + </body> +</html> ===================================== tools/tb-build-06-start-nightly-build ===================================== @@ -22,6 +22,7 @@ function getlock { getlock today_version=$(date '+tbb-nightly.%Y.%m.%d') +export NIGHTLY_BUILD_DATE=$(date +"%Y-%m-%d") cd /home/tb-builder/tor-browser-bundle-testsuite export RBM_NO_DEBUG=1 @@ -73,6 +74,8 @@ builds_size=$(du -s ~/nightly-builds/tor-browser-builds | cut -f 1) test "$builds_size" -gt 20000000 && \ /home/tb-builder/tor-browser-bundle-testsuite/clones/tor-browser-build/tools/prune-old-builds --days 7 --weeks 0 --months 0 ~/nightly-builds/tor-browser-builds +./tbb-testsuite --config=tb-build-06.torproject.org-gitlab-pipelines "$@" + # sleep for 5m to give time to previous rsync to finish sleep 5m /home/tb-builder/tor-browser-bundle-testsuite/tools/rsync-to-tbb-nightlies-master View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-bundle-testsuite/... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-bundle-testsuite/... You're receiving this email because of your account on gitlab.torproject.org. Manage all notifications: https://gitlab.torproject.org/-/profile/notifications | Help: https://gitlab.torproject.org/help
participants (1)
-
boklm (@boklm)