Created
August 17, 2013 08:36
-
-
Save briandfoy/6255936 to your computer and use it in GitHub Desktop.
Put .travis.yml files in all my git repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use v5.10; | |
use utf8; | |
binmode STDOUT, ':encoding(UTF-8)'; | |
binmode STDERR, ':encoding(UTF-8)'; | |
use File::Basename qw(dirname); | |
use File::Spec::Functions qw(catfile); | |
my $sub = make_shorten_string( 70, '…' ); | |
my $travis_file_name = '.travis.yml'; | |
my $travis_config =<<"HERE"; | |
language: perl | |
perl: | |
- "5.10" | |
- "5.12" | |
- "5.14" | |
- "5.16" | |
- "5.18" | |
HERE | |
foreach my $dot_git_dir ( @ARGV ) { | |
say $sub->( $dot_git_dir ); | |
my $dir = dirname( $dot_git_dir ); | |
chdir( $dir ) or die "$!"; | |
unless( -e catfile( $dot_git_dir, 'HEAD' ) ) { | |
warn "\t→ Did not find ./HEAD → skipping\n"; | |
next; | |
} | |
my $travisyml = catfile( $dir, $travis_file_name ); | |
if( 0 && -s $travisyml ) { | |
say "\tFound $travis_file_name → skipping"; | |
next; | |
} | |
open my $fh, '>:utf8', $travisyml or do { | |
warn "\t→ Could not open $travisyml\n\t→ $!\n"; | |
next; | |
}; | |
print { $fh } $travis_config; | |
close $fh; | |
`git add -f $travisyml`; | |
`git commit -m 'Added Travis CL config' $travisyml`; | |
`git push --all`; | |
} | |
sub make_shorten_string { | |
my( $max_length, $replacement ) = @_; | |
sub { | |
my $string = shift; | |
my $length = length $string; | |
return $string if $length <= $max_length; | |
my $need_to_remove = $length - $max_length + length $replacement; | |
substr $string, | |
$middle - $need_to_remove / 2, | |
$need_to_remove, | |
$replacement; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment