[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor-browser-build/master] Bug 25101: Add the prune-old-builds script
commit 073dfa5f7402b54cfe7772d71a1c931552908463
Author: Nicolas Vigier <boklm@xxxxxxxxxxxxxx>
Date: Mon Dec 16 20:52:54 2019 +0100
Bug 25101: Add the prune-old-builds script
Previously we were using the prune-old-builds script which was located
in the testsuite repository in tools/prune-old-builds, as a git submodule.
As this script is not used anywhere other than here, it doesn't make
much sense to keep it as a separate git submodule. To simplify
modification of this script, we move it here.
---
.../roles/tbb-nightly-build/files/prune-old-builds | 74 ++++++++++++++++++++++
.../ansible/roles/tbb-nightly-build/tasks/main.yml | 7 ++
.../tbb-nightly-build/templates/start-tbb-nightly | 2 +-
3 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/tools/ansible/roles/tbb-nightly-build/files/prune-old-builds b/tools/ansible/roles/tbb-nightly-build/files/prune-old-builds
new file mode 100755
index 0000000..5d54229
--- /dev/null
+++ b/tools/ansible/roles/tbb-nightly-build/files/prune-old-builds
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+use strict;
+use Getopt::Long;
+use DateTime;
+use DateTime::Duration;
+use File::Path qw(remove_tree);
+
+my %options = (
+ days => 6,
+ weeks => 3,
+ months => 3,
+ prefix => 'tbb-nightly-',
+);
+
+sub keep_builds {
+ my %res;
+
+ my $day = DateTime::Duration->new(days => 1);
+ my $week = DateTime::Duration->new(weeks => 1);
+ my $month = DateTime::Duration->new(months => 1);
+
+ my $n = $options{days};
+ my $dt = DateTime->now;
+ while ($n) {
+ $res{ $options{prefix} . $dt->ymd } = 1;
+ $dt = $dt - $day;
+ $n--;
+ }
+
+ my $w = $options{weeks};
+ while ($dt->day_of_week != 1) {
+ $dt = $dt - $day;
+ }
+ while ($w) {
+ $res{ $options{prefix} . $dt->ymd } = 1;
+ $dt = $dt - $week;
+ $w--;
+ }
+
+ my $m = $options{months};
+ $dt = DateTime->now;
+ while ($dt->day != 1) {
+ $dt = $dt - $day;
+ }
+ while ($m) {
+ $res{ $options{prefix} . $dt->ymd } = 1;
+ $dt = $dt - $month;
+ $m--;
+ }
+
+ return \%res;
+}
+
+sub clean_directory {
+ my ($directory) = @_;
+ my $k = keep_builds;
+ chdir $directory || die "Error entering $directory";
+ foreach my $file (glob "$options{prefix}*") {
+ next unless $file =~ m/^$options{prefix}\d{4}-\d{2}-\d{2}$/;
+ next if $k->{$file};
+ if ($options{'dry-run'}) {
+ print "Would remove $file\n";
+ } else {
+ remove_tree($file);
+ }
+ }
+}
+
+my @opts = qw(days=i weeks=i months=i prefix=s dry-run!);
+Getopt::Long::GetOptions(\%options, @opts);
+die "Missing argument: directory to clean" unless @ARGV;
+foreach my $dir (@ARGV) {
+ clean_directory($dir);
+}
diff --git a/tools/ansible/roles/tbb-nightly-build/tasks/main.yml b/tools/ansible/roles/tbb-nightly-build/tasks/main.yml
index 64d31a9..2c795b8 100644
--- a/tools/ansible/roles/tbb-nightly-build/tasks/main.yml
+++ b/tools/ansible/roles/tbb-nightly-build/tasks/main.yml
@@ -39,6 +39,13 @@
mode: 0644
owner: "{{ nightly_build_user }}"
+- name: prune-old-builds
+ copy:
+ src: prune-old-builds
+ dest: "/home/{{ nightly_build_user }}/prune-old-builds"
+ mode: 0755
+ owner: "{{ nightly_build_user }}"
+
- name: add start-tbb-nightly script
template:
src: start-tbb-nightly
diff --git a/tools/ansible/roles/tbb-nightly-build/templates/start-tbb-nightly b/tools/ansible/roles/tbb-nightly-build/templates/start-tbb-nightly
index 3c1847d..c93bc94 100644
--- a/tools/ansible/roles/tbb-nightly-build/templates/start-tbb-nightly
+++ b/tools/ansible/roles/tbb-nightly-build/templates/start-tbb-nightly
@@ -2,4 +2,4 @@
cd {{ testsuite_dir }}
export RBM_NO_DEBUG=1
./tbb-testsuite --config=tbb-nightly "$@"
-./tools/prune-old-builds/prune-old-builds --prefix '' --days {{ nightly_build_keep_builds }} ./tor-browser-builds
+/home/{{ nightly_build_user }}/prune-old-builds --prefix '' --days {{ nightly_build_keep_builds }} ./tor-browser-builds
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits