CPANci: Continuous Integration for CPAN

135
Testing CPAN in the 21st Century Mike Friedman (friedo) YAPC::NA 2013 Austin, TX Tuesday, June 4, 13

description

A continuous integration framework for the CPAN

Transcript of CPANci: Continuous Integration for CPAN

Page 1: CPANci: Continuous Integration for CPAN

Testing CPANin the

21st CenturyMike Friedman

(friedo)

YAPC::NA 2013 Austin, TX

Tuesday, June 4, 13

Page 2: CPANci: Continuous Integration for CPAN

A lengthy series of bad ideas and stupid

questions.

Tuesday, June 4, 13

Page 3: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 4: CPANci: Continuous Integration for CPAN

Stupid Question No. 1

Tuesday, June 4, 13

Page 5: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 6: CPANci: Continuous Integration for CPAN

Stupid Question No. 2

Tuesday, June 4, 13

Page 7: CPANci: Continuous Integration for CPAN

What’s this about, anyway?

Tuesday, June 4, 13

Page 8: CPANci: Continuous Integration for CPAN

What’s this about, anyway?

CPANci

Tuesday, June 4, 13

Page 9: CPANci: Continuous Integration for CPAN

A Brief History

Tuesday, June 4, 13

Page 10: CPANci: Continuous Integration for CPAN

A Brief History

•December 18, 1987

Tuesday, June 4, 13

Page 11: CPANci: Continuous Integration for CPAN

A Brief History

•December 18, 1987•Perl 1.000 released.

Tuesday, June 4, 13

Page 12: CPANci: Continuous Integration for CPAN

A Brief History

•December 18, 1987•Perl 1.000 released.•TAP invented.

Tuesday, June 4, 13

Page 13: CPANci: Continuous Integration for CPAN

The Test Anything Protocol

Tuesday, June 4, 13

Page 14: CPANci: Continuous Integration for CPAN

The Test Anything Protocol

1..42ok 1 the thing looks good!ok 2ok 3 $beer isa $drinknot ok 4 too much $beernot ok 5 $me->vomit( 'now' )...

Tuesday, June 4, 13

Page 15: CPANci: Continuous Integration for CPAN

A Brief History

Tuesday, June 4, 13

Page 16: CPANci: Continuous Integration for CPAN

A Brief History

•October 17, 1994

Tuesday, June 4, 13

Page 17: CPANci: Continuous Integration for CPAN

A Brief History

•October 17, 1994•Perl 5.000 released.

Tuesday, June 4, 13

Page 18: CPANci: Continuous Integration for CPAN

A Brief History

•October 17, 1994•Perl 5.000 released.•Perl has a module system.

Tuesday, June 4, 13

Page 19: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 20: CPANci: Continuous Integration for CPAN

# from thisrequire "funcs.pl";

Tuesday, June 4, 13

Page 21: CPANci: Continuous Integration for CPAN

# from thisrequire "funcs.pl";

# to thisuse My::Module;

Tuesday, June 4, 13

Page 22: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 23: CPANci: Continuous Integration for CPAN

# but under the hoodBEGIN { require My::Module; My::Module->import;};

Tuesday, June 4, 13

Page 24: CPANci: Continuous Integration for CPAN

A Brief History

Tuesday, June 4, 13

Page 25: CPANci: Continuous Integration for CPAN

A Brief History

•October 26, 1995

Tuesday, June 4, 13

Page 26: CPANci: Continuous Integration for CPAN

A Brief History

•October 26, 1995•CPAN established.

Tuesday, June 4, 13

Page 27: CPANci: Continuous Integration for CPAN

A Brief History

•October 26, 1995•CPAN established.•Perl modules are available.

Tuesday, June 4, 13

Page 28: CPANci: Continuous Integration for CPAN

A Brief History

Tuesday, June 4, 13

Page 29: CPANci: Continuous Integration for CPAN

A Brief History

•May 15, 1997

Tuesday, June 4, 13

