Skip to content

Commit 6cb77d3

Browse files
zehaclaude
andcommitted
Extract validation script to standalone file
- Add bin/validate_masterlist as executable Perl script - Simplify GitHub Actions workflow to use standalone script - Remove inline script generation from workflow 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 948746b commit 6cb77d3

2 files changed

Lines changed: 89 additions & 96 deletions

File tree

.github/workflows/validate-masterlist.yml

Lines changed: 22 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -9,138 +9,64 @@ on:
99
jobs:
1010
validate-masterlist:
1111
runs-on: ubuntu-latest
12-
12+
1313
steps:
1414
- uses: actions/checkout@v4
15-
15+
1616
- name: Install dependencies
1717
run: |
1818
sudo apt-get update
1919
sudo apt-get install -y perl mirmon
20-
21-
- name: Create validation script
22-
run: |
23-
cat > validate_masterlist.pl << 'SCRIPT'
24-
#!/usr/bin/perl
25-
use strict;
26-
use warnings;
27-
28-
my $file = $ARGV[0] || 'Mirrors.masterlist';
29-
die "no file $file" unless -f $file;
30-
31-
open(my $fh, '<', $file) or die "Could not open $file: $!";
32-
33-
my @mirrors;
34-
my $data;
35-
my $line_num = 0;
36-
my $errors = 0;
37-
38-
while (my $line = <$fh>) {
39-
$line_num++;
40-
chomp $line;
41-
if ($line =~ /([^:]+): (.*)/) {
42-
my $key = lc($1);
43-
my $value = $2;
44-
$data->{$key} = $value;
45-
} elsif ($line eq '') {
46-
if ($data) {
47-
# Validate required fields
48-
unless ($data->{site}) {
49-
print "ERROR: Entry missing Site field around line $line_num\n";
50-
$errors++;
51-
}
52-
unless ($data->{type}) {
53-
print "ERROR: Entry missing Type field for site " . ($data->{site} || "unknown") . "\n";
54-
$errors++;
55-
}
56-
unless ($data->{country}) {
57-
print "ERROR: Entry missing Country field for site " . ($data->{site} || "unknown") . "\n";
58-
$errors++;
59-
}
60-
push @mirrors, $data;
61-
}
62-
$data = undef;
63-
} else {
64-
print "WARNING: Malformed line $line_num: $line\n";
65-
}
66-
}
67-
68-
# Check last entry if file does not end with blank line
69-
if ($data) {
70-
unless ($data->{site}) {
71-
print "ERROR: Last entry missing Site field\n";
72-
$errors++;
73-
}
74-
unless ($data->{type}) {
75-
print "ERROR: Last entry missing Type field for site " . ($data->{site} || "unknown") . "\n";
76-
$errors++;
77-
}
78-
unless ($data->{country}) {
79-
print "ERROR: Last entry missing Country field for site " . ($data->{site} || "unknown") . "\n";
80-
$errors++;
81-
}
82-
push @mirrors, $data;
83-
}
84-
85-
if ($errors > 0) {
86-
print "Found $errors syntax errors in masterlist\n";
87-
exit(1);
88-
} else {
89-
print "Masterlist syntax validation passed (" . @mirrors . " entries)\n";
90-
}
91-
SCRIPT
92-
93-
chmod +x validate_masterlist.pl
94-
20+
9521
- name: Validate masterlist syntax
9622
run: |
9723
# Check if masterlist file exists
9824
if [ ! -f "Mirrors.masterlist" ]; then
9925
echo "ERROR: Mirrors.masterlist not found"
10026
exit 1
10127
fi
102-
103-
# Run syntax validation
104-
./validate_masterlist.pl Mirrors.masterlist
105-
28+
29+
# Run syntax validation using the standalone script
30+
./bin/validate_masterlist Mirrors.masterlist
31+
10632
- name: Test masterlist2mirmon conversion
10733
run: |
10834
# Make script executable
10935
chmod +x bin/masterlist2mirmon
110-
36+
11137
# Run the conversion
11238
echo "Converting masterlist to mirmon format..."
11339
./bin/masterlist2mirmon Mirrors.masterlist > test-mirror.list
114-
40+
11541
# Check if output was generated
11642
if [ ! -s test-mirror.list ]; then
11743
echo "ERROR: masterlist2mirmon produced no output"
11844
exit 1
11945
fi
120-
46+
12147
# Count entries
12248
entries=$(wc -l < test-mirror.list)
12349
echo "Generated $entries mirror entries"
124-
50+
12551
# Basic format validation
12652
echo "Validating mirmon list format..."
12753
if ! grep -q "^[A-Z][A-Z] " test-mirror.list; then
12854
echo "ERROR: No valid country code entries found"
12955
exit 1
13056
fi
131-
57+
13258
# Check for valid URL patterns
13359
if ! grep -qE "^[A-Z][A-Z] (https?|ftp|rsync)://" test-mirror.list; then
13460
echo "ERROR: No valid URL entries found"
13561
exit 1
13662
fi
137-
63+
13864
echo "Mirror list format validation passed"
139-
65+
14066
# Show sample output
14167
echo "Sample mirror entries:"
14268
head -5 test-mirror.list
143-
69+
14470
- name: Test mirmon compatibility
14571
run: |
14672
# Create minimal mirmon config for testing
@@ -155,10 +81,10 @@ jobs:
15581
probe /usr/bin/wget -q -O- -T %TIMEOUT% -t 1 %URL%timestamp.txt
15682
icons icons
15783
CONFIG
158-
84+
15985
# Create dummy icons directory
16086
mkdir -p icons
161-
87+
16288
# Test if mirmon can parse our generated mirror list
16389
echo "Testing mirmon compatibility..."
16490
if ! mirmon -c test-mirmon.conf -q test >/dev/null 2>&1; then
@@ -168,7 +94,7 @@ jobs:
16894
else
16995
echo "Mirmon compatibility test passed"
17096
fi
171-
97+
17298
# Alternative test: just verify mirmon can read the mirror list file
17399
echo "Alternative test: verify mirmon can parse mirror list format..."
174100
if perl -e '
@@ -193,15 +119,15 @@ jobs:
193119
echo "ERROR: Mirror list format validation failed"
194120
exit 1
195121
fi
196-
122+
197123
- name: Validate mirror URLs accessibility (sample)
198124
run: |
199125
# Test a sample mirror URL
200126
echo "Testing sample mirror URL accessibility..."
201-
127+
202128
# Extract first HTTPS URL
203129
first_url=$(grep -m1 "^[A-Z][A-Z] https" test-mirror.list | cut -d' ' -f2- || true)
204-
130+
205131
if [ -n "$first_url" ]; then
206132
echo "Testing URL: $first_url"
207133
if timeout 10 curl -sSf --head "$first_url" > /dev/null 2>&1; then
@@ -212,4 +138,4 @@ jobs:
212138
fi
213139
else
214140
echo "No HTTPS URLs found to test"
215-
fi
141+
fi

