From c011be931c1a3db4a9b17926888bd17d27840bb2 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Fri, 22 Mar 2024 00:21:16 +0100 Subject: [PATCH] [CI] Validate uploaded icons --- .github/validate-rapps.py | 44 +++++++++++++++++++++++----- .github/workflows/validate-rapps.yml | 12 ++++---- .gitignore | 1 + 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 .gitignore diff --git a/.github/validate-rapps.py b/.github/validate-rapps.py index 18b1c65..9c9c3c0 100644 --- a/.github/validate-rapps.py +++ b/.github/validate-rapps.py @@ -2,15 +2,17 @@ PROJECT: ReactOS rapps-db validator LICENSE: MIT (https://spdx.org/licenses/MIT) PURPOSE: Validate all rapps-db files -COPYRIGHT: Copyright 2020-2023 Mark Jansen +COPYRIGHT: Copyright 2020-2024 Mark Jansen ''' -import os +from pathlib import Path import sys from enum import Enum, unique +import struct; + # TODO: make this even nicer by using https://github.com/pytorch/add-annotations-github-action -REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +REPO_ROOT = Path(__file__).parents[1] REQUIRED_SECTION_KEYS = [ b'Name', @@ -95,6 +97,10 @@ class Reporter: idx = column - 1 + len("b'") # Offset the b' prefix print(' ' * idx + '^') + def add_file(self, file, problem): + self._problems += 1 + print('{file}: {problem}'.format(file=file, problem=problem)) + def problems(self): return self._problems > 0 @@ -227,11 +233,11 @@ class RappsLine: class RappsFile: def __init__(self, fullname): self.path = fullname - self.filename = os.path.basename(fullname) + self.filename = fullname.name self._sections = [] def parse(self, reporter): - with open(self.path, 'rb') as f: + with open(str(self.path), 'rb') as f: lines = [RappsLine(self, idx + 1, line) for idx, line in enumerate(f.readlines())] # Create sections from all lines, and add keyvalue entries in their own section @@ -298,14 +304,38 @@ def verify_unique(reporter, lines, line, name): else: lines[name] = line +def validate_single_icon(icon, reporter): + try: + with open(str(icon), 'rb') as f: + header = f.read(4) + # First we validate the header + if header != b'\x00\x00\x01\x00': + reporter.add_file('icons/' + icon.name, 'Bad icon header') + return + # Check that there is at least one icon + num_icons, = struct.unpack('