Page 30: CPANci: Continuous Integration for CPAN

A Brief History

•May 15, 1997•Perl 5.004 released.

Tuesday, June 4, 13

Page 31: CPANci: Continuous Integration for CPAN

A Brief History

•May 15, 1997•Perl 5.004 released.•CPAN.pm is in the core.

Tuesday, June 4, 13

Page 32: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 33: CPANci: Continuous Integration for CPAN

# the dark art$ perl -MCPAN -e 'install Foo'

Tuesday, June 4, 13

Page 34: CPANci: Continuous Integration for CPAN

A Brief History

Tuesday, June 4, 13

Page 35: CPANci: Continuous Integration for CPAN

A Brief History

•May, 1998

Tuesday, June 4, 13

Page 36: CPANci: Continuous Integration for CPAN

A Brief History

•May, 1998•CPAN Testers conceived

Tuesday, June 4, 13

Page 37: CPANci: Continuous Integration for CPAN

A Brief History

•May, 1998•CPAN Testers conceived•Automated feedback for authors

Tuesday, June 4, 13

Page 38: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 39: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 40: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 41: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 42: CPANci: Continuous Integration for CPAN

A Brief History

Tuesday, June 4, 13

Page 43: CPANci: Continuous Integration for CPAN

A Brief History

•November 15, 2003

Tuesday, June 4, 13

Page 44: CPANci: Continuous Integration for CPAN

A Brief History

•November 15, 2003•Perl 5.6.2 released.

Tuesday, June 4, 13

Page 45: CPANci: Continuous Integration for CPAN

A Brief History

•November 15, 2003•Perl 5.6.2 released.•Test::More is in the core.

Tuesday, June 4, 13

Page 46: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 47: CPANci: Continuous Integration for CPAN

use Test::More tests => 3;

ok( 42 );is( $foo, 'my value' );isnt( 'foo', 'bar' );

Tuesday, June 4, 13

Page 48: CPANci: Continuous Integration for CPAN

A Brief History

Tuesday, June 4, 13

Page 49: CPANci: Continuous Integration for CPAN

A Brief History

•August 6, 2012

Tuesday, June 4, 13

Page 50: CPANci: Continuous Integration for CPAN

A Brief History

•August 6, 2012•Mike goes to work for 10gen

Tuesday, June 4, 13

Page 51: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 52: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 53: CPANci: Continuous Integration for CPAN

WEB SCALE!!!!11Tuesday, June 4, 13

Page 54: CPANci: Continuous Integration for CPAN

WEB SCALE!!!!11

LOLTuesday, June 4, 13

Page 55: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 56: CPANci: Continuous Integration for CPAN

Bad Idea No. 1

Tuesday, June 4, 13

Page 57: CPANci: Continuous Integration for CPAN

Bad Idea No. 1Come up with a cool Perl MongoDB project

to show off at YAPC!

Tuesday, June 4, 13

Page 58: CPANci: Continuous Integration for CPAN

Bad Idea No. 1Come up with a cool Perl MongoDB project

to show off at YAPC!

It'll be fun!

Tuesday, June 4, 13

Page 59: CPANci: Continuous Integration for CPAN

Bad Idea No. 1Come up with a cool Perl MongoDB project

to show off at YAPC!

It'll be fun!promise!

Tuesday, June 4, 13

Page 60: CPANci: Continuous Integration for CPAN

CPAN Testers is Wonderful and Amazing

Tuesday, June 4, 13

Page 61: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 62: CPANci: Continuous Integration for CPAN

Disadvantages:

Tuesday, June 4, 13

Page 63: CPANci: Continuous Integration for CPAN

Disadvantages:Not real time

Tuesday, June 4, 13

Page 64: CPANci: Continuous Integration for CPAN

Disadvantages:Not real timeNot consistent

Tuesday, June 4, 13

Page 65: CPANci: Continuous Integration for CPAN

Disadvantages:Not real timeNot consistentPolluted / Inconsistent environments