bin/validate_masterlist

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
5+
my $file = $ARGV[0] || 'Mirrors.masterlist';
6+
die "no file $file" unless -f $file;
7+
8+
open(my $fh, '<', $file) or die "Could not open $file: $!";
9+
10+
my @mirrors;
11+
my $data;
12+
my $line_num = 0;
13+
my $errors = 0;
14+
15+
while (my $line = <$fh>) {
16+
$line_num++;
17+
chomp $line;
18+
if ($line =~ /([^:]+): (.*)/) {
19+
my $key = lc($1);
20+
my $value = $2;
21+
$data->{$key} = $value;
22+
} elsif ($line eq '') {
23+
if ($data) {
24+
# Validate required fields
25+
unless ($data->{site}) {
26+
print "ERROR: Entry missing Site field around line $line_num\n";
27+
$errors++;
28+
}
29+
unless ($data->{type}) {
30+
print "ERROR: Entry missing Type field for site " . ($data->{site} || "unknown") . "\n";
31+
$errors++;
32+
}
33+
unless ($data->{country}) {
34+
print "ERROR: Entry missing Country field for site " . ($data->{site} || "unknown") . "\n";
35+
$errors++;
36+
}
37+
push @mirrors, $data;
38+
}
39+
$data = undef;
40+
} else {
41+
print "WARNING: Malformed line $line_num: $line\n";
42+
}
43+
}
44+
45+
# Check last entry if file does not end with blank line
46+
if ($data) {
47+
unless ($data->{site}) {
48+
print "ERROR: Last entry missing Site field\n";
49+
$errors++;
50+
}
51+
unless ($data->{type}) {
52+
print "ERROR: Last entry missing Type field for site " . ($data->{site} || "unknown") . "\n";
53+
$errors++;
54+
}
55+
unless ($data->{country}) {
56+
print "ERROR: Last entry missing Country field for site " . ($data->{site} || "unknown") . "\n";
57+
$errors++;
58+
}
59+
push @mirrors, $data;
60+
}
61+
62+
if ($errors > 0) {
63+
print "Found $errors syntax errors in masterlist\n";
64+
exit(1);
65+
} else {
66+
print "Masterlist syntax validation passed (" . @mirrors . " entries)\n";
67+
}

0 commit comments

Comments
 (0)