Skip to content

Commit

Permalink
Merge pull request #2 from Tyil/make-release
Browse files Browse the repository at this point in the history
Add command to release a new version of a module
  • Loading branch information
Tyil committed Oct 14, 2017
2 parents 7f6218c + 8aaa04e commit 6281908
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 25 deletions.
51 changes: 26 additions & 25 deletions META6.json
@@ -1,26 +1,27 @@
{
"perl": "6",
"name": "App::Bob",
"version": "0.0.1",
"auth": "github:scriptkitties",
"description": "Bob helps you build and package your modules",
"license": "GPL-3.0",
"depends": [
"JSON::Fast",
"Template::Mustache"
],
"provides": {
"bob": "bin/bob",
"App::Bob": "lib/App/Bob.pm6",
"App::Bob::Package::Ebuild": "lib/App/Bob/Package/Ebuild.pm6"
},
"authors": [
"Patrick Spek <p.spek@tyil.work>"
],
"tags": [
],
"test-depends": [
"Test::META"
],
"source-url": "https://github.com/scriptkitties/perl6-App-Bob.git"
}
"name": "App::Bob",
"perl": "6",
"source-url": "https://github.com/scriptkitties/perl6-App-Bob.git",
"auth": "github:scriptkitties",
"depends": [
"JSON::Fast",
"Template::Mustache"
],
"license": "GPL-3.0",
"provides": {
"bob": "bin/bob",
"App::Bob::Package::Ebuild": "lib/App/Bob/Package/Ebuild.pm6",
"App::Bob": "lib/App/Bob.pm6"
},
"tags": [

],
"test-depends": [
"Test::META"
],
"version": "0.2.1",
"description": "Bob helps you build and package your modules",
"authors": [
"Patrick Spek <p.spek@tyil.work>"
]
}
90 changes: 90 additions & 0 deletions bin/bob
Expand Up @@ -50,3 +50,93 @@ multi sub MAIN("pkg", "ebuild", $path where /META6.json$/, Bool :$force = False)

say "Saved $atom-name";
}

multi sub MAIN("release", $path, Bool :$ask = False)
{
# Define release types
my Str @release-types = (
"Major",
"Minor",
"Bugfix",
);
my Int $default-release = 3;

# Change to the directory to release
chdir $path;

# Make sure the directory is clean
my $git-cmd = run « git status --short », :out;

if (0 < $git-cmd.out.lines.elems) {
die "Refusing to work on an unclean directory.";
}

# Get the META6 info
my %meta = get-meta();

say "Making release for {%meta<name>} v{%meta<version>}";

# Output the possible release types
say "Release type";

for @release-types.kv -> $i, $type {
say " {$i + 1} - $type";
};

# Request user input to select the release type
my Int $release;

loop {
my $input = prompt "Release type [$default-release]: ";

if ($input ~~ /^$ | ^\d+$/) {
$release = $input.Int;
}

if ($release == 0) {
$release = $default-release;
}

$release--;

if ($release < @release-types.elems) {
last;
}
}

# Update the version accordingly
my @version = %meta<version>.split(".");
my @new-version = @version;

given @release-types[$release].lc {
when "major" {
@new-version[0]++;
@new-version[1] = 0;
@new-version[2] = 0;
}
when "minor" {
@new-version[1]++;
@new-version[2] = 0;
}
when "bugfix" {
@new-version[2]++;
}
}

%meta<version> = @new-version.join(".");

say "New release version will be {%meta<version>}";

exit if $ask && !confirm;

put-meta(:%meta);

# Commit the updated META6
run « git add META6.json »;
run « git commit -m "Bump version to {%meta<version>}" »;

exit if $ask && !confirm("Create new dist?");

# Build the dist
MAIN("dist", $path);
}
51 changes: 51 additions & 0 deletions lib/App/Bob.pm6
Expand Up @@ -2,8 +2,21 @@

use v6.c;

use JSON::Fast;

unit module App::Bob;

sub get-meta($path = ".") is export
{
my $meta6 = $path.IO.add("META6.json");

if (! $meta6.e) {
die "No META6.json in {$path.IO.absolute}";
}

from-json(slurp($meta6.path));
}

sub get-dist-fqdn(%meta --> Str) is export
{
return "{get-dist-name(%meta)}-{get-dist-version(%meta)}";
Expand All @@ -26,3 +39,41 @@ sub get-dist-version(%meta --> Str) is export

return %meta<version>.trim;
}

sub put-meta(:%meta, :$path = ".", :$clobber = True) is export
{
my $meta6 = $path.IO.add("META6.json").absolute;

if ($meta6.IO.e && !$clobber) {
die "Not clobbering {$meta6}";
}

spurt($meta6, to-json(%meta))
}

sub confirm(Str $prompt = "Continue?", Bool $default = True --> Bool) is export
{
my Str $options;

if ($default) {
$options = "Y/n";
} else {
$options = "y/N";
}

loop {
my $input = prompt "$prompt [$options] ";

if ($input eq "") {
return $default;
}

if ($input ~~ m:i/y[es]?/) {
return True;
}

if ($input ~~ m:i/no?/) {
return False;
}
}
}

0 comments on commit 6281908

Please sign in to comment.