From 2dccd0ee5fe6d31e908e248ddf6644feb73df16a Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 01:43:40 +0200 Subject: [PATCH 01/10] Make python script to check wether all categories are sorted or not --- ensure_sorted.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ensure_sorted.py diff --git a/ensure_sorted.py b/ensure_sorted.py new file mode 100644 index 00000000..f954d1a6 --- /dev/null +++ b/ensure_sorted.py @@ -0,0 +1,75 @@ +#!/bin/python3 +import re + +class bcolors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + +class Category: + def __init__(self, name): + self.name = name + # a list of apps + self.apps = [] + + def add_app(self, app_str: str): + matches = re.findall("(?<=\\[\\*\\*).*(?=\\*\\*\\])", app_str) + if len(matches) != 1: + raise "These should be only one match" + app_name = matches[0] + # make it lower case and append it + self.apps.append(app_name.lower()) + + def is_sorted(self): + # I know not effiencent + return sorted(self.apps) == self.apps + + def __str__(self): + return str(self.apps) + + def __repr__(self): + return self.__str__() + +def main(): + readme_file = open('README.md', 'r') + # start of the Apps section + APPS_LINE_START = '## – Apps –\n' + lines = readme_file.readlines() + + index: int + try: + index = lines.index(APPS_LINE_START) + except ValueError: + print(f'String "{APPS_LINE_START}" was not found in README.md it\'s needed to determine the start of the app categories') + exit(1) + + categories = [] + for i in range(index+1, len(lines)): + # This is a category + if lines[i].startswith("### •"): + category = Category(lines[i][6:-1]) + categories.append(category) + # This is an app + elif lines[i].startswith("*"): + # The last category in the categories list is the one we're working on + category = categories[-1] + category.add_app(lines[i]) + + all_sorted = True + for i in categories: + if not i.is_sorted(): + print(f'Category {bcolors.OKBLUE}{i.name}{bcolors.ENDC} is not sorted') + all_sorted = False + + if not all_sorted: + exit(2) + + +if __name__ == "__main__": + main() \ No newline at end of file From db4def5f1c28dfac5120e6d7231f1e1182003ce8 Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 11:40:07 +0200 Subject: [PATCH 02/10] Show how to sort --- ensure_sorted.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) mode change 100644 => 100755 ensure_sorted.py diff --git a/ensure_sorted.py b/ensure_sorted.py old mode 100644 new mode 100755 index f954d1a6..7d6e4326 --- a/ensure_sorted.py +++ b/ensure_sorted.py @@ -3,11 +3,11 @@ class bcolors: HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKCYAN = '\033[96m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' + BLUE = '\033[94m' + CYAN = '\033[96m' + GREEN = '\033[92m' + YELLOW = '\033[93m' + RED = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' @@ -30,6 +30,15 @@ def is_sorted(self): # I know not effiencent return sorted(self.apps) == self.apps + # Tell exactly where it's unsorted + def where_unsorted(self): + for i in range(1, len(self.apps)): + if self.apps[i] < self.apps[i-1]: + return f'App {bcolors.RED}{self.apps[i-1]}{bcolors.ENDC} is not in the correct order' + + def get_sorted_list(self): + return sorted(self.apps) + def __str__(self): return str(self.apps) @@ -64,7 +73,11 @@ def main(): all_sorted = True for i in categories: if not i.is_sorted(): - print(f'Category {bcolors.OKBLUE}{i.name}{bcolors.ENDC} is not sorted') + print(f'Category {bcolors.BLUE}{i.name}{bcolors.ENDC} is not sorted') + print(' ' + i.where_unsorted()) + print(' Should be sorted as follows:') + for j in i.get_sorted_list(): + print(f' {j}') all_sorted = False if not all_sorted: From 99910ef42df1e754a7c9b7dcd1fd03d7568fca4d Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 11:53:58 +0200 Subject: [PATCH 03/10] Show how to sort but better --- ensure_sorted.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ensure_sorted.py b/ensure_sorted.py index 7d6e4326..c9c7a8d0 100755 --- a/ensure_sorted.py +++ b/ensure_sorted.py @@ -36,8 +36,16 @@ def where_unsorted(self): if self.apps[i] < self.apps[i-1]: return f'App {bcolors.RED}{self.apps[i-1]}{bcolors.ENDC} is not in the correct order' - def get_sorted_list(self): - return sorted(self.apps) + def how_to_sort(self): + sorted_apps = sorted(self.apps) + unsorted_apps = self.apps.copy() + for i in range(len(sorted_apps)): + if sorted_apps[i] != unsorted_apps[i]: + # Color it + sorted_apps[i] = f'{sorted_apps[i]}' + unsorted_apps[i] = f'{unsorted_apps[i]}' + + return sorted_apps, unsorted_apps def __str__(self): return str(self.apps) @@ -76,8 +84,11 @@ def main(): print(f'Category {bcolors.BLUE}{i.name}{bcolors.ENDC} is not sorted') print(' ' + i.where_unsorted()) print(' Should be sorted as follows:') - for j in i.get_sorted_list(): - print(f' {j}') + sorted, unsorted = i.how_to_sort() + longest_str = len(max(unsorted, key=len)) + for j in range(len(sorted)): + color = sorted[j] != unsorted[j] + print(f' {bcolors.RED if color else ''}{unsorted[j]}{bcolors.ENDC if color else ''}{((longest_str-len(unsorted[j]))+2) * ' '}{bcolors.GREEN if color else ''}{sorted[j]}{bcolors.ENDC if color else ''}') all_sorted = False if not all_sorted: From b64ca33f9854d9fe2b3d462e49f5a3510ffb3f9f Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 12:18:56 +0200 Subject: [PATCH 04/10] CI --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b127729..c2375fc4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,3 +23,9 @@ jobs: with: files: "*.md" config_file: .markdownlint.json + + ensure_sorted: + runs-on: ubuntu-latest + name: Ensure sorted + run: ./ensure_sorted.py + From b9805a97fbe17b5001255b8ef5c9f3d690f028d6 Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 12:22:20 +0200 Subject: [PATCH 05/10] CI fix --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2375fc4..bae4dedb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: ci -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: build: @@ -27,5 +27,7 @@ jobs: ensure_sorted: runs-on: ubuntu-latest name: Ensure sorted - run: ./ensure_sorted.py + steps: + - name: Ensure sorted + run: ./ensure_sorted.py From 5abbc72804644841b9207a2ba8d7f58b60724087 Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 12:24:22 +0200 Subject: [PATCH 06/10] CI fix Ensure sorted job --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bae4dedb..b55070c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,8 @@ jobs: ensure_sorted: runs-on: ubuntu-latest + permissions: + contents: read name: Ensure sorted steps: - name: Ensure sorted From dba43b38d54db463ade67dd5e0d079e19beccd28 Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 12:29:02 +0200 Subject: [PATCH 07/10] Maybe this work --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b55070c9..23317983 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,5 +31,5 @@ jobs: name: Ensure sorted steps: - name: Ensure sorted - run: ./ensure_sorted.py + run: python3 ./ensure_sorted.py From ce1a6b670c3d6645929f860e3c24ffbcd848a7bc Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 12:32:00 +0200 Subject: [PATCH 08/10] Make it look better --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23317983..29d8bd91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,5 +31,5 @@ jobs: name: Ensure sorted steps: - name: Ensure sorted - run: python3 ./ensure_sorted.py + run: python3 ensure_sorted.py From acae682442b0a2f9e6233c89ba293edd75a609c7 Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 13:06:26 +0200 Subject: [PATCH 09/10] =?UTF-8?q?count=20categories=20that=20starts=20with?= =?UTF-8?q?=20'##=20=E2=80=93'=20as=20well?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ensure_sorted.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ensure_sorted.py b/ensure_sorted.py index c9c7a8d0..04951eea 100755 --- a/ensure_sorted.py +++ b/ensure_sorted.py @@ -72,6 +72,11 @@ def main(): if lines[i].startswith("### •"): category = Category(lines[i][6:-1]) categories.append(category) + # This is also a category + elif lines[i].startswith("## –"): + category_name = re.findall("(?<=##\s–\s).*?(?=\s–)", lines[i])[0] + category = Category(category_name) + categories.append(category) # This is an app elif lines[i].startswith("*"): # The last category in the categories list is the one we're working on From 943e8381ee15a66a36a203bf6c48164f384ff763 Mon Sep 17 00:00:00 2001 From: Ammar64 Date: Thu, 7 Nov 2024 19:33:32 +0200 Subject: [PATCH 10/10] Remove workflow_dispatch --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29d8bd91..45263644 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: ci -on: [push, pull_request, workflow_dispatch] +on: [push, pull_request] jobs: build: