Update seed.py #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"), | ||
| }); | ||