I was trying to automate more (=keep as far away as possible) the process of pushing to github through a Makefile and I came up with the following simplistic approach. It basically creates a make target called git-push via MY::postamble provided by ExtUtils::MakeMaker. I got the postamble idea from pryrt's answer to Benchmarks target in Makefile

perl Makefile.PL make all make git-push

At first it creates a .gitignore file which whitelists the files/dirs to push, then calls git init, git add ., git commit ... and finally git push ... (I hope it's correct, it works for me).

As it is, it works for me but I am sure there are lots and lots of improvements and safeguards. Also, it does not proceed unless the target repository already exists remotely - there is no git-cmdline-only way to create a repository as I understand.

Possible major improvement would be to use Git::Repository instead of make shelling out git commands. But this is the idea I wanted to share.

Deviations from the normal Makefile.PL are designated by ADD this:

use 5.006; use strict; use warnings; use ExtUtils::MakeMaker; use File::Spec; WriteMakefile( #INSTALL_BASE => $ENV{'HOME'}.'/usr', NAME => '<My::Module::Name>', AUTHOR => q{<MY-NAME> <MY-EMAIL>}, VERSION_FROM => 'My/Module/Name/file.pm', ABSTRACT_FROM => 'My/Module/Name/file.pm', LICENSE => 'artistic_2', PL_FILES => {}, MIN_PERL_VERSION => '5.006', CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => '0', }, BUILD_REQUIRES => { 'Test::More' => '0', 'LWP::UserAgent' => '6.35', 'HTTP::Request::Common' => '6.15', }, PREREQ_PM => { 'File::Spec' => '3.75', }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'My::Module::Name-*' }, # ADD this: postamble => { SRCDIR => '.', # repo must already exist, you must explicitly create it using git +hub web interface # or use some API perhaps? GIT_DESTINATION => 'git@github.com:<GIT-USERNAME>/<GIT-REPO-NAME>. +git', # list of files to add or wildcards, space separated, quote for sh +ell GIT_ADD => '.', # the above with the whitelist gitignore below will add what I nee +d GITIGNORE => <<'EOC', # WARNING: will overwrite any existing .giti +gnore (in dist dir) # whitelist mode: # first, ignore everything /* # then add what we like !lib !bin !*/t !*/xt !Makefile.PL !Changes !MANIFEST !README EOC } ); # ADD this: # this is based on https://www.perlmonks.org/?node_id=1216932 (especia +lly pryrt's answer) sub MY::postamble { my (undef,%h) = @_; #require Data::Dumper; #print STDERR Data::Dumper->Dump([\%h], [qw(mm_args{postamble})]); my $indir = $h{'SRCDIR'}; $indir = '.' unless defined $indir; if( defined $h{'GITIGNORE'} ){ # we have a string of .gitignore content, replace any existing .gi +tignore my $gitignorefile = File::Spec->catdir($indir, '.gitignore'); my $GH; if( ! open $GH, '>:encoding(utf-8)', $gitignorefile ){ print STDER +R "$0 : failed to open '$gitignorefile' file for writing.\n"; exit(1) + } print $GH $h{'GITIGNORE'}; close $GH } # if # append to Makefile, newlines and tabs are important! my $ret = "git-push ::\n"; $ret .= "\t".'@git ls-remote '.$h{GIT_DESTINATION}.' &> /dev/null +|| (echo "make : you need to create the repository '.$h{GIT_DESTINATI +ON}.' first ..."; exit 1)'."\n"; $ret .= "\tgit init\n"; $ret .= "\tgit add ".(exists($h{'GIT_ADD'})?$h{'GIT_ADD'}:'.')."\n +"; $ret .= "\tgit commit -am 'first commit'\n"; $ret .= "\t".'git push -f "'.$h{GIT_DESTINATION}.'" --all'."\n"; return $ret; }

bw, bliako


In reply to git-push target for Makefile (via ExtUtils::MakeMaker) by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.