From dee8166048096f916697a266c29bc50248928afa Mon Sep 17 00:00:00 2001 From: Denis Averin Date: Tue, 7 May 2024 14:17:22 +0700 Subject: [PATCH] Cleanup --- .github/workflows/python-app.yml | 25 --------- scripts/check-order.py | 95 -------------------------------- 2 files changed, 120 deletions(-) delete mode 100644 .github/workflows/python-app.yml delete mode 100755 scripts/check-order.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 13c3131..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Python - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - name: Check Release Notes order - run: | - python ./scripts/check-order.py diff --git a/scripts/check-order.py b/scripts/check-order.py deleted file mode 100755 index d63ff01..0000000 --- a/scripts/check-order.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python - -import os -import re -from collections import namedtuple -import operator -from typing import List, Optional - -RELEASE_NOTES_RE = re.compile(r"release-notes-(?P\d+)") -BARCODE_VERSION_RE = re.compile( - r"aspose-barcode(?:-for)?-cloud-(\d+)-(\d+)(?:-(\d+))?-release-notes" -) - -WEIGHT_RE = re.compile(r"^\s*weight:\s*(?P\d+)\s*$") - -SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) - -RELEASE_NOTES_DIR = os.path.abspath( - os.path.join(SCRIPT_DIR, "..", "barcode", "release-notes") -) -assert os.path.isdir(RELEASE_NOTES_DIR) - -Item = namedtuple("Item", ("key", "weight", "memo")) - - -def list_dirs(root: str): - return [d for d in os.listdir(root) if os.path.isdir(os.path.join(root, d))] - - -def get_weight_from_index(index_filename: str) -> int: - with open(index_filename, "rt") as f: - for line in f.readlines(): - match = WEIGHT_RE.match(line) - if match: - return int(match.groupdict()["weight"]) - else: - raise Exception( - f"Pattern {WEIGHT_RE.pattern} not found in '{index_filename}'" - ) - - -def get_dir_weight(dirname: str) -> Optional[int]: - index = os.path.join(dirname, "_index.md") - if not os.path.isfile(index): - return None - - return get_weight_from_index(index) - - -def extract_version(s: str, regex: re.Pattern) -> tuple[int]: - match = regex.match(s) - assert match, f"String {s} doesn't match '{regex.pattern}'" - return tuple(int(d) for d in match.groups() if d is not None) - - -def assert_sorted(items: List[Item]) -> bool: - reverse_sorted_items = sorted(items, key=operator.attrgetter("key"), reverse=True) - prev_item = None - for item in reverse_sorted_items: - if prev_item is None: - prev_item = item - continue - - assert ( - item.weight > prev_item.weight - ), f"'{prev_item.memo}.weight' ({prev_item.weight}) should be less than '{item.memo}.weight' ({item.weight})" - return False - return True - - -def check_sorted(root, regex): - weights = [] - for dir_name in list_dirs(root): - version = extract_version(dir_name, regex) - weight = get_dir_weight(os.path.join(root, dir_name)) - if weight is None: - continue - weights.append(Item(key=version, weight=weight, memo=dir_name)) - - return assert_sorted(weights) - - -def main(): - weights = [] - for rn in list_dirs(RELEASE_NOTES_DIR): - check_sorted(os.path.join(RELEASE_NOTES_DIR, rn), BARCODE_VERSION_RE) - key = extract_version(rn, RELEASE_NOTES_RE) - weight = get_dir_weight(os.path.join(RELEASE_NOTES_DIR, rn)) - weights.append(Item(key=key, weight=weight, memo=rn)) - assert_sorted(weights) - print("All release notes sorted!") - - -if __name__ == "__main__": - main()