From 65fdbbf2f9485cc907cb9a6d6b9210938a50f71e Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Thu, 7 Dec 2023 07:47:34 -0500 Subject: [PATCH] add ci --- .github/workflows/ci.yml | 16 ++++++++++++++++ check.py | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 check.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..52fbecd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout last commit + uses: actions/checkout@v4 + - name: Check format + run: python check.py diff --git a/check.py b/check.py new file mode 100644 index 0000000..61283fc --- /dev/null +++ b/check.py @@ -0,0 +1,23 @@ +import re + +with open('stroke.dict.yaml') as file: + lines = file.readlines() + +item2line: dict[tuple[str, str], int] = {} + +start = lines.index('...\n') + 1 + +for i, line in enumerate(lines[start:], start=start+1): + line = line.rstrip() + if not line or line.startswith('#'): + continue + match = re.match(r'(\S+)\t(\S+)', line) + if not match: + print(f'Syntax error at line {i}') + exit(1) + key = (match.group(1), match.group(2)) + n = item2line.get(key) + if n: + print(f'Duplicated definition at line {n} and {i}: {line}') + exit(1) + item2line[key] = i