File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed
Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ name : OpenMetrics
2+
3+ on :
4+ pull_request :
5+ paths :
6+ - ' docs/specs/om/open_metrics_spec_2_0.md'
7+
8+ jobs :
9+ check-abnf :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - uses : actions/checkout@v4
14+ - name : Set up Python 3.10
15+ uses : actions/setup-python@v3
16+ with :
17+ python-version : " 3.12.3"
18+ - name : Install dependencies
19+ run : |
20+ python -m pip install --upgrade pip
21+ pip install abnf
22+ - name : Check ABNF for OpenMetrics 2.0
23+ run : |
24+ python3 scripts/check_openmetrics_spec.py docs/specs/om/open_metrics_spec_2_0.md
Original file line number Diff line number Diff line change 11---
2+
23title : " OpenMetrics 2.0"
34nav_title : " 2.0"
45sort_rank : 2
Original file line number Diff line number Diff line change 1+ #!/bin/env python3
2+
3+ from abnf import Rule
4+ import sys
5+
6+ class FromStringRule (Rule ):
7+ pass
8+
9+ # Start node for the OpenMetrics spec.
10+ start_node = 'exposition'
11+
12+ def get_spec (filename ):
13+ with open (filename , 'r' ) as file :
14+ lines = file .readlines ()
15+ spec = []
16+ collecting = False
17+ for line in lines :
18+ if collecting :
19+ if line .startswith ('```' ):
20+ collecting = False
21+ else :
22+ spec .append (line .strip ())
23+ continue
24+ if line .startswith ('```abnf' ):
25+ if len (spec ) > 0 :
26+ raise ValueError ("Multiple ABNF blocks found in the file." )
27+ collecting = True
28+
29+ if len (spec ) == 0 :
30+ raise ValueError ("No or empty ABNF block found in the file. Wanted ```abnf ... ```." )
31+ return spec
32+
33+ # Main
34+ if __name__ == "__main__" :
35+ if len (sys .argv ) != 2 :
36+ print ("Usage: python3 check_openmetrics_spec.py <filename.md>" )
37+ sys .exit (1 )
38+
39+ filename = sys .argv [1 ]
40+ if not filename .endswith ('.md' ):
41+ print (f"Error: { filename } is not a Markdown file." )
42+ sys .exit (1 )
43+ spec = get_spec (filename )
44+ try :
45+ rule = FromStringRule .load_grammar (grammar = '\n ' .join (spec ), strict = True )
46+ except Exception as e :
47+ print (f"Error parsing ABNF: { e } " )
48+ sys .exit (1 )
49+ print ("ABNF parsed successfully." )
You can’t perform that action at this time.
0 commit comments