-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcreate-ecr-description.py
More file actions
50 lines (40 loc) · 1.18 KB
/
create-ecr-description.py
File metadata and controls
50 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
import json
import re
import os
# Read entire markdown file
with open(sys.argv[1], "r") as f:
md = f.read()
# Normalize underlined headings
md = re.sub(
r'(?m)^[ \t]*(.+?)\s*\r?\n[ \t]*-{3,}[ \t]*\r?\n',
r'## \1\n\n',
md
)
# Split by top-level headings (# ...)
sections = re.split(r"(?m)^# ", md)
parsed = {}
for sec in sections[1:]:
# Extract title (text until newline)
title, _, content = sec.partition("\n")
title = title.strip()
parsed[title] = content.strip()
# Sections we want in usage
usage_sections = [
"How to use this image",
"Image Variants"
]
usage_text = ""
about_text = ""
# Add sections to appropriate text blocks
for title, content in parsed.items():
# heading_prefix = "##" if title == "Latest unstable" else "#"
heading_prefix = "#"
if title in usage_sections:
usage_text += f"{heading_prefix} {title}\n{content}\n\n"
else:
about_text += f"{heading_prefix} {title}\n{content}\n\n"
# Write to GitHub Actions environment file
with open(os.environ['GITHUB_ENV'], 'a') as f:
f.write(f"ABOUT_JSON={json.dumps(about_text.strip())}\n")
f.write(f"USAGE_JSON={json.dumps(usage_text.strip())}\n")