Tuesday, June 4, 13

Page 66: CPANci: Continuous Integration for CPAN

Disadvantages:Not real timeNot consistentPolluted / Inconsistent environmentsNot all versions on all platforms

Tuesday, June 4, 13

Page 67: CPANci: Continuous Integration for CPAN

I want Continuous Integrationfor the entire CPAN.

Tuesday, June 4, 13

Page 68: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 69: CPANci: Continuous Integration for CPAN

Bad Idea No. 2

Tuesday, June 4, 13

Page 70: CPANci: Continuous Integration for CPAN

CPANci.org

Bad Idea No. 2

Tuesday, June 4, 13

Page 71: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 72: CPANci: Continuous Integration for CPAN

Stupid Question No. 3

Tuesday, June 4, 13

Page 73: CPANci: Continuous Integration for CPAN

Stupid Question No. 3How can we test CPAN without the

disadvantages of CPAN Testers?

Tuesday, June 4, 13

Page 74: CPANci: Continuous Integration for CPAN

Postulate:

Every CPAN distribution must be tested in isolation, on a virgin Perl installation untouched by human hands.

Tuesday, June 4, 13

Page 75: CPANci: Continuous Integration for CPAN

Postulate:

Every CPAN distribution must be tested in isolation, on a virgin Perl installation untouched by human hands.

So how do we do that?

Tuesday, June 4, 13

Page 76: CPANci: Continuous Integration for CPAN

perlbrew

Tuesday, June 4, 13

Page 77: CPANci: Continuous Integration for CPAN

Virtualization

Tuesday, June 4, 13

Page 78: CPANci: Continuous Integration for CPAN

Virtualization

Whoa!

Tuesday, June 4, 13

Page 79: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 80: CPANci: Continuous Integration for CPAN

Bad Idea No. 3

Tuesday, June 4, 13

Page 81: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 82: CPANci: Continuous Integration for CPAN

•Create an EC2 image

Tuesday, June 4, 13

Page 83: CPANci: Continuous Integration for CPAN

•Create an EC2 image•Put perlbrew on it

Tuesday, June 4, 13

Page 84: CPANci: Continuous Integration for CPAN

•Create an EC2 image•Put perlbrew on it•Install every Perl locally

Tuesday, June 4, 13

Page 85: CPANci: Continuous Integration for CPAN

•Create an EC2 image•Put perlbrew on it•Install every Perl locally•Boot an instance for every uploaded distribution

Tuesday, June 4, 13

Page 86: CPANci: Continuous Integration for CPAN

•Create an EC2 image•Put perlbrew on it•Install every Perl locally•Boot an instance for every uploaded distribution•Install needed dependencies for the distribution

Tuesday, June 4, 13

Page 87: CPANci: Continuous Integration for CPAN

•Create an EC2 image•Put perlbrew on it•Install every Perl locally•Boot an instance for every uploaded distribution•Install needed dependencies for the distribution•Run the tests and report the results

Tuesday, June 4, 13

Page 88: CPANci: Continuous Integration for CPAN

•Create an EC2 image•Put perlbrew on it•Install every Perl locally•Boot an instance for every uploaded distribution•Install needed dependencies for the distribution•Run the tests and report the results•Shut down the instance

Tuesday, June 4, 13

Page 89: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 90: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 91: CPANci: Continuous Integration for CPAN

Stupid Question No. 4

Tuesday, June 4, 13

Page 92: CPANci: Continuous Integration for CPAN

Stupid Question No. 4How can we do this on one instance?

Tuesday, June 4, 13

Page 93: CPANci: Continuous Integration for CPAN

local::lib

cpanminus

Tuesday, June 4, 13

Page 94: CPANci: Continuous Integration for CPAN

App::cpanminus

Tuesday, June 4, 13

Page 95: CPANci: Continuous Integration for CPAN

App::cpanminus

•Self-contained

Tuesday, June 4, 13

Page 96: CPANci: Continuous Integration for CPAN

