summaryrefslogtreecommitdiff
path: root/.github/workflows/fail_on_error.py
diff options
context:
space:
mode:
authorIngHK <[email protected]>2023-12-08 16:44:58 +0100
committerIngHK <[email protected]>2023-12-08 16:44:58 +0100
commit4d88f146e3a79ca4e7c7bbba2cdd6b8f3b07537a (patch)
treed3e7eed808967619fd880e4425256f8e1cc6de6e /.github/workflows/fail_on_error.py
parentb8881a3a141530a1d383d8869881e773b8a07d80 (diff)
parent338ff2daba63fc60835934efc374c818f7c5980c (diff)
Merge remote-tracking branch 'remotes/hathach/master' into HostLogsFixes
Diffstat (limited to '.github/workflows/fail_on_error.py')
-rwxr-xr-x.github/workflows/fail_on_error.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/.github/workflows/fail_on_error.py b/.github/workflows/fail_on_error.py
new file mode 100755
index 000000000..29791742b
--- /dev/null
+++ b/.github/workflows/fail_on_error.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+import json
+import sys
+
+# Return whether SARIF file contains error-level results
+def codeql_sarif_contain_error(filename):
+ with open(filename, 'r') as f:
+ s = json.load(f)
+
+ for run in s.get('runs', []):
+ rules_metadata = run['tool']['driver']['rules']
+ if not rules_metadata:
+ rules_metadata = run['tool']['extensions'][0]['rules']
+
+ for res in run.get('results', []):
+ if 'ruleIndex' in res:
+ rule_index = res['ruleIndex']
+ elif 'rule' in res and 'index' in res['rule']:
+ rule_index = res['rule']['index']
+ else:
+ continue
+ try:
+ rule_level = rules_metadata[rule_index]['defaultConfiguration']['level']
+ except IndexError as e:
+ print(e, rule_index, len(rules_metadata))
+ else:
+ if rule_level == 'error':
+ return True
+ return False
+
+if __name__ == "__main__":
+ if codeql_sarif_contain_error(sys.argv[1]):
+ sys.exit(1)