#!/usr/bin/perl
# $Id: release,v 1.1.1.1 2005/12/24 18:52:19 comdog Exp $

=head1 NAME

release - upload files to the CPAN and SourceForge.net

=head1 SYNOPSIS

release [ LOCAL_FILE REMOTE_FILE ]

=head1 DESCRIPTION

This program automates Perl module releases.  It makes the distribution,
tests it, checks that CVS is up to date, tags CVS, uploads it to
the PAUSE anonymous FTP directory and to the incoming directory for
SourceForge.net, claims it on PAUSE for your CPAN account, and releases
it on SourceForge.net.

=head2 Process

The release script checks many things before it actually releases
the file.  Some of these are annoying, but they are also the last
line of defense against releasing bad distributions.

=over 4

=item Read the configuration data

Look in the current working directory for C<.releaserc>.  See
the Configuration section.  If release cannot find the
configuration file, it dies.

=item Test and make the distribution

Run make realclean, perl Makefile.PL, make test, make dist, make
disttest.  If testing fails, release dies.  make dist provides the name
of the distribution if LOCAL_FILE is not provided on the command line.

=item Check that CVS is up-to-date

You can release a file without CVS being up-to-date, but this
script also tags the repository with the version number of the
release, so it insists on CVS being up-to-date.  It fails otherwise.

=item Upload to PAUSE and SourceForge.net

Simply drop the distribution in the incoming/ directory of these
servers.

=item Claim the file on PAUSE

Connect to the PAUSE web thingy and claim the uploaded file for your
CPAN account.

=item Tag the repository

Use the version number (in the distribution name) to tag
the repository.  You should be able to checkout the code
from any release.

=item Release to SourceForge.net

The release name is the distribution name without the .tar.gz.
The file name is the distribution name.  SourceForge.net divides
things into projects (with project IDs) and packages within
the project (with package IDs).  Specify these in the
configuration file.

=back

=head2 Configuration

The release script uses a configuration file in the current working
directory.  The file name is F<.releaserc>.  Although most of the
information is the same for all of your projects, the C<sf_package_id>
is probably different.  You can get the C<sf_package_id> from the data
in the Quick Release Form.

release's own F<.releaserc> looks like this:

    sf_user petdance
    sf_group_id 36221
    sf_package_id 56559
    cpan_user PETDANCE

=over 4

=item cpan_user

=item sf_user

If C<cpan_user> or C<sf_user> is set to C<< <none> >>, the program will
skip releasing for that system.  You must release for at least one system.

=item sf_group_id

=item sf_package_id

=item sf_processor_id

=item sf_type_id

=item sf_release_match

=item sf_release_replace

To find C<sf_package_id> and C<sf_group_id>, go to the Add/Edit
Release page for your project.  The link for "[Add Release]" might
look something like this (this is the link for the F<release> package
itself):

    https://sourceforge.net/project/admin/newrelease.php?package_id=56559&group_id=36221

so C<sf_package_id> is 56559 and C<sf_group_id> is 36221.

C<sf_processor_id> and C<sf_type_id> are optional, and default to "Any"
and "Source .gz".  See the HTML in a file release form on SourceForge.net
for other options.

C<sf_release_match> and C<sf_release_replace> are for defining the release
name, if you don't like the default.  For example, the default would
set the name for this program to something like "release-0.10".
But if you want the name to be only the version number, set
C<sf_release_match=^.+-([\d.]+)$> and C<sf_release_replace=$1>.

=item passive_ftp

Set C<passive_ftp> to "y" or "yes" for passive FTP transfers.  Usually
this is to get around a firewall issue.

=item release_subclass

Specify the name of a subclass to use instead of Module::Release.  The
subclass can override any of the Module::Release methods.  This makes
it possible to maintain your own local releasing procedures.  For
instance, one such subclass might look like this:

  package Module::Release::KWILLIAMS;
  use base qw(Module::Release);
  
  sub make_cvs_tag {
    my $self = shift;
    (my $version) = $self->{remote} =~ / - (\d[\w.]*) \.tar \.gz $/x;
    $version =~ s/[^a-z0-9_]/_/gi;
    return "release-$version";
  }
  1;

To use this subclass, you'd put it in your C<@INC> somewhere, then set
C<release_subclass> to C<Module::Release::KWILLIAMS>.

=back

=head2 Environment

=over 4

=item * CPAN_PASS

=item * SF_PASS

release reads the C<CPAN_PASS> and C<SF_PASS> environment variables to
set the passwords for PAUSE and SourceForge.net, respectively.  Of course,
you don't need to set the password for a system you're not uploading to.

=item * RELEASE_DEBUG

The C<RELEASE_DEBUG> environment variable sets the debugging value,
which is 0 by default.  Set C<RELEASE_DEBUG> to a true value to get
debugging output.

=item * PERL

The C<PERL> environment variable sets the path to perl for use in the
make; otherwise, the perl used to run release will be used.

=back

=head1 TO DO

=over 4

=item * check make disttest (to catch MANIFEST errors) -- needs error catching and reporting

=back

=head1 SOURCE AVAILABILITY

This source is part of a SourceForge.net project which always has the
latest sources in CVS, as well as all of the previous releases.

        http://sourceforge.net/projects/brian-d-foy/

If, for some reason, I disappear from the world, one of the other
members of the project can shepherd this software appropriately.

=head1 AUTHOR

brian d foy, C<< <bdfoy@cpan.org> >> and
Andy Lester, C<< <andy@petdance.com> >>

=head1 COPYRIGHT

Copyright 2002-2003, brian d foy, All rights reserved.

You may use this software under the same terms as Perl itself.

=cut


use strict;

use Module::Release;

use Getopt::Std;

my %opts;
getopts('hdt', \%opts) or $opts{h} = 1;

if ($opts{h}) {
        print <<"USAGE";

Usage: release -hdt [ LOCAL_FILE REMOTE_FILE ]

Will upload current release LOCAL_FILE, naming it REMOTE_FILE.  Will
get LOCAL_FILE and REMOTE_FILE automatically (using same name for both)
if not supplied.

  -h   This help
  -d   Print extra debugging information
  -t   Just make and test distribution, don't tag/upload

The program works in the current directory, and looks for a .releaserc
file and the environment for its preferences.  See `man release`, or
`perldoc $0`, for more information.

USAGE
        exit();
}

# Construct the Release object
my %params;
$params{local}  = shift(@ARGV) if @ARGV;
if (@ARGV) {
    $params{remote} = shift(@ARGV);
} elsif ($params{local}) {
    $params{remote} = $params{local};
}

$params{debug} = 1 if $opts{d};

my $r = Module::Release->new(%params);
warn "release, based on Module::Release $Module::Release::VERSION\n" if $params{debug};

$r->clean;
$r->build_makefile;
$r->test;
$r->dist;
$r->dist_test;
$r->check_cvs;
exit if $opts{t};

$r->check_for_passwords;
$r->ftp_upload;
$r->pause_claim;
$r->cvs_tag;
$r->sf_login;
$r->sf_qrs;
$r->sf_release;

print "Done.\n";

__END__