App::cpanminus

•Self-contained•That is, the cpanm script is self-contained

Tuesday, June 4, 13

Page 97: CPANci: Continuous Integration for CPAN

App::cpanminus

•Self-contained•That is, the cpanm script is self-contained•via App::FatPacker

Tuesday, June 4, 13

Page 98: CPANci: Continuous Integration for CPAN

App::cpanminus

Tuesday, June 4, 13

Page 99: CPANci: Continuous Integration for CPAN

App::cpanminusThat means the same cpanm can be run by any perl

Tuesday, June 4, 13

Page 100: CPANci: Continuous Integration for CPAN

App::cpanminusThat means the same cpanm can be run by any perl

perlbrew switch mastercurl -L http://cpanmin.us/ | perl - App::cpanminusln -s ~/perl5/perlbrew/perls/master/bin/cpanm ./cpanm

~/perl5/perlbrew/perls/perl-5.8.9/bin/perl cpanm~/perl5/perlbrew/perls/perl-5.10.1/bin/perl cpanm~/perl5/perlbrew/perls/perl-5.12.5/bin/perl cpanm~/perl5/perlbrew/perls/perl-5.14.4/bin/perl cpanm~/perl5/perlbrew/perls/perl-5.16.3/bin/perl cpanm~/perl5/perlbrew/perls/perl-5.18.0/bin/perl cpanm~/perl5/perlbrew/perls/perl-5.19.0/bin/perl cpanm

Tuesday, June 4, 13

Page 101: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 102: CPANci: Continuous Integration for CPAN

•Use perlbrew to install a "master" perl

Tuesday, June 4, 13

Page 103: CPANci: Continuous Integration for CPAN

•Use perlbrew to install a "master" perl•Use it again to install "virgin" perls of every major version

Tuesday, June 4, 13

Page 104: CPANci: Continuous Integration for CPAN

•Use perlbrew to install a "master" perl•Use it again to install "virgin" perls of every major version•Use the master perl to install everything from CPAN that makes CPANci work

Tuesday, June 4, 13

Page 105: CPANci: Continuous Integration for CPAN

•Use perlbrew to install a "master" perl•Use it again to install "virgin" perls of every major version•Use the master perl to install everything from CPAN that makes CPANci work•For each distribution, create a temp directory

Tuesday, June 4, 13

Page 106: CPANci: Continuous Integration for CPAN

•Use perlbrew to install a "master" perl•Use it again to install "virgin" perls of every major version•Use the master perl to install everything from CPAN that makes CPANci work•For each distribution, create a temp directory•Tell cpanminus to install dependencies there, as if for local::lib

Tuesday, June 4, 13

Page 107: CPANci: Continuous Integration for CPAN

•Use perlbrew to install a "master" perl•Use it again to install "virgin" perls of every major version•Use the master perl to install everything from CPAN that makes CPANci work•For each distribution, create a temp directory•Tell cpanminus to install dependencies there, as if for local::lib•Run tests and report results

Tuesday, June 4, 13

Page 108: CPANci: Continuous Integration for CPAN

•Use perlbrew to install a "master" perl•Use it again to install "virgin" perls of every major version•Use the master perl to install everything from CPAN that makes CPANci work•For each distribution, create a temp directory•Tell cpanminus to install dependencies there, as if for local::lib•Run tests and report results•Delete temp directory, leaving each perl untouched!

Tuesday, June 4, 13

Page 109: CPANci: Continuous Integration for CPAN

What does that look like?

The "fetcher" grabs the latest distribution URLs from MetaCPAN's RSS feed.

Tuesday, June 4, 13

Page 110: CPANci: Continuous Integration for CPAN

What does that look like?

We retrieve the distribution metadata from the MetaCPAN JSON API and saved it to

MongoDB.

Then we start the Installer.

Tuesday, June 4, 13

Page 111: CPANci: Continuous Integration for CPAN

What does that look like?

We download the distribution tarball to a temp file.

