Skip to content

Instantly share code, notes, and snippets.

@wakaba
Created August 6, 2012 06:57
Show Gist options
  • Save wakaba/3271758 to your computer and use it in GitHub Desktop.
Save wakaba/3271758 to your computer and use it in GitHub Desktop.
Maintaining GitHub repository mirrors
use strict;
use warnings;
use Path::Class;
use File::Temp qw(tempdir);
my $config_f = file(__FILE__)->dir->parent->subdir('config')->file('repos.txt');
my @repo = grep { length and not /^\#/ } split /\n/, scalar $config_f->slurp;
my $temp_d = dir(tempdir(CLEANUP => 1));
$temp_d->mkpath;
for (@repo) {
my ($name, @branch) = split /\s+/, $_;
push @branch, 'master';
my $from_url = q<git://github.com/> . $name;
my $to_url = q<git@repository:/git/repository/github/> . $name;
my $repo_d = $temp_d->subdir($name);
system 'git', 'clone', $from_url => $repo_d;
chdir $repo_d or die "Can't chdir $repo_d";
system 'git', 'remote', 'add', 'myrepo', $to_url;
system 'git', 'fetch', 'myrepo';
for my $branch (@branch) {
system 'git', 'checkout', -b => $branch, 'origin/' . $branch;
system 'git', 'checkout', $branch;
system 'git', 'merge', 'myrepo/' . $branch;
system 'git', 'push', 'myrepo', $branch;
}
}
END {
chdir $temp_d->parent;
}
=head1 AUTHOR
Wakaba <wakabatan@hatena.ne.jp>
=head1 LICENSE
Copyright 2012 Hatena <http://www.hatena.ne.jp/>.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
22,52 * * * * repouser cd @@ROOT@@ && make sync-all
# ------ Configuration files ------
config-all: config-cron
config-cron:
mkdir -p local/config/cron.d
cd config/cron.d.src && find -type f | \
xargs -l1 -i% -- sh -c "cat % | sed 's/@@ROOT@@/$(subst /,\\/,$(abspath .))/g' > ../../local/config/cron.d/%"
# ------ Sync operations ------
PERL_ENV = PATH=$(PERL_PATH):$(PATH) PERL5LIB=$(shell cat config/perl/libs.txt)
sync-all:
$(PERL_ENV) $(PERL) bin/sync.pl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment