Skip to content

Commit

Permalink
Merge pull request #63 from empty-233/main
Browse files Browse the repository at this point in the history
Add split rules
  • Loading branch information
SunsetMkt authored Jun 19, 2024
2 parents f4c236d + be2d416 commit 0bde691
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
run: |
pip3 install -r requirements.txt
python3 generate.py
python3 generate_rule.py
- name: 提交更改
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
Expand Down
28 changes: 28 additions & 0 deletions generate_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import re

# 读取文件
with open("./rules.yaml", "r") as file:
rules = file.read()

# 创建文件夹
os.makedirs("./rules", exist_ok=True)

# 正则
regex = r"# ======= (.*?) ======= #"
result = re.split(regex, rules)

# 拆分 yaml文件
for i in range(1, len(result), 2):
ruleName = result[i]
ruleContent = result[i + 1]

# 创建对应名称的文件
filePath = f"./rules/{ruleName}.yaml"

# 添加原始文件内容
splitYAML = f"{result[0]}\n# ======= {ruleName} ======= #\n{ruleContent}"

# 写入文件
with open(filePath, "w") as file:
file.write(splitYAML)

0 comments on commit 0bde691

Please sign in to comment.