Skip to content

Commit

Permalink
Add strings file validation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelherger committed Aug 26, 2024
1 parent f3208fd commit 795c531
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/00_smoketest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ on:
jobs:
linux:
name: Run LMS to see whether it crashes immediately...
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

steps:
- name: Make sure we're running as non-root
run: |
if [ "$RUNNER_USER" == "root" ]; then
echo Specify non-root image when testing with act:
echo act -P ubuntu-22.04=ghcr.io/catthehacker/ubuntu:runner-22.04
echo act -P ubuntu-24.04=ghcr.io/catthehacker/ubuntu:runner-24.04
exit 1
fi
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install depedencies
run: |
Expand All @@ -27,5 +27,8 @@ jobs:
fi
sudo apt-get install -y libio-socket-ssl-perl libnet-ssleay-perl netcat
- name: Run test
- name: Test Strings File
run: perl -ICPAN t/verifyStrings.pl

- name: Run Startup Test
run: bash t/00_smoketest.sh
50 changes: 50 additions & 0 deletions t/verifyStrings.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env perl

use strict;
use warnings;

use File::Next;
use File::Slurp;
use JSON;

my %translations;
my (@output, @invalid, $slug);

my $files = File::Next::files( {
file_filter => sub { /\bstrings\.txt$/ }
}, '.' );

while (my $file = $files->()) {
foreach (read_file($file)) {
my ($lang, $translation);
chomp;

next if /^#/;

if (/^\t([-A-Z0-9_]{2,5})\t(.*)/) {
($lang, $translation) = ($1, $2);
} elsif (/^[-A-Z0-9_]+$/) {
$slug = $_;
} elsif ($_) {
push @invalid, "Invalid line ($slug): $_";
}

if ($lang && !exists $translations{$lang}) {
$translations{$lang} = {};
}

if ($lang) {
$translations{$lang}{$slug} = $translation;
}
}
}

foreach my $lang (grep { !$translations{$_}->{LANGUAGE_CHOICES} } keys %translations) {
push @invalid, "Invalid language: $lang";
}

if (scalar(@invalid)) {
print "Errors:\n";
print join("\n", @invalid);
exit 1;
}

0 comments on commit 795c531

Please sign in to comment.