diff options
| author | Ailin Nemui | 2014-06-16 04:11:29 +0200 | 
|---|---|---|
| committer | Ailin Nemui | 2014-06-24 18:28:59 +0200 | 
| commit | ca374a4a1acec99b19486549071ef6c9968b749a (patch) | |
| tree | ec4f7f7e66b423c392b5dbb46e424ec56a43247c /_testing/travis | |
| parent | 525b2128888f1e3ca2088a54cc086b102dbfe690 (diff) | |
| download | scripts.irssi.org-ca374a4a1acec99b19486549071ef6c9968b749a.tar.bz2 | |
Add travis testing to Irssi scripts.
Diffstat (limited to '_testing/travis')
| -rw-r--r-- | _testing/travis/_get_files_arr.zsh | 38 | ||||
| -rwxr-xr-x | _testing/travis/autoinstall-perl-prereqs.zsh | 48 | ||||
| -rwxr-xr-x | _testing/travis/extract-artefacts.zsh | 40 | ||||
| -rwxr-xr-x | _testing/travis/load-old-artefacts.zsh | 12 | ||||
| -rwxr-xr-x | _testing/travis/show-failures.zsh | 37 | ||||
| -rw-r--r-- | _testing/travis/update-scripts-yaml.pl | 100 | 
6 files changed, 275 insertions, 0 deletions
| diff --git a/_testing/travis/_get_files_arr.zsh b/_testing/travis/_get_files_arr.zsh new file mode 100644 index 0000000..9fb6324 --- /dev/null +++ b/_testing/travis/_get_files_arr.zsh @@ -0,0 +1,38 @@ +filelist=(scripts/*.pl) +if [[ $TRAVIS_PULL_REQUEST != false ]] { +    local -a scriptfiles +    OIFS=$IFS; IFS=$'\n' +    scriptfiles=($(git diff --numstat $TRAVIS_BRANCH|cut -f3|grep '^scripts/.*\.pl')) +    IFS=$OIFS +    if [[ $#scriptfiles -gt 0 ]] { +	filelist=($scriptfiles) +    } +} \ +elif [[ $USE_ARTEFACTS_CACHE = yes ]] { +    local -a cache_allowed +    OIFS=$IFS; IFS=$'\n' +    cache_allowed=(scripts/${^$(grep -v __ARTEFACTS_CI__ old-artefacts/can-use-cache | cut -f2- -d\  )}) +    IFS=$OIFS + +    if [[ $REPORT_STAGE == yes ]] { +        autoload -Uz zargs +        { zargs -r -- old-artefacts/Test/${^cache_allowed:t:r} -- mv -nt Test } 2>/dev/null +        cached_run=($cache_allowed) +    } \ +    else { +        autoload -Uz is-at-least +        if { is-at-least 5.0.0 } { +            filelist=(${filelist:|cache_allowed}) +        } \ +        else { +	    # manually filter the array in zsh4 +            local -a scriptfiles +            for x ($filelist) { +                if [[ $+cache_allowed[(r)$x] -eq 0 ]] { +                    scriptfiles+=($x) +                } +            } +            filelist=($scriptfiles) +        } +    } +} diff --git a/_testing/travis/autoinstall-perl-prereqs.zsh b/_testing/travis/autoinstall-perl-prereqs.zsh new file mode 100755 index 0000000..11c9824 --- /dev/null +++ b/_testing/travis/autoinstall-perl-prereqs.zsh @@ -0,0 +1,48 @@ +#!/bin/zsh + +. ./_testing/_get_files_arr.zsh + +local -a modlist +modlist=($(scan-perl-prereqs $filelist)) + +sudo apt-file update >/dev/null 2>&1 + +local -a ubu_pkgs +local -a cpan_mods +for mod ($modlist) { +    mod=${mod%\~*} +    if [[ $mod != Irssi* && $mod != feature ]] { +        if { ! perl -M$mod -E1 2>/dev/null } { +            local -a ubu_pkg +            ubu_pkg=($(apt-file -l search "/perl5/${mod//:://}.pm")) +            if [[ $#ubu_pkg -gt 0 ]] { ubu_pkgs+=($ubu_pkg) } \ +            else { cpan_mods+=($mod) } +        } +    } +} + +if [[ $#ubu_pkgs -gt 0 ]] { sudo apt-get install -qq $ubu_pkgs } + +typeset -A broken_tests +typeset -A broken_mods + +broken_tests=($(perl -MYAML::Tiny=LoadFile -e'print "$_ 1 " for @{LoadFile(+shift)->{cpan}{broken_tests}}' _testing/config.yml)) +broken_mods=($(perl -MYAML::Tiny=LoadFile -e'print "$_ 1 " for @{LoadFile(+shift)->{cpan}{broken_modules}}' _testing/config.yml)) + +for mod ($cpan_mods) { +    if { ! perl -M$mod -E1 2>/dev/null } { +        local skip_test= +        if [[ -n $broken_tests[$mod] ]] { +            skip_test=--notest +            echo Skipping broken test on $mod +        } +        if [[ -n $broken_mods[$mod] ]] { +            echo SKIPPING AUTOINSTALL OF BROKEN MODULE $mod +        } \ +        else { +            echo Auto-installing $mod +            sudo cpanm -q --skip-satisfied $skip_test $mod +        } +    } +} +exit 0 diff --git a/_testing/travis/extract-artefacts.zsh b/_testing/travis/extract-artefacts.zsh new file mode 100755 index 0000000..f383536 --- /dev/null +++ b/_testing/travis/extract-artefacts.zsh @@ -0,0 +1,40 @@ +#!/bin/zsh +if [[ -z $REPO_LOGIN_TOKEN || -z $TRAVIS_REPO_SLUG ]] { exit 1 } +autoload -Uz zargs + +if { ! git clone -b ci-artefacts https://github.com/$TRAVIS_REPO_SLUG artefacts } { +    mkdir artefacts && git init artefacts +    pushd artefacts +    git remote add origin https://github.com/$TRAVIS_REPO_SLUG +    git checkout -b ci-artefacts +    popd +} + +pushd artefacts +git config user.email "scripts@irssi.org" +git config user.name "Irssi Scripts Helper" +git config credential.helper store + +git rm -qrf . + +echo "This branch stores the travis-ci results for $TRAVIS_REPO_SLUG +See [the testing read-me](../gh-pages/_testing/) for details." > README.markdown +pushd .. +MARKDOWN_REPORT=1 ./_testing/report-test.zsh >> artefacts/README.markdown +popd +echo >> README.markdown +echo "$TRAVIS_COMMIT | $TRAVIS_BUILD_NUMBER" >> README.markdown + +mv ../Test . +rm -fr Test/.home +zargs -r -- Test/*/passed(N) -- rm +if [[ $USE_ARTEFACTS_CACHE == yes ]] { +    mv ../old-artefacts/new-changed-info changed-info +} + +git add . +git commit -q -m "ci artefacts for $TRAVIS_COMMIT + +[skip ci]" + +git push -u origin ci-artefacts diff --git a/_testing/travis/load-old-artefacts.zsh b/_testing/travis/load-old-artefacts.zsh new file mode 100755 index 0000000..f28e38f --- /dev/null +++ b/_testing/travis/load-old-artefacts.zsh @@ -0,0 +1,12 @@ +#!/bin/zsh +if { ! git clone -q --depth 1 -b ci-artefacts git://github.com/$TRAVIS_REPO_SLUG.git old-artefacts } { +   mkdir old-artefacts +} +echo $(git log --format=%H -1 _testing .travis.yml) __ARTEFACTS_CI__>old-artefacts/new-changed-info +for f (scripts/*.pl) { +    echo $(git hash-object $f) ${f:t} >>old-artefacts/new-changed-info +} +grep -sxFf old-artefacts/new-changed-info old-artefacts/changed-info >old-artefacts/can-use-cache +if { ! grep -q __ARTEFACTS_CI__ old-artefacts/can-use-cache } { +    :>|old-artefacts/can-use-cache +} diff --git a/_testing/travis/show-failures.zsh b/_testing/travis/show-failures.zsh new file mode 100755 index 0000000..1ce6229 --- /dev/null +++ b/_testing/travis/show-failures.zsh @@ -0,0 +1,37 @@ +#!/bin/zsh + +. ./_testing/_get_files_arr.zsh + +if [[ $TRAVIS_PULL_REQUEST != false ]] { +    echo '======== INTEGRATION REPORT =========' +    for scriptfile ($filelist) { +        echo '--- '$scriptfile:t +        if [[ -f "Test/${scriptfile:t:r}/failed.yml" ]] { +	    echo "FATAL: SCRIPT FAILED TO LOAD	" +	} +        cat "Test/${scriptfile:t:r}/stderr.log" 2>/dev/null +        cat "Test/${scriptfile:t:r}/irssi.log" +	echo +	echo 'Source code critic:' +	cat "Test/${scriptfile:t:r}/perlcritic.log" +	echo +    } +    echo +    echo '======== YAML DATABASE ========' +    for scriptfile ($filelist) { +        if [[ ! -f "Test/${scriptfile:t:r}/failed.yml" ]] { +	    cat "Test/${scriptfile:t:r}/info.yml" +	} +    } +} \ +else { +    echo '============= DETAILED FAILURE REPORTS =============' +    for scriptfile ($filelist) { +        if [[ -f "Test/${scriptfile:t:r}/failed.yml" ]] { +           echo '--- '$scriptfile:t +           cat "Test/${scriptfile:t:r}/stderr.log" 2>/dev/null +           cat "Test/${scriptfile:t:r}/irssi.log" +           echo +        } +    } +} diff --git a/_testing/travis/update-scripts-yaml.pl b/_testing/travis/update-scripts-yaml.pl new file mode 100644 index 0000000..d3384a8 --- /dev/null +++ b/_testing/travis/update-scripts-yaml.pl @@ -0,0 +1,100 @@ +use strict; use warnings; +use YAML::Tiny; + +my @docs; +{ open my $ef, '<:utf8', '_data/scripts.yaml' or die $!; +  @docs = Load(do { local $/; <$ef> }); +} + +my %oldmeta; +for (@{$docs[0]//[]}) { +    $oldmeta{$_->{filename}} = $_; +} + +my %newmeta; +for my $file (<scripts/*.pl>) { +    my ($filename, $base) = +	$file =~ m,^scripts/((.*)\.pl)$,; +    my $info_file = "Test/$base/info.yml"; +    my @cdoc; +    if (-f $info_file && open my $ef, '<:utf8', $info_file) { +	local $@; +	@cdoc = eval { Load(do { local $/; <$ef> }); }; +	if ($@) { +	    print "ERROR $base: $@\n"; +	    @cdoc=(); +	} +    } +    if (@cdoc) { +	$newmeta{$filename} = $cdoc[0][0]; +	for my $copykey (qw(modified version)) { +	    unless (defined $newmeta{$filename}{$copykey}) { +		$newmeta{$filename}{$copykey} +		    = $oldmeta{$filename}{$copykey} +			if defined $oldmeta{$filename}{$copykey}; +	    } +	} +	$newmeta{$filename}{filename} = $filename; +	my $modules = delete $newmeta{$filename}{modules}; +	$newmeta{$filename}{modules} +	    = join ' ', @$modules +		if 'ARRAY' eq ref $modules; +    } +    elsif (exists $oldmeta{$filename}) { +	print "META-INF FOR $base NOT FOUND\n"; +	system "ls 'Test/$base/'*"; +	$newmeta{$filename} = $oldmeta{$filename}; +    } +    else { +	print "MISSING META FOR $base\n"; +    } +} +my @newdoc = map { $newmeta{$_} } sort keys %newmeta; +{ open my $ef, '>:utf8', '_data/scripts.yaml' or die $!; +  print $ef Dump \@newdoc; +} + +my @config; +if (open my $ef, '<:utf8', '_testing/config.yml') { +    @config = Load(do { local $/; <$ef> }); +} +if (@config && @{$config[0]{whitelist}//[]}) { +    my $changed; +    my @wl; +    for my $sf (@{$config[0]{whitelist}}) { +	if (-s "Test/$sf:passed") { +	    $changed = 1; +	} +	else { +	    push @wl, $sf; +	} +    } +    if ($changed) { +	$config[0]{whitelist} = \@wl; +	{ open my $ef, '>:utf8', '_testing/config.yml' or die $!; +	  print $ef Dump @config; +        } +    } +} + +if (exists $ENV{REPO_LOGIN_TOKEN} && exists $ENV{TRAVIS_REPO_SLUG}) { +    { open my $cred, '>', "$ENV{HOME}/.git-credentials" or die $!; +      print $cred "https://$ENV{REPO_LOGIN_TOKEN}:x-oauth-basic\@github.com\n"; +    } +    system qq[ +git config user.email "scripts\@irssi.org" +git config user.name "Irssi Scripts Helper" +git config credential.helper store +git config remote.origin.url https://github.com/$ENV{TRAVIS_REPO_SLUG} +git checkout '$ENV{TRAVIS_BRANCH}' +if [ "\$(git log -1 --format=%an)" != "\$(git config user.name)" -a \\ +     "\$(git log -1 --format=%cn)" != "\$(git config user.name)" ]; then +    git add _data/scripts.yaml +    git commit -m 'automatic scripts database update for $ENV{TRAVIS_COMMIT} + +[skip ci]' +    git config push.default simple +    git push origin +fi +]; +} | 
