From 3e32be0aba42020f82c29495207f7789c6b2571a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 17 Sep 2012 23:27:00 +0200 Subject: [PATCH 1/7] Prepare FatPacker directory structure --- .gitignore | 1 + github-keygen => bin/github-keygen | 0 2 files changed, 1 insertion(+) rename github-keygen => bin/github-keygen (100%) diff --git a/.gitignore b/.gitignore index 00977c6..99bb9e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ id_* +fatlib diff --git a/github-keygen b/bin/github-keygen similarity index 100% rename from github-keygen rename to bin/github-keygen From 41ef3e585642189b7bdf4dc0f3b46c0db5c0c0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 17 Sep 2012 23:40:23 +0200 Subject: [PATCH 2/7] Add release.pl (WIP) Work in progress: the release script that FatPack github-keygen with its dependencies (including Pod::Usage that is missing in msysgit). --- release.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 release.pl diff --git a/release.pl b/release.pl new file mode 100755 index 0000000..0aa03b8 --- /dev/null +++ b/release.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +# Only to fail early if the tool is missing +use App::FatPacker (); + +# Pod::Usage is supposed to be in core since 5.6, but it is missing from perl +# bundled in msysgit +my @MODULES = qw(Pod/Usage.pm Text/Diff.pm); + +# Retrieve the packlists +my @packlists = qx(fatpack packlists-for @MODULES); + +# Fill fatlib/ +system qw(fatpack tree), @packlists; +foreach (@MODULES) { + die "$_ is missing!" unless -f "fatlib/$_"; +} +-d 'lib' or mkdir 'lib'; + +# Create the script +system '(fatpack file; cat bin/github-keygen) > github-keygen'; +chmod 0755, 'github-keygen'; + +# TODO +print <<'EOF'; +TODO: + git stash save --include-untracked 'github-keygen fatpacked for release' + git checkout master + git stash pop + git add github-keygen + ???? # Merge to mark devel as merged + git commit + v=$(bin/github-keygen -v | head -n1 | cut -d' ' -f3) + git tag -a -m "Version $v" "v$v" +EOF From a03b8859da7bb79b3b97815fca94b58160122966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 15 Nov 2012 00:43:22 +0100 Subject: [PATCH 3/7] gitignore: github-keygen ignored (committed on release branch) github-keygen is now a generated file that will be committed on the 'release' branch with the 'release.pl' script. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 99bb9e7..5232328 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ id_* fatlib +github-keygen From eff60ed244096a43f44a8f3634583e666f16852f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 15 Nov 2012 00:45:16 +0100 Subject: [PATCH 4/7] release.pl nearly complete release.pl now creates the new merge commit on the 'release' (well 'toto' for now) branch that merges the previous release commit with changes that occured on 'devel' (for example, a README.pod update) and generated files (github-keygen built with fatpacker). --- release.pl | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 2 deletions(-) diff --git a/release.pl b/release.pl index 0aa03b8..15ef4ba 100755 --- a/release.pl +++ b/release.pl @@ -1,7 +1,14 @@ #!/usr/bin/env perl +use 5.010; +use strict; +use warnings; + # Only to fail early if the tool is missing use App::FatPacker (); +use Carp; + +#goto X; # Pod::Usage is supposed to be in core since 5.6, but it is missing from perl # bundled in msysgit @@ -18,10 +25,163 @@ -d 'lib' or mkdir 'lib'; # Create the script -system '(fatpack file; cat bin/github-keygen) > github-keygen'; +system '(echo "#!/usr/bin/env perl"; fatpack file; cat bin/github-keygen) > github-keygen'; chmod 0755, 'github-keygen'; -# TODO +my $version = do { + open my $version_output, '-|', './github-keygen -v' or die $!; + my $line = <$version_output>; + chomp $line; + (split / /, $line)[2] +}; + +if (-e ".git/refs/tags/v$version") { + say STDERR "version $version already released!"; +# exit 1 +} + +say "\$VERSION: $version"; + + +sub git ($;@) +{ + my ($input, $output_cb); + $output_cb = pop if ref $_[$#_] eq 'CODE'; + $input = pop if ref $_[$#_]; + my @args = @_; + say join(' ', '[', git => @args, ']'); + my ($pid, $out); + local $SIG{PIPE} = sub { say "SIGPIPE" }; + if ($input) { + use IPC::Open2; + my $in; + $pid = open2($out, $in, git => @args) or die $!; + binmode($in, ':utf8'); + if (ref $input eq 'ARRAY') { + print $in map { "$_\n" } @$input; + } elsif (ref $input eq 'SCALAR') { + # use ${$input}} as raw input + print $in $$input; + } + close $in; + } else { + $pid = open($out, '-|', git => @args) or die $!; + } + binmode($out, ':utf8'); + if (wantarray) { + my @output; + if ($output_cb) { + while (<$out>) { + chomp; + push @output, $output_cb->($_) + } + } else { + while (<$out>) { + chomp; + push @output, $_ + } + } + waitpid($pid, 0); + croak "git error ".($?>>8) if $? >> 8; + return @output + } elsif (defined wantarray) { + # Only the first line + my $output; + defined($output = <$out>) and chomp $output; + waitpid($pid, 0); + croak "git error ".($?>>8) if $? >> 8; + return $output + } else { # void context + if ($output_cb) { + while (<$out>) { + chomp; + $output_cb->($_) + } + } + waitpid($pid, 0); + croak "git error ".($?>>8) if $? >> 8; + return + } +} + + +#my $old_tree = + +X: + +my @new_files = ( + 'github-keygen', + @ARGV, +); + +#my $devel = `git rev-parse devel`; +#my $master = `git rev-parse master`; +my ($devel_commit) = git 'rev-parse' => 'devel'; +say "devel: $devel_commit"; + +my %devel_tree; +git 'ls-tree' => $devel_commit, sub { + my ($mode, $type, $object, $file) = split; + $devel_tree{$file} = [ $mode, $type, $object ]; +}; + +my ($release_commit) = git 'rev-parse' => 'release'; +say "release: $release_commit"; +my %release_tree; +git 'ls-tree' => $release_commit, sub { + my ($mode, $type, $object, $file) = split / |\t/; + # Merge files updated in devel + if ( $type eq 'blob' # Don't touch trees + && $file ne '.gitignore' # One .gitignore for each branch + && exists $devel_tree{$file} + && $object ne $devel_tree{$file}[2]) { + say "- $file: $object (updated)"; + $release_tree{$file} = $devel_tree{$file}; + } else { + say "- $file: $object"; + $release_tree{$file} = [ $mode, $type, $object ]; + } +}; + +# Create the objects file each new file and replace them +foreach my $file (@new_files) { + # TODO + my $object = git 'hash-object' => -w => $file; + say "- $file: $object (updated)"; + $release_tree{$file}[2] = $object; +} + +# Build the new tree object for release +my $new_release_tree = git mktree => -z => +\( + join( + '', + map { sprintf("%s %s %s\t%s\0", @{$release_tree{$_}}, $_) } + keys %release_tree + ) +); +say "new release tree: $new_release_tree"; + +# Create the release commit +# TODO use the "author" of devel as the committer +my $new_release_commit = + git 'commit-tree', $new_release_tree, + -p => $release_commit, + -p => $devel_commit, + -m => "Release v$version"; + +say "new release commit: $new_release_commit"; + +git 'update-ref' => 'refs/heads/toto' => $new_release_commit, $release_commit; + +exit 0; # ******** + +git tag => -a => + -m => "Release v$version", + "v$version", + $new_release_commit; + +exit 0; print <<'EOF'; TODO: git stash save --include-untracked 'github-keygen fatpacked for release' From 78617516608af3f782e41406d8905be80bfa399b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 15 Nov 2012 00:54:07 +0100 Subject: [PATCH 5/7] Bump github-keygen to version 1.002 (for release) --- bin/github-keygen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/github-keygen b/bin/github-keygen index 5251aac..531a55d 100755 --- a/bin/github-keygen +++ b/bin/github-keygen @@ -13,7 +13,7 @@ use Sys::Hostname; use constant HAS_TEXT_DIFF => eval { require Text::Diff; 1 }; -our $VERSION = '1.001'; +our $VERSION = '1.002'; use constant { PROG => (File::Spec->splitpath($0))[2], From ada99c42f143fb61f92751c15e8af27c48f141a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 15 Nov 2012 01:14:20 +0100 Subject: [PATCH 6/7] release.pl: cleanup --- release.pl | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/release.pl b/release.pl index 15ef4ba..c4a3492 100755 --- a/release.pl +++ b/release.pl @@ -6,9 +6,8 @@ # Only to fail early if the tool is missing use App::FatPacker (); -use Carp; +use Carp 'croak'; -#goto X; # Pod::Usage is supposed to be in core since 5.6, but it is missing from perl # bundled in msysgit @@ -37,7 +36,7 @@ if (-e ".git/refs/tags/v$version") { say STDERR "version $version already released!"; -# exit 1 + exit 1 } say "\$VERSION: $version"; @@ -105,17 +104,12 @@ ($;@) } -#my $old_tree = - -X: my @new_files = ( 'github-keygen', @ARGV, ); -#my $devel = `git rev-parse devel`; -#my $master = `git rev-parse master`; my ($devel_commit) = git 'rev-parse' => 'devel'; say "devel: $devel_commit"; @@ -164,6 +158,7 @@ ($;@) # Create the release commit # TODO use the "author" of devel as the committer +# TODO use more content in the commit message (ask interactively) my $new_release_commit = git 'commit-tree', $new_release_tree, -p => $release_commit, @@ -172,24 +167,12 @@ ($;@) say "new release commit: $new_release_commit"; -git 'update-ref' => 'refs/heads/toto' => $new_release_commit, $release_commit; - -exit 0; # ******** +git 'update-ref' => 'refs/heads/release' => $new_release_commit, $release_commit; git tag => -a => -m => "Release v$version", "v$version", $new_release_commit; -exit 0; -print <<'EOF'; -TODO: - git stash save --include-untracked 'github-keygen fatpacked for release' - git checkout master - git stash pop - git add github-keygen - ???? # Merge to mark devel as merged - git commit - v=$(bin/github-keygen -v | head -n1 | cut -d' ' -f3) - git tag -a -m "Version $v" "v$v" -EOF +say 'Done.'; +say "You can now push: git push github devel release v$version"; From d5c5dd17ea5cb014050f72aa665ca80a2fd30607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 15 Nov 2012 01:29:07 +0100 Subject: [PATCH 7/7] README: changes for 1.002 --- README.pod | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/README.pod b/README.pod index ba93293..45b9172 100644 --- a/README.pod +++ b/README.pod @@ -207,33 +207,6 @@ Fetch the script from GitHub: git clone https://github.com/dolmen/github-keygen.git cd github-keygen -Optional (but recommended to better understand what is done): install the -L Perl module. Use the one packaged by your system distribution -if possible. - -=over 4 - -=item * Debian/Ubuntu: - - sudo apt-get install libtext-diff-perl - -=item * RedHat/Fedora: - - sudo yum install perl-Text-Diff - -=item * OpenSuse: - - sudo zipper install perl-Text-Diff - -=item * Mandriva/Mageia/...: - - sudo urpmi install perl-Text-Diff - -=item * CPAN: - -Install L with your favorite -CPAN client. - =back =head1 UPGRADE @@ -246,6 +219,25 @@ changed (if you have installed the L perl module). git pull --rebase ./github-keygen +=head1 HISTORY + +=item v1.002 + +No functional changes, but distribution changes: branch C abandonned +and replaced by C (build result) and C (source). + +C is now L +from C in the C branch with +L and +L, so those modules do not +have to be installed before usage. + +=item v1.001 and before + +See the git log. + +=back + =head1 SUPPORT IRC: ask C on C.