Skip to content

Commit

Permalink
experimental python
Browse files Browse the repository at this point in the history
  • Loading branch information
Ailin Nemui committed Sep 11, 2023
1 parent abfb3a3 commit b6078ab
Show file tree
Hide file tree
Showing 21 changed files with 290 additions and 208 deletions.
28 changes: 28 additions & 0 deletions .github/pm-perl-critic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"problemMatcher": [
{
"owner": "perl-critic",
"severity": "warning",
"pattern": [
{
"regexp": "^(.*): (.*) at line (\\d+), column (\\d+)\\. (.*)\\. \\(Severity: \\d\\)$",
"file": 1,
"line": 3,
"column": 4,
"message": 2,
"code": 5
}
]
},
{
"owner": "perl-critic-fail",
"pattern": [
{
"regexp": "^(.*): (.*)\\. \\(Severity: \\d\\)$",
"file": 1,
"message": 2
}
]
}
]
}
16 changes: 16 additions & 0 deletions .github/pm-perl-warning.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "perl-warning",
"severity": "warning",
"pattern": [
{
"regexp": "^([*] )?(.*) at (.*) line (\\d+)\\.$",
"file": 3,
"line": 4,
"message": 2
}
]
}
]
}
18 changes: 18 additions & 0 deletions .github/pm-script-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "script-error",
"pattern": [
{
"regexp": ": Error in script ",
},
{
"regexp": "^([*] )?(.*) at (.*) line (\\d+)\\.$",
"file": 3,
"line": 4,
"message": 2
}
]
}
]
}
55 changes: 28 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,49 @@ on:
pull_request:
name: Check Script
env:
apt_build_deps: irssi-git-an cpanminus elinks zsh
apt_build_deps: irssi-git-an irssi-python3 cpanminus elinks flake8 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:
skip:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.ci-skip-step.outputs.ci-skip }}
skip-not: ${{ steps.ci-skip-step.outputs.ci-skip-not }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: ci-skip-step
uses: mstachniuk/ci-skip@v1
test:
needs: skip
if: ${{ needs.skip.outputs.skip == 'false' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
with:
fetch-depth: 0
- 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-an/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-an/xUbuntu_$RELEASE/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_ailin_nemui_irssi-git-an.gpg > /dev/null
sudo apt -q update
sudo apt -q install $apt_build_deps $apt_script_deps
- name: check Perl ver
id: perl-ver
- name: Setup flake8 annotations
uses: rbialon/flake8-annotations@master
if: ${{ github.event_name == 'pull_request' }}
- name: Setup local annotations
if: ${{ github.event_name == 'pull_request' }}
run: |
for pm in "$PWD"/.github/pm-*.json; do
echo "::add-matcher::$pm"
done
- name: check versions
id: ver
run: |
echo ::set-output name=perl_version::$(perl -e'print $^V')
echo "perl_version=$(perl -e'print $^V')" | tee -a "$GITHUB_OUTPUT"
echo "python_version=$(python3 -c 'import platform; print(platform.python_version())')" | tee -a "$GITHUB_OUTPUT"
echo "irssi_version=$(irssi --version | awk '{print $2}')" | tee -a "$GITHUB_OUTPUT"
- name: cache cpan
uses: actions/cache@v2
uses: actions/cache@main
with:
path: |
~/extlib
key: ${{ runner.os }}-${{ steps.perl-ver.outputs.perl_version }}-cpan-${{ github.sha }}-${{ github.run_number }}
key: ${{ runner.os }}-${{ steps.ver.outputs.perl_version }}-cpan-${{ github.sha }}-${{ github.run_number }}
restore-keys: |
${{ runner.os }}-${{ steps.perl-ver.outputs.perl_version }}-cpan-${{ github.sha }}-
${{ runner.os }}-${{ steps.perl-ver.outputs.perl_version }}-cpan-
${{ runner.os }}-${{ steps.ver.outputs.perl_version }}-cpan-${{ github.sha }}-
${{ runner.os }}-${{ steps.ver.outputs.perl_version }}-cpan-
- name: fetch origin master branch
if: ${{ github.event_name == 'pull_request' }}
run: |
Expand All @@ -61,7 +56,7 @@ jobs:
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
eval echo "\$v=\$$v" >> "$GITHUB_ENV"
done
- name: fix the broken Encode module
run: |
Expand Down Expand Up @@ -91,17 +86,23 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
run: |
git diff --stat origin/master
MARKDOWN_REPORT=1 ./_testing/report-test.zsh >> "$GITHUB_STEP_SUMMARY" || :
- name: test report
run: |
./_testing/report-test.zsh || rc=$?
echo "SCRIPT_RC=${rc:-0}" >> $GITHUB_ENV
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: show git changes
if: ${{ github.event_name == 'pull_request' }}
run: |
echo '```' >> "$GITHUB_STEP_SUMMARY"
git diff --ignore-matching-lines='^ modified:' | tee -a "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
- name: commit scripts.yaml
if: ${{ github.event_name == 'push' }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
_site
Test/
*~
5 changes: 1 addition & 4 deletions _testing/_get_files_arr.zsh
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
if [[ $TRAVIS == true ]] {
. ./_testing/travis/_get_files_arr.zsh
} \
elif [[ -n $GITHUB_ACTION ]] {
if [[ -n $GITHUB_ACTION ]] {
. ./_testing/github/_get_files_arr.zsh
} \
else {
Expand Down
5 changes: 3 additions & 2 deletions _testing/_irssi_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ BEGIN

if (!%info || !defined $info{name}) {
open my $ef, '>>', "perlcritic.log";
print $ef 'No %IRSSI header in script or name not given. (Severity: 6)', "\n";
print $ef "scripts/$CURRENT_SCRIPT.pl: ", 'No %IRSSI header in script or name not given. (Severity: 6)', "\n";
$info{name} //= $CURRENT_SCRIPT;
}
if (!defined $version) {
open my $ef, '>>', "perlcritic.log";
print $ef 'Missing $VERSION in script. (Severity: 6)', "\n";
print $ef "scripts/$CURRENT_SCRIPT.pl: ", 'Missing $VERSION in script. (Severity: 6)', "\n";
}
else {
$info{version} = $version;
Expand All @@ -103,5 +103,6 @@ BEGIN
$info{modules} = \@modules if @modules;
$info{commands} = \@commands if @commands;
$info{default_package} = $package =~ s/::$//r if $package;
$info{language} = 'Perl';
YAML::Tiny::DumpFile("info.yml", [\%info]);
Irssi::command('^window log off');
77 changes: 77 additions & 0 deletions _testing/_irssi_test_py.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use strict;
use warnings;

my $CURRENT_SCRIPT = $ENV{CURRENT_SCRIPT};
my $PWD = $ENV{PWD};
my $SWD = "$PWD/../..";

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
# and fall back to Latin-1.
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 %existing_commands;
my (%info, $version, $package, @commands);
Irssi::command_bind('_irssi_test_py_cb' => sub {
my ($data, $server, $witem) = @_;
use JSON::PP;
my $doc = decode_json("$data");
eval { %info = %{$doc->{'IRSSI'}} };
eval { $version = $doc->{'VERSION'} };
eval { $package = $doc->{'package'} };
@commands = sort grep { !$existing_commands{$_} } map { $_->{cmd} } Irssi::commands;
});

%existing_commands = map { ($_->{cmd} => 1) } Irssi::commands;

Irssi::command('^window log on');
Irssi::command("py load $CURRENT_SCRIPT");

unless (defined $package) {
my %fail = (failed => 1, name => $CURRENT_SCRIPT);
YAML::Tiny::DumpFile("failed.yml", [\%fail]);
# TODO: Grep for the code instead
}
delete $info{''};
for my $rb (keys %info) {
delete $info{$rb} unless defined $info{$rb};
}

if (!%info || !defined $info{name}) {
open my $ef, '>>', "perlcritic.log";
print $ef "scripts/$CURRENT_SCRIPT.py: ", 'No IRSSI header in script or name not given. (Severity: 6)', "\n";
$info{name} //= $CURRENT_SCRIPT;
}
if (!defined $version) {
open my $ef, '>>', "perlcritic.log";
print $ef "scripts/$CURRENT_SCRIPT.py: ", 'Missing __version__ in script. (Severity: 6)', "\n";
}
else {
$info{version} = $version;
}
chomp(my $loginfo = `git log 2d0759e6... -1 --format=%ai -- "$SWD/scripts/$CURRENT_SCRIPT.py" 2>/dev/null ||
git log -1 --format=%d%m%ai -- "$SWD/scripts/$CURRENT_SCRIPT.py" | grep -v grafted | cut -d'>' -f2`);
if ($loginfo) {
my ($date, $time) = split ' ', $loginfo;
$info{modified} = "$date $time";
}
#$info{modules} = \@modules if @modules;
$info{commands} = \@commands if @commands;
$info{default_package} = $package if $package;
$info{language} = 'Python';
YAML::Tiny::DumpFile("info.yml", [\%info]);
Irssi::command('^window log off');
1 change: 1 addition & 0 deletions _testing/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ scripts_yaml_keys:
- description
- license
# optional
- language
- url
- commands
- note
Expand Down
9 changes: 6 additions & 3 deletions _testing/github/_get_files_arr.zsh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
filelist=(scripts/*.pl)
script_pattern='^scripts/.*\.\(pl\|py\)$'
OIFS=$IFS; IFS=$'\n'
filelist=($(find scripts -type f | grep $script_pattern))
IFS=$OIFS
if [[ $GITHUB_REF != refs/heads/master ]] {
local -a scriptfiles
OIFS=$IFS; IFS=$'\n'
scriptfiles=($(git diff --numstat --no-renames origin/master|cut -f3|grep '^scripts/.*\.pl'))
scriptfiles=($(git diff --numstat --no-renames origin/master | cut -f3 | grep $script_pattern))
IFS=$OIFS
if [[ $#scriptfiles -gt 0 ]] {
filelist=($scriptfiles)
Expand All @@ -11,7 +14,7 @@ if [[ $GITHUB_REF != refs/heads/master ]] {
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\ )})
cache_allowed=(scripts/${^$(grep -v __ARTEFACTS_CI__ old-artefacts/can-use-cache | cut -f2- -d' ')})
IFS=$OIFS

if [[ $REPORT_STAGE == yes ]] {
Expand Down
2 changes: 1 addition & 1 deletion _testing/github/load-old-artefacts.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/zsh
echo $(git log --format=%H -1 _testing .github) __ARTEFACTS_CI__>old-artefacts/new-changed-info
for f (scripts/*.pl) {
for f (scripts/*.pl(N) scripts/*.py(N)) {
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
Expand Down
15 changes: 10 additions & 5 deletions _testing/github/show-failures.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

. ./_testing/_get_files_arr.zsh

root_script() {
perl -p -e 's{ at ([^/\s]*) line (\d+)}{ at scripts/$1 line $2}g'
}

if [[ $GITHUB_REF != refs/heads/master ]] {
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"
cat "Test/${scriptfile:t:r}/stderr.log" 2>/dev/null | root_script
cat "Test/${scriptfile:t:r}/irssi.log" | root_script
echo
echo 'Source code critic:'
cat "Test/${scriptfile:t:r}/perlcritic.log"
cat "Test/${scriptfile:t:r}/perlcritic.log" 2>/dev/null
cat "Test/${scriptfile:t:r}/flake8.log" 2>/dev/null
echo
}
echo
Expand All @@ -29,8 +34,8 @@ else {
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"
cat "Test/${scriptfile:t:r}/stderr.log" 2>/dev/null | root_script
cat "Test/${scriptfile:t:r}/irssi.log" | root_script
echo
}
}
Expand Down
8 changes: 6 additions & 2 deletions _testing/report-test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ for scriptfile ($filelist) {

# CRIT
if { grep -qs 'Code before strictures are enabled\|Two-argument "open" used' "Test/${scriptfile:t:r}/perlcritic.log" } { print -n ' '$failmark' ' } \
elif { grep -qs ': \(E9\|F63\|F7\|F82\)' "Test/${scriptfile:t:r}/flake8.log" } { print -n ' '$failmark' ' } \
elif { grep -qs 'command not found:' "Test/${scriptfile:t:r}/perlcritic.log" } { print -n ' '$skipmark' ' } \
else { print -n ' '$passmark' '; ((++pass)) }; print -n $T

# SCORE
perl -ne '$score += $1 -1 if /Severity: (\d+)/; END { printf "%3d", $score }' "Test/${scriptfile:t:r}/perlcritic.log" 2>/dev/null
perl -ne 'BEGIN { @fl = ("E9|F63|F7|F82" => 5, "F[0-9]" => 4, "E[0-9]" => 3, "[CW][0-9]" => 2, "N[0-9]" => 1) }
$score += $1 -1 if /Severity: (\d+)/;
for ($i = 0; $i < @fl; $i += 2) { if (/\d: $fl[$i]/) { $score += $fl[$i + 1]; last } }
END { printf "%3d", $score }' "Test/${scriptfile:t:r}/perlcritic.log" "Test/${scriptfile:t:r}/flake8.log" 2>/dev/null
print -n ' '$T
if [[ $pass -lt 3 ]] {
if [[ -n $allow_fail[$scriptfile:t:r] ]] || [[ ! -f scripts/${scriptfile:t:r}.pl ]] {
if [[ -n $allow_fail[$scriptfile:t:r] ]] || { [[ ! -f scripts/${scriptfile:t:r}.pl ]] && [[ ! -f scripts/${scriptfile:t:r}.py ]] } {
print -n ' '$skipmark' '
} \
else {
Expand Down
Loading

0 comments on commit b6078ab

Please sign in to comment.