-
Notifications
You must be signed in to change notification settings - Fork 1
157 lines (139 loc) · 5.63 KB
/
Copy pathschema_submission.yml
File metadata and controls
157 lines (139 loc) · 5.63 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Schema Submission
on:
issues:
types: [opened]
jobs:
ingest:
# Only run if issue title starts with "schema-submission:"
if: startsWith(github.event.issue.title, 'schema-submission:')
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Extract schema name from issue title
id: meta
run: |
TITLE="${{ github.event.issue.title }}"
# title format: "schema-submission:my-schema-name"
SCHEMA_NAME="${TITLE#schema-submission:}"
SCHEMA_NAME=$(echo "$SCHEMA_NAME" | tr -s ' ' | xargs | tr ' ' '-' | tr '[:upper:]' '[:lower:]')
echo "schema_name=$SCHEMA_NAME" >> $GITHUB_OUTPUT
- name: Extract YAML from issue body
id: extract
env:
ISSUE_BODY: ${{ github.event.issue.body }}
run: |
python3 - << 'PYEOF'
import os, re, sys
body = os.environ["ISSUE_BODY"]
# Accept YAML fenced in ```yaml ... ``` or bare (no fence)
fenced = re.search(r'```ya?ml\s*\n(.*?)```', body, re.DOTALL)
if fenced:
yaml_content = fenced.group(1)
else:
yaml_content = body.strip()
# Basic sanity check — must look like LinkML
if "classes:" not in yaml_content:
print("ERROR: issue body does not contain a valid LinkML schema (missing 'classes:' key).")
sys.exit(1)
schema_name = os.environ.get("SCHEMA_NAME", "unknown")
out_path = f"schemas/{schema_name}.yml"
os.makedirs("schemas", exist_ok=True)
with open(out_path, "w") as f:
f.write(yaml_content)
print(f"Wrote {out_path}")
PYEOF
env:
SCHEMA_NAME: ${{ steps.meta.outputs.schema_name }}
- name: Validate YAML parses as LinkML
run: |
python3 - << 'PYEOF'
import yaml, sys
name = "${{ steps.meta.outputs.schema_name }}"
path = f"schemas/{name}.yml"
with open(path) as f:
data = yaml.safe_load(f)
required = ["classes", "slots"]
missing = [k for k in required if k not in data]
if missing:
print(f"ERROR: schema missing required keys: {missing}")
sys.exit(1)
print(f"Valid LinkML schema: {len(data.get('classes', {}))} classes, {len(data.get('slots', {}))} slots")
PYEOF
- name: Ingest schema into registry
run: |
python neuro_registry/ingest_linkml.py \
--file schemas/${{ steps.meta.outputs.schema_name }}.yml \
--db registry.lbug
- name: Run alignment
run: |
python neuro_registry/align.py \
--source ${{ steps.meta.outputs.schema_name }} \
--db registry.lbug
- name: Export registry snapshot to JSON
run: |
python neuro_registry/export_json.py \
--db registry.lbug \
--out data/registry.json
- name: Commit schema file + updated data snapshot
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add schemas/${{ steps.meta.outputs.schema_name }}.yml data/registry.json
git diff --cached --quiet || git commit -m \
"feat(schema): ingest ${{ steps.meta.outputs.schema_name }} from issue #${{ github.event.issue.number }}"
git push
- name: Comment on issue — success
if: success()
uses: actions/github-script@v7
with:
script: |
const name = "${{ steps.meta.outputs.schema_name }}";
const pagesUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: [
`✅ **Schema \`${name}\` ingested successfully.**`,
``,
`- Classes and properties have been added to the registry.`,
`- Alignment against existing schemas has been computed.`,
`- Registry snapshot updated at \`data/registry.json\`.`,
``,
`Browse the updated schema at: ${pagesUrl}`,
].join("\n"),
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: "closed",
});
- name: Comment on issue — failure
if: failure()
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: [
`❌ **Schema ingestion failed.**`,
``,
`Please check that your issue body contains a valid LinkML YAML schema`,
`with both \`classes:\` and \`slots:\` keys, optionally fenced in \`\`\`yaml ... \`\`\`.`,
``,
`[View the workflow run for details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`,
].join("\n"),
});