Skip to content

Commit c9782f6

Browse files
committed
[CI] Validate uploaded icons
1 parent 220fbf8 commit c9782f6

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

.github/validate-rapps.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
PROJECT: ReactOS rapps-db validator
33
LICENSE: MIT (https://spdx.org/licenses/MIT)
44
PURPOSE: Validate all rapps-db files
5-
COPYRIGHT: Copyright 2020-2023 Mark Jansen <[email protected]>
5+
COPYRIGHT: Copyright 2020-2024 Mark Jansen <[email protected]>
66
'''
7-
import os
7+
from pathlib import Path
88
import sys
99
from enum import Enum, unique
10+
import struct;
11+
1012

1113
# TODO: make this even nicer by using https://github.com/pytorch/add-annotations-github-action
1214

13-
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15+
REPO_ROOT = Path(__file__).parents[1]
1416

1517
REQUIRED_SECTION_KEYS = [
1618
b'Name',
@@ -95,6 +97,10 @@ def add(self, line, column, problem):
9597
idx = column - 1 + len("b'") # Offset the b' prefix
9698
print(' ' * idx + '^')
9799

100+
def add_file(self, file, problem):
101+
self._problems += 1
102+
print('{file}: {problem}'.format(file=file, problem=problem))
103+
98104
def problems(self):
99105
return self._problems > 0
100106

@@ -227,11 +233,11 @@ def text(self):
227233
class RappsFile:
228234
def __init__(self, fullname):
229235
self.path = fullname
230-
self.filename = os.path.basename(fullname)
236+
self.filename = fullname.name
231237
self._sections = []
232238

233239
def parse(self, reporter):
234-
with open(self.path, 'rb') as f:
240+
with open(str(self.path), 'rb') as f:
235241
lines = [RappsLine(self, idx + 1, line) for idx, line in enumerate(f.readlines())]
236242

237243
# Create sections from all lines, and add keyvalue entries in their own section
@@ -298,14 +304,38 @@ def verify_unique(reporter, lines, line, name):
298304
else:
299305
lines[name] = line
300306

301-
302-
def validate_repo(dirname):
307+
def validate_single_icon(icon, reporter):
308+
try:
309+
with open(icon, 'rb') as f:
310+
header = f.read(4)
311+
# First we validate the header
312+
if header != b'\x00\x00\x01\x00':
313+
reporter.add_file('icons/' + icon.name, 'Bad icon header')
314+
return
315+
# Check that there is at least one icon
316+
num_icons, = struct.unpack('<H', f.read(2))
317+
if num_icons == 0:
318+
reporter.add_file('icons/' + icon.name, 'Empty icon?')
319+
return
320+
# Should we validate / display individual icons?
321+
# See https://en.wikipedia.org/wiki/ICO_(file_format)#Structure_of_image_directory
322+
except Exception as e:
323+
reporter.add_file('icons/' + icon.name, 'Exception while reading icon: ' + str(e))
324+
325+
def validate_icons(ico_dir, reporter):
326+
for icon in ico_dir.glob('*.ico'):
327+
validate_single_icon(icon, reporter)
328+
329+
330+
def validate_repo(check_dir):
303331
reporter = Reporter()
304332

305-
all_files = [RappsFile(filename) for filename in os.listdir(dirname) if filename.endswith('.txt')]
333+
all_files = [RappsFile(file) for file in check_dir.glob('*.txt')]
306334
for entry in all_files:
307335
entry.parse(reporter)
308336

337+
validate_icons(check_dir / 'icons', reporter)
338+
309339
if reporter.problems():
310340
print('Please check https://reactos.org/wiki/RAPPS for details on the file format.')
311341
sys.exit(1)

.github/workflows/validate-rapps.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
1+
# This workflow will install Python dependencies, lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
33

44
name: rapps-db validation
55

@@ -15,11 +15,11 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up Python 3.8
20-
uses: actions/setup-python@v2
18+
- uses: actions/checkout@v3
19+
- name: Set up Python 3.10
20+
uses: actions/setup-python@v3
2121
with:
22-
python-version: 3.8
22+
python-version: "3.10"
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv

0 commit comments

Comments
 (0)