Skip to content

Commit 8b8159e

Browse files
committed
enforce linting policy and require check before PR
1 parent 4202584 commit 8b8159e

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.github/workflows/lint.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Lint Database
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
name: Lint Database
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-node@v3
11+
with:
12+
node-version: 16
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.10'
16+
- run: npm i -g wrangler
17+
- run: python3 make.py

database.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,4 @@
247247
肆意流淌吧
248248
让世间到处盛开 无法定格的花
249249
才是盛夏
250-
-- 举烛 《夏日降雨禁令》, 2022
250+
-- 举烛 《夏日降雨禁令》, 2022

make.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,16 @@ def print_file_size(filename: str):
4545

4646

4747
def load():
48+
with open(FILENAMES.SOURCE_DATABASE, "rb") as f:
49+
if b'\r' in f.read():
50+
print(colored('red', 'Error:'), '数据库文件中不得包含 CR (\\r) 字符')
51+
sys.exit(-2)
4852
with open(FILENAMES.SOURCE_DATABASE, encoding='utf-8') as f:
49-
database = f.read().strip()
53+
database = f.read()
54+
if not database.endswith('\n'):
55+
print(colored('red', 'Error:'), '数据库文件应该以 LF (\\n) 结尾')
56+
sys.exit(-2)
57+
database = database.strip()
5058
database = [i.strip() for i in database.split('-' * 30)]
5159
if (database[0] == '') or (database[-1] == ''):
5260
print(colored('red', 'Error:'), '遇到了空的歌词块 (quoteblock)')

0 commit comments

Comments
 (0)