1 |
commit: a415817eb8b23db8aa7b99684ba7db33b279e2e1 |
2 |
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Feb 27 19:27:51 2023 +0000 |
4 |
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 27 19:30:40 2023 +0000 |
6 |
URL: https://gitweb.gentoo.org/data/api.git/commit/?id=a415817e |
7 |
|
8 |
bin/repositories-checker.py: various improvements and fixes |
9 |
|
10 |
- Add `--github` option to output in github actions format, |
11 |
otherwise use colored term output. |
12 |
- If "-" is passed as base xml, assume we are doing full xml check. |
13 |
In this mode I skip checking maintainer emails since it might use |
14 |
too much API calls. |
15 |
- Fix typing |
16 |
- Improve error message for bas repos sorting (explain what is bad) |
17 |
|
18 |
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> |
19 |
|
20 |
.github/workflows/repositories.yml | 2 +- |
21 |
bin/repositories-checker.py | 61 +++++++++++++++++++++++++------------- |
22 |
2 files changed, 41 insertions(+), 22 deletions(-) |
23 |
|
24 |
diff --git a/.github/workflows/repositories.yml b/.github/workflows/repositories.yml |
25 |
index 3f09609..dae070f 100644 |
26 |
--- a/.github/workflows/repositories.yml |
27 |
+++ b/.github/workflows/repositories.yml |
28 |
@@ -23,7 +23,7 @@ jobs: |
29 |
- name: Check repositories.xml |
30 |
run: | |
31 |
BASE_REF=$(git merge-base --fork-point origin/${{ github.base_ref }}) |
32 |
- python bin/repositories-checker.py <(git show ${BASE_REF}:files/overlays/repositories.xml) files/overlays/repositories.xml |
33 |
+ python bin/repositories-checker.py --github <(git show ${BASE_REF}:files/overlays/repositories.xml) files/overlays/repositories.xml |
34 |
|
35 |
validate-schema: |
36 |
runs-on: ubuntu-latest |
37 |
|
38 |
diff --git a/bin/repositories-checker.py b/bin/repositories-checker.py |
39 |
index 7d7cae3..2810bc3 100755 |
40 |
--- a/bin/repositories-checker.py |
41 |
+++ b/bin/repositories-checker.py |
42 |
@@ -1,7 +1,7 @@ |
43 |
#!/usr/bin/env python3 |
44 |
|
45 |
""" |
46 |
-Copyright (C) 2022 Arthur Zamarin <arthurzam@g.o> |
47 |
+Copyright (C) 2022-2023 Arthur Zamarin <arthurzam@g.o> |
48 |
|
49 |
This program is free software: you can redistribute it and/or modify |
50 |
it under the terms of the GNU General Public License as published by |
51 |
@@ -17,20 +17,24 @@ You should have received a copy of the GNU General Public License |
52 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
53 |
""" |
54 |
|
55 |
-from http.client import HTTPSConnection |
56 |
+import argparse |
57 |
import sys |
58 |
-from typing import Iterator, Tuple |
59 |
+from http.client import HTTPSConnection |
60 |
+from typing import Iterable, Tuple |
61 |
from urllib.parse import quote_plus |
62 |
-from lxml import etree |
63 |
|
64 |
+from lxml import etree |
65 |
|
66 |
ok_flag = True |
67 |
|
68 |
|
69 |
def output_xml_error(xml: etree._Element, title: str, content: str): |
70 |
start = xml.sourceline |
71 |
- end = start + len(etree.tostring(xml).strip().split(b'\n')) - 1 |
72 |
- print(f'::error file={sys.argv[2]},line={start},endLine={end},title={title}::{content}') |
73 |
+ if args.github: |
74 |
+ end = start + len(etree.tostring(xml).strip().split(b'\n')) - 1 |
75 |
+ print(f'::error file={args.current},line={start},endLine={end},title={title}::{content}') |
76 |
+ else: |
77 |
+ print(f'\033[91m{args.current}:{start} - {title} - {content}\033[0m') |
78 |
|
79 |
global ok_flag |
80 |
ok_flag = False |
81 |
@@ -38,8 +42,11 @@ def output_xml_error(xml: etree._Element, title: str, content: str): |
82 |
|
83 |
def output_xml_warning(xml: etree._Element, title: str, content: str): |
84 |
start = xml.sourceline |
85 |
- end = start + len(etree.tostring(xml).strip().split()) |
86 |
- print(f'::warning file={sys.argv[2]},line={start},endLine={end},title={title}::{content}') |
87 |
+ if args.github: |
88 |
+ end = start + len(etree.tostring(xml).strip().split()) |
89 |
+ print(f'::warning file={args.current},line={start},endLine={end},title={title}::{content}') |
90 |
+ else: |
91 |
+ print(f'\033[93m{args.current}:{start} - {title} - {content}\033[0m') |
92 |
|
93 |
|
94 |
class Overlay: |
95 |
@@ -79,11 +86,11 @@ class Overlay: |
96 |
return isinstance(o, Overlay) and o.repo_name == self.repo_name |
97 |
|
98 |
|
99 |
-def read_repositories(file: str) -> Iterator[Overlay]: |
100 |
+def read_repositories(file: str) -> Iterable[Overlay]: |
101 |
return map(Overlay, etree.parse(file).findall('./repo')) |
102 |
|
103 |
|
104 |
-def check_maintainers(overlays: Iterator[Overlay]) -> Iterator[Overlay]: |
105 |
+def check_maintainers(overlays: Iterable[Overlay]): |
106 |
try: |
107 |
client = HTTPSConnection('bugs.gentoo.org') |
108 |
for m in overlays: |
109 |
@@ -92,20 +99,32 @@ def check_maintainers(overlays: Iterator[Overlay]) -> Iterator[Overlay]: |
110 |
client.close() |
111 |
|
112 |
|
113 |
-def check_sorted(curr: Tuple[Overlay], adds: Iterator[Overlay]): |
114 |
+def check_sorted(curr: Tuple[Overlay, ...], adds: Iterable[Overlay]): |
115 |
for addition in adds: |
116 |
index = curr.index(addition) |
117 |
- if index > 0 and curr[index - 1].repo_name >= addition.repo_name: |
118 |
- output_xml_error(addition.xml, 'Unsorted overlay list', f'overlay "{addition.repo_name}" in wrong place') |
119 |
- elif index < len(curr) and curr[index + 1].repo_name <= addition.repo_name: |
120 |
- output_xml_error(addition.xml, 'Unsorted overlay list', f'overlay "{addition.repo_name}" in wrong place') |
121 |
+ repo_name = addition.repo_name |
122 |
+ if index > 0 and curr[index - 1].repo_name.lower() >= repo_name.lower(): |
123 |
+ output_xml_error(addition.xml, 'Unsorted overlay list', |
124 |
+ f"overlay {repo_name!r} in wrong place: {repo_name!r} isn't before {curr[index - 1].repo_name!r}") |
125 |
+ elif index + 1 < len(curr) and curr[index + 1].repo_name.lower() <= repo_name.lower(): |
126 |
+ output_xml_error(addition.xml, 'Unsorted overlay list', |
127 |
+ f"overlay {repo_name!r} in wrong place: {repo_name!r} isn't after {curr[index + 1].repo_name!r}") |
128 |
|
129 |
|
130 |
if __name__ == '__main__': |
131 |
- base = tuple(read_repositories(sys.argv[1])) |
132 |
- current = tuple(read_repositories(sys.argv[2])) |
133 |
- additions = frozenset(current).difference(base) |
134 |
- |
135 |
- check_maintainers(additions) |
136 |
- check_sorted(current, additions) |
137 |
+ parser = argparse.ArgumentParser(description='Check repositories.xml') |
138 |
+ parser.add_argument('base', help='Original repositories.xml, pass "-" to perform full check') |
139 |
+ parser.add_argument('current', help='Current repositories.xml') |
140 |
+ parser.add_argument('--github', help='print errors in GitHub Actions format', action='store_true') |
141 |
+ args = parser.parse_args() |
142 |
+ |
143 |
+ current = tuple(read_repositories(args.current)) |
144 |
+ |
145 |
+ if args.base != '-': |
146 |
+ base = tuple(read_repositories(args.base)) |
147 |
+ additions = frozenset(current).difference(base) |
148 |
+ check_maintainers(additions) |
149 |
+ check_sorted(current, additions) |
150 |
+ else: |
151 |
+ check_sorted(current, current) |
152 |
sys.exit(int(not ok_flag)) |