From: Ailin Nemui Date: Mon, 25 Jan 2021 18:42:25 +0000 (+0100) Subject: add github workflow test X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=59c3d706264d1a480fd23ddb038b97d8a8a8ce8f;p=irssi-scripts.irssi.org.git add github workflow test --- diff --git a/.github/actions.yml b/.github/actions.yml deleted file mode 100644 index cb88d59..0000000 --- a/.github/actions.yml +++ /dev/null @@ -1,52 +0,0 @@ -addons: - apt: - packages: - # irssi build dependencies - - elinks - # script test dependencies - - zsh - # script dependencies - - libdb-dev - - libaspell-dev - - libgirepository1.0-dev - - gobject-introspection - - gir1.2-notify-0.7 # for desktop-notify - - xosd-bin # for osd -before_install: - - wget -nv https://download.opensuse.org/repositories/home:ailin_nemui:irssi-git/Debian_9.0/Release.key -O- | apt-key add - - - echo 'deb http://download.opensuse.org/repositories/home:/ailin_nemui:/irssi-git/Debian_9.0/ /' > /etc/apt/sources.list.d/irssi_obs.list - - apt-get update -q && apt-get install -y irssi-git -install: - - | - if [ "${USE_ARTEFACTS_CACHE:-no}" = yes ] && [ "${EXTRACT_TEST_ARTEFACTS:-no}" = yes ]; then - ./_testing/github/load-old-artefacts.zsh - fi - - ./_testing/autoinstall-perl-prereqs.zsh - - cpanm --quiet --installdeps --notest ./auto -before_script: - - ./_testing/run-test.zsh - - | - if [ "${GITHUB_REF:-}" != refs/heads/master ]; then - git diff --stat origin/master - fi -script: - - ./_testing/report-test.zsh || rc=$? - - echo ${rc:-0} > $HOME/script-rc -after_script: - - ./_testing/github/show-failures.zsh - - | - if [ "${GITHUB_REF:-}" = refs/heads/master ] && [ -n "${GITHUB_TOKEN:-}" ]; then - perl ./_testing/update-scripts-yaml.pl - ./_testing/github/commit-scripts-yaml.zsh - fi - - | - if [ "${GITHUB_REF:-}" = refs/heads/master ] && [ -n "${GITHUB_TOKEN:-}" ] && [ "${EXTRACT_TEST_ARTEFACTS:-no}" = yes ]; then - ./_testing/github/extract-artefacts.zsh - fi - - cat /github/home/.git-credential-helper -script_result: - - (exit "$(cat $HOME/script-rc)") -global_env: - - export LANG=C.UTF-8 - - export USE_ARTEFACTS_CACHE=yes - - export EXTRACT_TEST_ARTEFACTS=yes diff --git a/.github/main.workflow b/.github/main.workflow deleted file mode 100644 index 0001264..0000000 --- a/.github/main.workflow +++ /dev/null @@ -1,62 +0,0 @@ -# workflow "Check Scripts(M)" { -# on = "push" -# resolves = ["update-scripts"] -# } - -# workflow "Check Scripts" { -# on = "push" -# resolves = ["result"] -# } - -action "On Master Branch" { - uses = "actions/bin/filter@master" - args = "branch master" -} - -action "On Pull Request" { - uses = "actions/bin/filter@master" - args = "not branch master" -} - -action "run-test(m)" { - uses = "irssi-import/actions-irssi/check-irssi-scripts@master" - needs = ["On Master Branch"] - args = "before_install global_env install before_script" -} - -action "run-test" { - uses = "irssi-import/actions-irssi/check-irssi-scripts@master" - needs = ["On Pull Request"] - args = "before_install global_env install before_script" -} - -action "report-test" { - uses = "irssi-import/actions-irssi/check-irssi-scripts@master" - needs = ["run-test"] - args = "global_env script" -} - -action "report-test(m)" { - uses = "irssi-import/actions-irssi/check-irssi-scripts@master" - needs = ["run-test(m)"] - args = "global_env script" -} - -action "update-scripts" { - uses = "irssi-import/actions-irssi/check-irssi-scripts@master" - needs = ["report-test(m)"] - args = "global_env after_script" - secrets = ["GITHUB_TOKEN"] -} - -action "show-failures" { - uses = "irssi-import/actions-irssi/check-irssi-scripts@master" - needs = ["report-test"] - args = "global_env after_script" -} - -action "result" { - uses = "irssi-import/actions-irssi/check-irssi-scripts@master" - needs = ["show-failures"] - args = "global_env script_result" -} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4de60a0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,96 @@ +on: + push: + branches: + - master + pull_request: +name: Check Script +env: + apt_build_deps: irssi-git cpanminus elinks zsh + apt_script_deps: libdb-dev libaspell-dev libgirepository1.0-dev gobject-introspection gir1.2-notify-0.7 xosd-bin wbritish + USE_ARTEFACTS_CACHE: yes + EXTRACT_TEST_ARTEFACTS: yes + PERL_MM_NONINTERACTIVE: 1 +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + - uses: mstachniuk/ci-skip@v1 + with: + fail-fast: true + - name: prepare required software + run: | + RELEASE=$(lsb_release -rs) + echo "deb http://download.opensuse.org/repositories/home:/ailin_nemui:/irssi-git/xUbuntu_$RELEASE/ /" | sudo tee /etc/apt/sources.list.d/home:ailin_nemui:irssi-git.list + curl -fsSL https://download.opensuse.org/repositories/home:ailin_nemui:irssi-git/xUbuntu_$RELEASE/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_ailin_nemui_irssi-git.gpg > /dev/null + sudo apt -q update + sudo apt -q install $apt_build_deps $apt_script_deps + - name: cache cpan + uses: actions/cache@v2 + with: + path: | + ~/extlib + key: ${{ runner.os }}-cpan-${{ github.sha }}-${{ github.run_number }} + restore-keys: | + ${{ runner.os }}-cpan-${{ github.sha }}- + ${{ runner.os }}-cpan- + - name: fetch origin master branch + if: ${{ github.event_name == 'pull_request' }} + run: | + git fetch --depth=1 origin refs/heads/master + - name: configure local::lib + run: | + eval $(perl -Mlocal::lib="$HOME"/extlib) + for v in PATH PERL5LIB PERL_LOCAL_LIB_ROOT PERL_MB_OPT PERL_MM_OPT; do + eval echo "\$v=\$$v" >> $GITHUB_ENV + done + - name: fix the broken Encode module + run: | + cpanm Encode + - name: load old artefacts + if: ${{ env.USE_ARTEFACTS_CACHE == 'yes' }} + run: + ./_testing/github/load-old-artefacts.zsh + - name: install cpan dependencies + run: | + cpanm --installdeps --notest . + ./_testing/autoinstall-perl-prereqs.zsh + - name: auto-install cpan script dependencies + run: | + pushd auto + cpanm --quiet --installdeps --notest . + popd + - name: run tests + run: | + ./_testing/run-test.zsh + - name: show diffstat + if: ${{ github.event_name == 'pull_request' }} + run: | + git diff --stat origin/master + - name: test report + run: | + ./_testing/report-test.zsh || rc=$? + echo "SCRIPT_RC=${rc:-0}" >> $GITHUB_ENV + - name: integration report + run: | + ./_testing/github/show-failures.zsh + - name: update scripts.yaml + if: ${{ github.event_name == 'push' }} + run: | + perl ./_testing/update-scripts-yaml.pl + - name: commit scripts.yaml + if: ${{ github.event_name == 'push' }} + run: | + ./_testing/github/commit-scripts-yaml.zsh + - uses: actions/checkout@main + if: ${{ github.event_name == 'push' && env.EXTRACT_TEST_ARTEFACTS == 'yes' }} + with: + ref: ci-artefacts + path: artefacts + - name: extract artefacts + if: ${{ github.event_name == 'push' && env.EXTRACT_TEST_ARTEFACTS == 'yes' }} + run: | + ./_testing/github/extract-artefacts.zsh + - name: end + run: | + exit $SCRIPT_RC diff --git a/_testing/_irssi_test.pl b/_testing/_irssi_test.pl index 572d270..c29cb7c 100644 --- a/_testing/_irssi_test.pl +++ b/_testing/_irssi_test.pl @@ -3,8 +3,8 @@ use warnings; BEGIN { *CORE::GLOBAL::exit = sub (;$) { - require Carp; - Carp::croak("script tried to call exit @_"); + require Carp; + Carp::croak("script tried to call exit @_"); }; } @@ -30,6 +30,7 @@ $Carp::MaxEvalLen = 3; require YAML::Tiny; YAML::Tiny->VERSION("1.59"); require Encode; +die "Broken Encode version (2.88)" if $Encode::VERSION eq '2.88'; { # This is an ugly hack to be `lax' about the encoding. We try to # read everything as UTF-8 regardless of declared file encoding @@ -37,11 +38,11 @@ require Encode; my $orig = YAML::Tiny->can("_has_internal_string_value") || die("Error in ".__PACKAGE__); no warnings 'redefine'; *YAML::Tiny::_has_internal_string_value = sub { - my $ret = $orig->(@_); - use bytes; - $_[0] = Encode::decode_utf8($_[0], sub{pack 'U', +shift}) - unless Encode::is_utf8($_[0]); - $ret + my $ret = $orig->(@_); + use bytes; + $_[0] = Encode::decode_utf8($_[0], sub{pack 'U', +shift}) + unless Encode::is_utf8($_[0]); + $ret } } require Module::CoreList; @@ -50,8 +51,8 @@ require Perl::PrereqScanner; my $prereq_results = Perl::PrereqScanner->new->scan_file("$SWD/scripts/$CURRENT_SCRIPT.pl"); my @modules = grep { $_ ne 'perl' && - $_ ne 'Irssi' && $_ ne 'Irssi::UI' && $_ ne 'Irssi::TextUI' && $_ ne 'Irssi::Irc' - && !Module::CoreList->first_release($_) + $_ ne 'Irssi' && $_ ne 'Irssi::UI' && $_ ne 'Irssi::TextUI' && $_ ne 'Irssi::Irc' + && !Module::CoreList->first_release($_) } sort keys %{ $prereq_results->as_string_hash }; my (%info, $version, @commands); diff --git a/_testing/config.yml b/_testing/config.yml index e8b9ee0..a91d4d4 100644 --- a/_testing/config.yml +++ b/_testing/config.yml @@ -34,6 +34,7 @@ whitelist: - idonkey - ircgallery - isdn + - iMPD - ixmmsa - l33tmusic - log2ansi diff --git a/_testing/github/_get_files_arr.zsh b/_testing/github/_get_files_arr.zsh index 384a952..03b3974 100644 --- a/_testing/github/_get_files_arr.zsh +++ b/_testing/github/_get_files_arr.zsh @@ -5,7 +5,7 @@ if [[ $GITHUB_REF != refs/heads/master ]] { scriptfiles=($(git diff --numstat --no-renames origin/master|cut -f3|grep '^scripts/.*\.pl')) IFS=$OIFS if [[ $#scriptfiles -gt 0 ]] { - filelist=($scriptfiles) + filelist=($scriptfiles) } } \ elif [[ $USE_ARTEFACTS_CACHE = yes ]] { diff --git a/_testing/github/commit-scripts-yaml.zsh b/_testing/github/commit-scripts-yaml.zsh index 947655e..3e9791f 100755 --- a/_testing/github/commit-scripts-yaml.zsh +++ b/_testing/github/commit-scripts-yaml.zsh @@ -1,6 +1,6 @@ #!/bin/zsh -[[ -z $GITHUB_TOKEN ]] && exit +[[ -z $GITHUB_ACTION ]] && exit git config user.email "scripts@irssi.org" git config user.name "Irssi Scripts Helper" @@ -12,7 +12,7 @@ if [[ "$(git log -1 --format=%an)" != "$(git config user.name)" && git add _data/scripts.yaml git commit -m "automatic scripts database update for $GITHUB_SHA -[skip ci]" +[ci skip]" git config push.default simple git push --set-upstream origin master } diff --git a/_testing/github/extract-artefacts.zsh b/_testing/github/extract-artefacts.zsh index f43f32e..be4bf55 100755 --- a/_testing/github/extract-artefacts.zsh +++ b/_testing/github/extract-artefacts.zsh @@ -1,15 +1,7 @@ #!/bin/zsh -if [[ -z $GITHUB_TOKEN || -z $GITHUB_REPOSITORY ]] { exit 1 } +if [[ -z $GITHUB_REPOSITORY ]] { exit 1 } autoload -Uz zargs -if { ! git clone -b ci-artefacts https://github.com/${GITHUB_REPOSITORY}.git artefacts } { - mkdir artefacts && git init artefacts - pushd artefacts - git remote add origin https://github.com/${GITHUB_REPOSITORY}.git - git checkout -b ci-artefacts - popd -} - pushd artefacts git config user.email "scripts@irssi.org" git config user.name "Irssi Scripts Helper" @@ -34,6 +26,6 @@ if [[ $USE_ARTEFACTS_CACHE == yes ]] { git add . git commit -q -m "ci artefacts for $GITHUB_SHA -[skip ci]" +[ci skip]" git push -u origin ci-artefacts diff --git a/_testing/github/show-failures.zsh b/_testing/github/show-failures.zsh index 95670fc..50ef4ea 100755 --- a/_testing/github/show-failures.zsh +++ b/_testing/github/show-failures.zsh @@ -7,21 +7,21 @@ if [[ $GITHUB_REF != refs/heads/master ]] { for scriptfile ($filelist) { echo '--- '$scriptfile:t if [[ -f "Test/${scriptfile:t:r}/failed.yml" ]] { - echo "FATAL: SCRIPT FAILED TO LOAD " - } + 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 '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" - } + cat "Test/${scriptfile:t:r}/info.yml" + } } } \ else { diff --git a/_testing/report-test.zsh b/_testing/report-test.zsh index 130374e..37a49c6 100755 --- a/_testing/report-test.zsh +++ b/_testing/report-test.zsh @@ -60,17 +60,17 @@ for scriptfile ($filelist) { perl -ne '$score += $1 -1 if /Severity: (\d+)/; END { printf "%3d", $score }' "Test/${scriptfile:t:r}/perlcritic.log" 2>/dev/null print -n ' '$T if [[ $pass -lt 3 ]] { - if [[ -n $allow_fail[$scriptfile:t:r] ]] || [[ ! -f scripts/${scriptfile:t:r}.pl ]] { - print -n ' '$skipmark' ' - } \ - else { - print -n ' '$failmark' ' - if [[ $failed -lt 254 ]] { ((++failed)) } - } + if [[ -n $allow_fail[$scriptfile:t:r] ]] || [[ ! -f scripts/${scriptfile:t:r}.pl ]] { + print -n ' '$skipmark' ' + } \ + else { + print -n ' '$failmark' ' + if [[ $failed -lt 254 ]] { ((++failed)) } + } } \ else { - print -n ' '$passmark' '; ((++pass)) - echo 1>"Test/${scriptfile:t:r}/passed" + print -n ' '$passmark' '; ((++pass)) + echo 1>"Test/${scriptfile:t:r}/passed" } if [[ $+cached_run[(r)$scriptfile] -gt 0 ]] { print -n $T' (c)' diff --git a/_testing/run-test.zsh b/_testing/run-test.zsh index 6191d12..6b8d40b 100755 --- a/_testing/run-test.zsh +++ b/_testing/run-test.zsh @@ -2,14 +2,19 @@ local base_path="`pwd`" local test_script="$base_path/_testing/_irssi_test.pl" +if [[ $(perl -MEncode -e'print $Encode::VERSION') == 2.88 ]] { + echo "Broken Encode version (2.88). Please update the Perl Encode module." + exit 4 +} + . ./_testing/_get_files_arr.zsh for scriptfile ($filelist) { rm -rf "Test/${scriptfile:t:r}" mkdir -p "Test/${scriptfile:t:r}" if [[ ! -f scripts/${scriptfile:t:r}.pl ]] { - {echo "command not found: script ${scriptfile:t:r}";echo "test skipped"} >"Test/${scriptfile:t:r}/perlcritic.log" - continue + {echo "command not found: script ${scriptfile:t:r}";echo "test skipped"} >"Test/${scriptfile:t:r}/perlcritic.log" + continue } perlcritic --theme certrule --exclude RequireEndWithOne -2 scripts/${scriptfile:t:r}.pl >"Test/${scriptfile:t:r}/perlcritic.log" 2>&1 pushd Test @@ -38,6 +43,9 @@ STARTUP if [[ ! -s stderr.log ]] { rm -f stderr.log } popd printf . >&2 + if [[ -n $GITHUB_ACTION ]] { + echo /$scriptfile >&2 + } popd logs=(~/irc.log.*(N)) if [[ $#logs -gt 0 ]] { diff --git a/_testing/travis/_get_files_arr.zsh b/_testing/travis/_get_files_arr.zsh index f798818..98086d7 100644 --- a/_testing/travis/_get_files_arr.zsh +++ b/_testing/travis/_get_files_arr.zsh @@ -5,7 +5,7 @@ if [[ $TRAVIS_PULL_REQUEST != false ]] { scriptfiles=($(git diff --numstat --no-renames $TRAVIS_BRANCH|cut -f3|grep '^scripts/.*\.pl')) IFS=$OIFS if [[ $#scriptfiles -gt 0 ]] { - filelist=($scriptfiles) + filelist=($scriptfiles) } } \ elif [[ $USE_ARTEFACTS_CACHE = yes ]] { diff --git a/_testing/travis/show-failures.zsh b/_testing/travis/show-failures.zsh index 1ce6229..1c5be14 100755 --- a/_testing/travis/show-failures.zsh +++ b/_testing/travis/show-failures.zsh @@ -7,21 +7,21 @@ if [[ $TRAVIS_PULL_REQUEST != false ]] { for scriptfile ($filelist) { echo '--- '$scriptfile:t if [[ -f "Test/${scriptfile:t:r}/failed.yml" ]] { - echo "FATAL: SCRIPT FAILED TO LOAD " - } + 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 '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" - } + cat "Test/${scriptfile:t:r}/info.yml" + } } } \ else { diff --git a/_testing/update-scripts-yaml.pl b/_testing/update-scripts-yaml.pl index 2c155f7..04228e4 100644 --- a/_testing/update-scripts-yaml.pl +++ b/_testing/update-scripts-yaml.pl @@ -21,44 +21,44 @@ for (@{$docs[0]//[]}) { my %newmeta; for my $file () { my ($filename, $base) = - $file =~ m,^scripts/((.*)\.pl)$,; + $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=(); - } + 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; - my $commands = delete $newmeta{$filename}{commands}; - my @commands = grep { !/ / } @$commands - if 'ARRAY' eq ref $commands; - $newmeta{$filename}{commands} = "@commands" - if @commands; + $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; + my $commands = delete $newmeta{$filename}{commands}; + my @commands = grep { !/ / } @$commands + if 'ARRAY' eq ref $commands; + $newmeta{$filename}{commands} = "@commands" + if @commands; } elsif (exists $oldmeta{$filename}) { - print "META-INF FOR $base NOT FOUND\n"; - system "ls 'Test/$base/'*"; - $newmeta{$filename} = $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"; + print "MISSING META FOR $base\n"; } } my @newdoc = map { @@ -77,15 +77,15 @@ if ($config && @{$config->{whitelist}//[]}) { my $changed; my @wl; for my $sf (@{$config->{whitelist}}) { - if (-s "Test/$sf:passed") { - $changed = 1; - } - else { - push @wl, $sf; - } + if (-s "Test/$sf:passed") { + $changed = 1; + } + else { + push @wl, $sf; + } } if ($changed) { - $config->{whitelist} = \@wl; - YAML::Tiny::DumpFile('_testing/config.yml', $config); + $config->{whitelist} = \@wl; + YAML::Tiny::DumpFile('_testing/config.yml', $config); } } diff --git a/_tools/add_script_vote_comment.pl b/_tools/add_script_vote_comment.pl index 272ba6f..60aec3d 100755 --- a/_tools/add_script_vote_comment.pl +++ b/_tools/add_script_vote_comment.pl @@ -68,12 +68,12 @@ for my $sc (sort { $a->{modified} cmp $b->{modified} } @$x) { my %sc = %$sc; #sleep 1; my $res = p("https://$cred{user}:$cred{pass}\@api.github.com/repos/$cred{user}/scripts.irssi.org/issues/$issue/comments" - => {Accept => "*/*"} - => json - => { - body => "$sc{filename}\n---\n$sc{description}\n\nClick on ![+😃](https://user-images.githubusercontent.com/5665186/52212818-af6a7480-288d-11e9-9e48-4822b0a8efce.png) :+1: :-1: to add your votes" - } - ); + => {Accept => "*/*"} + => json + => { + body => "$sc{filename}\n---\n$sc{description}\n\nClick on ![+😃](https://user-images.githubusercontent.com/5665186/52212818-af6a7480-288d-11e9-9e48-4822b0a8efce.png) :+1: :-1: to add your votes" + } + ); say $res->code; unless ($res->code == 201) { say $res->body; exit 1; } exit;