Skip to content

Instantly share code, notes, and snippets.

@MARTIMM
Created July 31, 2019 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MARTIMM/a48078be6a7a207dc03d9d5882ea6dae to your computer and use it in GitHub Desktop.
Save MARTIMM/a48078be6a7a207dc03d9d5882ea6dae to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
use v6;
use JSON::Fast;
use CPAN::Uploader::Tiny;
#-------------------------------------------------------------------------------
sub MAIN ( *@p6-dirs is copy ) {
@p6-dirs //= ();
for @p6-dirs -> $p6-dir {
next unless "$p6-dir".IO.d;
# Check for a Meta file and if there is a git directory
if "$p6-dir/META6.json".IO.r and "$p6-dir/.git".IO.d {
archive($p6-dir);
}
}
}
#-------------------------------------------------------------------------------
sub archive ( Str $p6-dir is copy ) {
# remove trailing slash if any
$p6-dir ~~ s/ '/' $ //;
chdir($p6-dir);
# Read the meta file and get the version
my Hash $meta = from-json('META6.json'.IO.slurp);
my Str $version = $meta<version>;
# Remove a leading 'v' if it is used, then keep only 3 version parts
# separated by 2 dots. CPAN does not like more dots than two.
$version ~~ s:i/ ^ 'v' //;
$version ~~ s/ \. \d+ $ // while $version.comb(/\./).join.chars > 2;
note "Build git archive $p6-dir-$version.tar.gz";
run 'git', 'archive', "--prefix=$p6-dir-$version/",
'-o', "../$p6-dir-$version.tar.gz", 'HEAD';
chdir('..');
# A file $HOME/.pause must exist with username and password.
# This file may be encrypted. Two rows are in this file;
# user <username>
# password <password>
my $uploader = CPAN::Uploader::Tiny.new-from-config($*HOME.add: '.pause');
try {
$uploader.upload("$p6-dir-$version.tar.gz");
note "$p6-dir-$version.tar.gz is uploaded to PAUSE";
CATCH {
default {
note "Error: $_.message";
}
}
}
note "Remove $p6-dir-$version.tar.gz";
unlink "$p6-dir-$version.tar.gz";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment