| 1 | package ShipIt::Step::AddToSVNDir; | ||
| 2 | use strict; | ||
| 3 | use base 'ShipIt::Step'; | ||
| 4 | use File::Copy (); | ||
| 5 | use ShipIt::Util qw(in_dir); | ||
| 6 | use File::Basename qw(basename); | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | ShipIt::Step::AddToSVNDir - copies/adds/commits distfile to local (svn) directory | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | This step takes the resultant distfile and copies it to a local | ||
| 15 | directory (which is backed by svn), does svn add, svn up, and svn | ||
| 16 | commits that file. | ||
| 17 | |||
| 18 | Presumably, the post-commit hook on that svn repo then triggers some | ||
| 19 | remote webserver elsewhere to svn up and make the distfile appear to | ||
| 20 | your users. (At least that's how it works for me... :)) | ||
| 21 | |||
| 22 | =head1 CONFIGURATION | ||
| 23 | |||
| 24 | In .shipit config: | ||
| 25 | |||
| 26 | AddToSVNDir.dir = /path/to/some/directory/ | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | sub init { | ||
| 31 | my ($self, $conf) = @_; | ||
| 32 | $self->{dir} = $conf->value("AddToSVNDir.dir"); | ||
| 33 | $self->{dir} =~ s/^~/$ENV{HOME}/; | ||
| 34 | die "AddToSVNDir.dir not defined in config." unless $self->{dir}; | ||
| 35 | die "AddToSVNDir.dir's value isn't a directory." unless -d $self->{dir}; | ||
| 36 | die "AddToSVNDir.dir's value isn't an svn directory." unless -d "$self->{dir}/.svn"; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub run { | ||
| 40 | my ($self, $state) = @_; | ||
| 41 | my $distfile = $state->distfile; | ||
| 42 | die "No distfile was created!" unless $distfile; | ||
| 43 | die "distfile $distfile no longer exists!" unless -e $distfile; | ||
| 44 | |||
| 45 | if ($state->dry_run) { | ||
| 46 | warn "*** DRY RUN, not adding to SVN dir!\n"; | ||
| 47 | return; | ||
| 48 | } | ||
| 49 | |||
| 50 | my $base = basename($distfile); | ||
| 51 | die "dest file already exists" if -e "$self->{dir}/$base"; | ||
| 52 | |||
| 53 | File::Copy::copy($distfile, $self->{dir}) or | ||
| 54 | die "file copy of $distfile to $self->{dir} failed: $!\n"; | ||
| 55 | |||
| 56 | in_dir($self->{dir}, sub { | ||
| 57 | system("svn", "add", $base) and die "svn add failed"; | ||
| 58 | system("svn", "up") and die "svn up failed"; | ||
| 59 | system("svn", "ci", "-m", "auto-adding file using shipit", $base) and die "svn ci failed"; | ||
| 60 | }); | ||
| 61 | |||
| 62 | } | ||
| 63 | |||
| 64 | 1; |