Skip to content

Commit

Permalink
Merge PR cosmos#97: Add CI to check sections
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes authored May 21, 2019
1 parent c88d039 commit 6a475d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ jobs:
<<: *linux_defaults
steps:
- checkout
- run: sudo make setup_dependencies check_links
- run: make check_links

check_sections:
<<: *linux_defaults
steps:
- checkout
- run: make check_sections

check_syntax:
<<: *linux_defaults
Expand All @@ -31,4 +37,5 @@ workflows:
jobs:
- check_dependencies
- check_links
- check_sections
- check_syntax
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ check_dependencies:
check_syntax:
bash ./scripts/check_syntax.sh

.PHONY: $(TOPTARGETS) $(SUBDIRS) setup_dependencies check_links check_dependencies check_syntax
check_sections:
python ./scripts/check_sections.py

.PHONY: $(TOPTARGETS) $(SUBDIRS) setup_dependencies check_links check_dependencies check_syntax check_sections
37 changes: 37 additions & 0 deletions scripts/check_sections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

import re, os, sys

top_section_regex = re.compile('[^#]# (.*)')
sub_section_regex = re.compile('[^#]## (.*)')
sub_sub_section_regex = re.compile('[^#]### (.*)')

specs = [f.path for f in os.scandir('./spec') if f.is_dir()]
files = [f.path for spec in specs for f in os.scandir(spec) if f.is_file() and f.path[-3:] == '.md' and 'ics-1' not in f.path]

expected_sub_sections = ['Synopsis', 'Technical Specification', 'Backwards Compatibility', 'Forwards Compatibility', 'Example Implementation', 'Other Implementations', 'History', 'Copyright']
expected_sub_sub_sections = ['Motivation', 'Definitions', 'Desired Properties']

for fn in files:
print('Checking sections in {}'.format(fn))
data = open(fn).read()
top_sections = top_section_regex.findall(data)
if len(top_sections) != 0:
print('Expected no top-level sections but instead found: {}'.format(top_sections))
sys.exit(1)
sub_sections = sub_section_regex.findall(data)[::-1]
for sub_section in expected_sub_sections:
found = sub_sections.pop()
if sub_section != found:
print('Expected sub-section {} but instead found {}!'.format(sub_section, found))
sys.exit(1)
if len(sub_sections) != 0:
print('Expected no remaining sub-sections but instead found: {}'.format(sub_sections))
sys.exit(1)
sub_sub_sections = sub_sub_section_regex.findall(data)[::-1]
for sub_sub_section in expected_sub_sub_sections:
found = sub_sub_sections.pop()
if sub_sub_section != found:
print('Expected sub-sub-section {} but instead found {}!'.format(sub_section, found))
sys.exit(1)
print('Remaining sub-sub-sections: {}'.format(sub_sub_sections))

0 comments on commit 6a475d9

Please sign in to comment.