Skip to content

Instantly share code, notes, and snippets.

@samestep
Created January 15, 2021 20:58
Show Gist options
  • Save samestep/2c480cd5e3c70e7b36f2678c65cfbbb2 to your computer and use it in GitHub Desktop.
Save samestep/2c480cd5e3c70e7b36f2678c65cfbbb2 to your computer and use it in GitHub Desktop.
set of CircleCI resource classes
#!/usr/bin/env python3
import re
from pathlib import Path
import yaml
def all_resource_classes(thing):
if isinstance(thing, list):
return {c for e in thing for c in all_resource_classes(e)}
elif isinstance(thing, dict):
s = set()
for k, v in thing.items():
if k == 'resource_class':
if isinstance(v, dict):
s.add(v['default'])
else:
s.add(v)
else:
s |= all_resource_classes(v)
return s
else:
return set()
if __name__ == '__main__':
text = Path('.circleci/config.yml').read_text()
thing = yaml.load(text, Loader=yaml.Loader)
for c in all_resource_classes(thing):
if not re.match(r'^<< .* >>$', c):
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment