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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: git-push target for Makefile (via ExtUtils::MakeMaker)
by Haarg (Priest) on May 27, 2019 at 13:19 UTC | |
by bliako (Abbot) on May 27, 2019 at 15:53 UTC | |
by Aldebaran (Curate) on May 31, 2019 at 06:31 UTC | |
by soonix (Chancellor) on May 31, 2019 at 07:32 UTC | |
by Aldebaran (Curate) on May 31, 2019 at 21:42 UTC | |
by bliako (Abbot) on May 31, 2019 at 09:25 UTC | |
|
Re: git-push target for Makefile (via ExtUtils::MakeMaker)
by bliako (Abbot) on May 27, 2019 at 16:02 UTC |