Skip to content

Commit

Permalink
Add duplicate key check to the CI build
Browse files Browse the repository at this point in the history
  • Loading branch information
kickroot committed May 10, 2023
1 parent a67b18f commit 5831c74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
# Clones the magpie repository, build it and then validate the security rules
# using the SecurityRuleValidator in magpie core
- name: Verify Rule IDs
run: python3 dupe_check.py
- name: Clone Magpie
run: git clone https://github.com/openraven/magpie.git
- name: Build Magpie
Expand Down
19 changes: 19 additions & 0 deletions dupe_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import os

sub_path = "resources/rules/"

id_to_files = {}

for file in os.listdir(sub_path):
if file.endswith(".yaml"):
with open(sub_path + file, 'r') as f:
line = f.readline().strip()
uuid = line.split(":")[1].strip()
if uuid in id_to_files.keys():
msg = f"Duplicate key found for id={uuid}, file1={id_to_files[uuid]}, file2={file}"
raise Exception(msg)
id_to_files[uuid] = file
print(f"Successfully validated {id_to_files.size()} files for duplicate IDs")


0 comments on commit 5831c74

Please sign in to comment.