-
Notifications
You must be signed in to change notification settings - Fork 1
193 lines (172 loc) · 7.35 KB
/
Copy pathschema_submission.yml
File metadata and controls
193 lines (172 loc) · 7.35 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: Schema Submission
on:
issues:
types: [opened]
jobs:
ingest:
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: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-
- name: Cache sentence-transformers model
uses: actions/cache@v4
with:
path: ~/.cache/huggingface/hub
key: hf-minilm-v2
restore-keys: hf-
# Embeddings cache keyed on all schemas — new schema busts the cache and
# forces a recompute, unchanged schemas reuse their cached vectors.
- name: Cache embeddings
uses: actions/cache@v4
with:
path: data/embeddings.parquet
key: embeddings-${{ hashFiles('schemas/*.yml') }}-${{ github.run_id }}
restore-keys: embeddings-${{ hashFiles('schemas/*.yml') }}-
embeddings-
# -----------------------------------------------------------------------
- name: Install dependencies
run: pip install -r requirements.txt
# -----------------------------------------------------------------------
- name: Parse issue metadata
id: meta
run: |
TITLE="${{ github.event.issue.title }}"
SCHEMA_NAME="${TITLE#schema-submission:}"
SCHEMA_NAME=$(echo "$SCHEMA_NAME" | xargs | tr ' ' '-' | tr '[:upper:]' '[:lower:]')
echo "schema_name=$SCHEMA_NAME" >> $GITHUB_OUTPUT
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
if echo "$LABELS" | grep -q "breaking"; then
echo "bump=major" >> $GITHUB_OUTPUT
else
echo "bump=minor" >> $GITHUB_OUTPUT
fi
# -----------------------------------------------------------------------
# Write the submitted schema to schemas/{name}.yml so it's picked up
# by pipeline.py alongside all previously committed schemas.
- name: Extract and write schema file
env:
ISSUE_BODY: ${{ github.event.issue.body }}
SCHEMA_NAME: ${{ steps.meta.outputs.schema_name }}
run: |
python3 - << 'PYEOF'
import os, re, sys, json
import yaml
body = os.environ["ISSUE_BODY"]
name = os.environ["SCHEMA_NAME"]
fenced = re.search(r'```([\w-]*)\s*\n(.*?)```', body, re.DOTALL)
if fenced:
lang = (fenced.group(1) or "yaml").lower()
content = fenced.group(2).strip()
else:
lang = "yaml"
content = body.strip()
json_schema_langs = {"json", "json-schema", "jsonschema"}
os.makedirs("schemas", exist_ok=True)
out_path = f"schemas/{name}.yml"
if lang in json_schema_langs:
print(f"Detected format: JSON Schema ({lang!r}) — converting…")
sys.path.insert(0, ".")
from neuro_ghost.converters.from_jsonschema import convert as js2lm
try:
data = json.loads(content)
except json.JSONDecodeError:
data = yaml.safe_load(content)
linkml_dict = js2lm(data, name)
with open(out_path, "w") as f:
yaml.dump(linkml_dict, f, default_flow_style=False,
allow_unicode=True, sort_keys=False)
print(f"Converted → {out_path} "
f"({len(linkml_dict['classes'])} classes)")
else:
print(f"Detected format: LinkML ({lang!r})")
with open(out_path, "w") as f:
f.write(content)
print(f"Wrote {out_path}")
PYEOF
# -----------------------------------------------------------------------
- name: Validate LinkML schema
run: |
python neuro_ghost/validate_schema.py \
schemas/${{ steps.meta.outputs.schema_name }}.yml
# -----------------------------------------------------------------------
# Full rebuild from all schemas/*.yml in the repo (including the new one
# written above). --skip-converters keeps CI fast — external schemas
# (BIDS/NWB/DANDI/…) are refreshed by the weekly publish_registry.yml.
- name: Rebuild registry (all local schemas)
run: |
python neuro_ghost/pipeline.py \
--fresh \
--skip-converters \
--bump ${{ steps.meta.outputs.bump }} \
--issue ${{ github.event.issue.number }} \
--agent "${{ github.event.issue.user.login }}"
# -----------------------------------------------------------------------
- name: Commit registry + schema file
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 \
data/versions/ \
data/provenance.json
git diff --cached --quiet || git commit -m \
"feat(registry): ingest ${{ steps.meta.outputs.schema_name }} (issue #${{ github.event.issue.number }})"
git push
# -----------------------------------------------------------------------
- name: Comment success
if: success()
uses: actions/github-script@v7
with:
script: |
const name = "${{ steps.meta.outputs.schema_name }}";
const pagesUrl = "https://sensein.group/NeuroGhost/";
await github.rest.issues.createComment({
owner: context.repo.owner, repo: context.repo.repo,
issue_number: context.issue.number,
body: [
`✅ **\`${name}\` ingested successfully.**`,
``,
`- All schemas rebuilt and aligned.`,
`- Provenance logged to \`data/provenance.json\`.`,
`- Archived snapshot in \`data/versions/\`.`,
``,
`Browse: ${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 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: [
`❌ **Ingestion failed.**`,
``,
`Check the run log for validation errors (undefined slot, \`is_a\` parent, or range).`,
``,
`[View run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`,
].join("\n"),
});