Then the fun stuff starts to happen.

Tuesday, June 4, 13

Page 112: CPANci: Continuous Integration for CPAN

What does that look like?

We extract the archive in a specific "work" directoryfor each perl.

Then create a temp directory for building and installingdependencies.

Tuesday, June 4, 13

Page 113: CPANci: Continuous Integration for CPAN

What does that look like?

Use a specific perl binary to run cpanm and install dependencies, with no tests, to the temp

directory.

Then we parse the cpanm log on stderrTuesday, June 4, 13

Page 114: CPANci: Continuous Integration for CPAN

What does that look like? "deps" : { "log" : [ { "indent" : 0, "type" : "working-on", "line" : "--> Working on .\n" }, { "line" : "Configuring Lingua-EN-NamedEntity-1.92 ... OK\n", "type" : "config", "indent" : 1 }, { "type" : "found-deps", "indent" : 1, "line" : "==> Found dependencies: Lingua::Stem::En, DB_File, LWP::Simple\n" }, { "indent" : 1, "type" : "working-on", "line" : "--> Working on Lingua::Stem::En\n" }, { "indent" : 2, "type" : "fetch", "line" : "Fetching http://www.cpan.org/authors/id/S/SN/SNOWHARE/Lingua-Stem-0.84.tar.gz ... OK\n" },

Tuesday, June 4, 13

Page 115: CPANci: Continuous Integration for CPAN

What does that look like?

Use a specific perl to run each test file,save the TAP output and any errors, and

use the exit status to determine if it passed.

Tuesday, June 4, 13

Page 116: CPANci: Continuous Integration for CPAN

What does that look like?

Parse the TAP output of each test into a structure which can be saved in MongoDB

Tuesday, June 4, 13

Page 117: CPANci: Continuous Integration for CPAN

What does that look like? "name" : "t/05depth.t", "lines" : [ { "ok" : true, "text" : "1..12", "type" : "plan" }, { "number" : 1, "ok" : true, "type" : "test", "desc" : "new object", "text" : "ok 1 - new object" }, { "ok" : true, "number" : 2, "desc" : "depth", "type" : "test", "text" : "ok 2 - depth" }, { "desc" : "depth", "text" : "ok 3 - depth", "type" : "test", "number" : 3, "ok" : true }, { "type" : "test", "desc" : "depth", "text" : "ok 4 - depth", "ok" : true, "number" : 4 }, { "number" : 5, "ok" : true, "text" : "ok 5 - depth", "desc" : "depth", "type" : "test" }, { "number" : 6, "ok" : true, "type" : "test", "desc" : "depth", "text" : "ok 6 - depth" },

Tuesday, June 4, 13

Page 118: CPANci: Continuous Integration for CPAN

What does that look like? "name" : "t/05depth.t", "lines" : [ { "ok" : true, "text" : "1..12", "type" : "plan" }, { "number" : 1, "ok" : true, "type" : "test", "desc" : "new object", "text" : "ok 1 - new object" }, { "ok" : true, "number" : 2, "desc" : "depth", "type" : "test", "text" : "ok 2 - depth" }, { "desc" : "depth", "text" : "ok 3 - depth", "type" : "test", "number" : 3, "ok" : true }, { "type" : "test", "desc" : "depth", "text" : "ok 4 - depth", "ok" : true, "number" : 4 }, { "number" : 5, "ok" : true, "text" : "ok 5 - depth", "desc" : "depth", "type" : "test" }, { "number" : 6, "ok" : true, "type" : "test", "desc" : "depth", "text" : "ok 6 - depth" },

•This is JSON

Tuesday, June 4, 13

Page 119: CPANci: Continuous Integration for CPAN

What does that look like? "name" : "t/05depth.t", "lines" : [ { "ok" : true, "text" : "1..12", "type" : "plan" }, { "number" : 1, "ok" : true, "type" : "test", "desc" : "new object", "text" : "ok 1 - new object" }, { "ok" : true, "number" : 2, "desc" : "depth", "type" : "test", "text" : "ok 2 - depth" }, { "desc" : "depth", "text" : "ok 3 - depth", "type" : "test", "number" : 3, "ok" : true }, { "type" : "test", "desc" : "depth", "text" : "ok 4 - depth", "ok" : true, "number" : 4 }, { "number" : 5, "ok" : true, "text" : "ok 5 - depth", "desc" : "depth", "type" : "test" }, { "number" : 6, "ok" : true, "type" : "test", "desc" : "depth", "text" : "ok 6 - depth" },

•This is JSON•Stored in MongoDB

Tuesday, June 4, 13

Page 120: CPANci: Continuous Integration for CPAN

What does that look like? "name" : "t/05depth.t", "lines" : [ { "ok" : true, "text" : "1..12", "type" : "plan" }, { "number" : 1, "ok" : true, "type" : "test", "desc" : "new object", "text" : "ok 1 - new object" }, { "ok" : true, "number" : 2, "desc" : "depth", "type" : "test", "text" : "ok 2 - depth" }, { "desc" : "depth", "text" : "ok 3 - depth", "type" : "test", "number" : 3, "ok" : true }, { "type" : "test", "desc" : "depth", "text" : "ok 4 - depth", "ok" : true, "number" : 4 }, { "number" : 5, "ok" : true, "text" : "ok 5 - depth", "desc" : "depth", "type" : "test" }, { "number" : 6, "ok" : true, "type" : "test", "desc" : "depth", "text" : "ok 6 - depth" },

•This is JSON•Stored in MongoDB•But it's also TAP!

Tuesday, June 4, 13

Page 121: CPANci: Continuous Integration for CPAN

Tuesday, June 4, 13

Page 122: CPANci: Continuous Integration for CPAN

Bad Idea No. 4

Tuesday, June 4, 13

Page 123: CPANci: Continuous Integration for CPAN

Bad Idea No. 4

LIVE DEMO!Tuesday, June 4, 13

Page 124: CPANci: Continuous Integration for CPAN

The future?

Tuesday, June 4, 13

Page 125: CPANci: Continuous Integration for CPAN

The future?•Integration with Pinto

Tuesday, June 4, 13

Page 126: CPANci: Continuous Integration for CPAN

The future?•Integration with Pinto•Integration with Stratopan

Tuesday, June 4, 13

Page 127: CPANci: Continuous Integration for CPAN

The future?•Integration with Pinto•Integration with Stratopan•All kinds of cool statistics on the website

Tuesday, June 4, 13

Page 128: CPANci: Continuous Integration for CPAN

The future?•Integration with Pinto•Integration with Stratopan•All kinds of cool statistics on the website•Organizations using CPANci for their internal DarkPANs

Tuesday, June 4, 13

Page 129: CPANci: Continuous Integration for CPAN

Final Thoughts

Tuesday, June 4, 13

Page 130: CPANci: Continuous Integration for CPAN

Final Thoughts

•Play with new toys.

Tuesday, June 4, 13

Page 131: CPANci: Continuous Integration for CPAN

Final Thoughts

•Play with new toys.•Think before you code.

Tuesday, June 4, 13

Page 132: CPANci: Continuous Integration for CPAN

Final Thoughts

•Play with new toys.•Think before you code.•Have bad ideas.

Tuesday, June 4, 13

Page 133: CPANci: Continuous Integration for CPAN

Final Thoughts

•Play with new toys.•Think before you code.•Have bad ideas.•Ask stupid questions.

Tuesday, June 4, 13

Page 134: CPANci: Continuous Integration for CPAN

Final Thoughts

•Play with new toys.•Think before you code.•Have bad ideas.•Ask stupid questions.•Have fun.

Tuesday, June 4, 13

Page 135: CPANci: Continuous Integration for CPAN

Stupid Questions?

Mike Friedman(friedo)

[email protected]://github.com/friedo/cpanci

Tuesday, June 4, 13