-
-
Notifications
You must be signed in to change notification settings - Fork 162
74 lines (61 loc) · 2.25 KB
/
sync-adopters.yaml
File metadata and controls
74 lines (61 loc) · 2.25 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Sync Adopters to README
on:
push:
branches: [main]
paths: [USERS.md]
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract adopters and update README
run: |
python3 - <<'SCRIPT'
import re
# Read USERS.md and extract Organization + Description columns
with open("USERS.md") as f:
lines = f.read().strip().split("\n")
def esc_cell(value: str) -> str:
return value.replace("\n", " ").replace("|", r"\|").strip()
rows = []
for line in lines:
if not line.startswith("|"):
continue
parts = [p.strip() for p in line.split("|")]
# parts: ['', org, contact, desc, '']
if len(parts) < 4:
continue
org = parts[1]
if org == "Organization" or org.startswith("---") or org.startswith("--"):
continue
desc = parts[3]
rows.append(f"| {esc_cell(org)} | {esc_cell(desc)} |")
table = "| Organization | Description of Use |\n| --- | --- |\n" + "\n".join(rows)
# Replace content between markers in README.md
with open("README.md") as f:
readme = f.read()
pattern = re.compile(
r"(<!-- ADOPTERS:START -->\n).*?(\n<!-- ADOPTERS:END -->)",
flags=re.DOTALL,
)
readme, replaced = pattern.subn(
rf"\g<1>{table}\g<2>", readme, count=1
)
if replaced != 1:
raise SystemExit("Expected exactly one ADOPTERS block in README.md")
with open("README.md", "w") as f:
f.write(readme)
SCRIPT
- name: Check for changes
id: diff
run: git diff --quiet README.md || echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Commit and push
if: steps.diff.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "docs: sync adopters from USERS.md to README"
git push