Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to release a new version of a module #2

Merged
merged 5 commits into from Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}
}