|
| 1 | +name: Schema Submission |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + ingest: |
| 9 | + # Only run if issue title starts with "schema-submission:" |
| 10 | + if: startsWith(github.event.issue.title, 'schema-submission:') |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + issues: write |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.12" |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: pip install -r requirements.txt |
| 27 | + |
| 28 | + - name: Extract schema name from issue title |
| 29 | + id: meta |
| 30 | + run: | |
| 31 | + TITLE="${{ github.event.issue.title }}" |
| 32 | + # title format: "schema-submission:my-schema-name" |
| 33 | + SCHEMA_NAME="${TITLE#schema-submission:}" |
| 34 | + SCHEMA_NAME=$(echo "$SCHEMA_NAME" | tr -s ' ' | xargs | tr ' ' '-' | tr '[:upper:]' '[:lower:]') |
| 35 | + echo "schema_name=$SCHEMA_NAME" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + - name: Extract YAML from issue body |
| 38 | + id: extract |
| 39 | + env: |
| 40 | + ISSUE_BODY: ${{ github.event.issue.body }} |
| 41 | + run: | |
| 42 | + python3 - << 'PYEOF' |
| 43 | + import os, re, sys |
| 44 | +
|
| 45 | + body = os.environ["ISSUE_BODY"] |
| 46 | +
|
| 47 | + # Accept YAML fenced in ```yaml ... ``` or bare (no fence) |
| 48 | + fenced = re.search(r'```ya?ml\s*\n(.*?)```', body, re.DOTALL) |
| 49 | + if fenced: |
| 50 | + yaml_content = fenced.group(1) |
| 51 | + else: |
| 52 | + yaml_content = body.strip() |
| 53 | +
|
| 54 | + # Basic sanity check — must look like LinkML |
| 55 | + if "classes:" not in yaml_content: |
| 56 | + print("ERROR: issue body does not contain a valid LinkML schema (missing 'classes:' key).") |
| 57 | + sys.exit(1) |
| 58 | +
|
| 59 | + schema_name = os.environ.get("SCHEMA_NAME", "unknown") |
| 60 | + out_path = f"schemas/{schema_name}.yml" |
| 61 | + os.makedirs("schemas", exist_ok=True) |
| 62 | + with open(out_path, "w") as f: |
| 63 | + f.write(yaml_content) |
| 64 | + print(f"Wrote {out_path}") |
| 65 | + PYEOF |
| 66 | + env: |
| 67 | + SCHEMA_NAME: ${{ steps.meta.outputs.schema_name }} |
| 68 | + |
| 69 | + - name: Validate YAML parses as LinkML |
| 70 | + run: | |
| 71 | + python3 - << 'PYEOF' |
| 72 | + import yaml, sys |
| 73 | + name = "${{ steps.meta.outputs.schema_name }}" |
| 74 | + path = f"schemas/{name}.yml" |
| 75 | + with open(path) as f: |
| 76 | + data = yaml.safe_load(f) |
| 77 | + required = ["classes", "slots"] |
| 78 | + missing = [k for k in required if k not in data] |
| 79 | + if missing: |
| 80 | + print(f"ERROR: schema missing required keys: {missing}") |
| 81 | + sys.exit(1) |
| 82 | + print(f"Valid LinkML schema: {len(data.get('classes', {}))} classes, {len(data.get('slots', {}))} slots") |
| 83 | + PYEOF |
| 84 | +
|
| 85 | + - name: Ingest schema into registry |
| 86 | + run: | |
| 87 | + python neuro_registry/ingest_linkml.py \ |
| 88 | + --file schemas/${{ steps.meta.outputs.schema_name }}.yml \ |
| 89 | + --db registry.lbug |
| 90 | +
|
| 91 | + - name: Run alignment |
| 92 | + run: | |
| 93 | + python neuro_registry/align.py \ |
| 94 | + --source ${{ steps.meta.outputs.schema_name }} \ |
| 95 | + --db registry.lbug |
| 96 | +
|
| 97 | + - name: Export registry snapshot to JSON |
| 98 | + run: | |
| 99 | + python neuro_registry/export_json.py \ |
| 100 | + --db registry.lbug \ |
| 101 | + --out data/registry.json |
| 102 | +
|
| 103 | + - name: Commit schema file + updated data snapshot |
| 104 | + run: | |
| 105 | + git config user.name "github-actions[bot]" |
| 106 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 107 | + git add schemas/${{ steps.meta.outputs.schema_name }}.yml data/registry.json |
| 108 | + git diff --cached --quiet || git commit -m \ |
| 109 | + "feat(schema): ingest ${{ steps.meta.outputs.schema_name }} from issue #${{ github.event.issue.number }}" |
| 110 | + git push |
| 111 | +
|
| 112 | + - name: Comment on issue — success |
| 113 | + if: success() |
| 114 | + uses: actions/github-script@v7 |
| 115 | + with: |
| 116 | + script: | |
| 117 | + const name = "${{ steps.meta.outputs.schema_name }}"; |
| 118 | + const pagesUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}`; |
| 119 | + await github.rest.issues.createComment({ |
| 120 | + owner: context.repo.owner, |
| 121 | + repo: context.repo.repo, |
| 122 | + issue_number: context.issue.number, |
| 123 | + body: [ |
| 124 | + `✅ **Schema \`${name}\` ingested successfully.**`, |
| 125 | + ``, |
| 126 | + `- Classes and properties have been added to the registry.`, |
| 127 | + `- Alignment against existing schemas has been computed.`, |
| 128 | + `- Registry snapshot updated at \`data/registry.json\`.`, |
| 129 | + ``, |
| 130 | + `Browse the updated schema at: ${pagesUrl}`, |
| 131 | + ].join("\n"), |
| 132 | + }); |
| 133 | + await github.rest.issues.update({ |
| 134 | + owner: context.repo.owner, |
| 135 | + repo: context.repo.repo, |
| 136 | + issue_number: context.issue.number, |
| 137 | + state: "closed", |
| 138 | + }); |
| 139 | +
|
| 140 | + - name: Comment on issue — failure |
| 141 | + if: failure() |
| 142 | + uses: actions/github-script@v7 |
| 143 | + with: |
| 144 | + script: | |
| 145 | + await github.rest.issues.createComment({ |
| 146 | + owner: context.repo.owner, |
| 147 | + repo: context.repo.repo, |
| 148 | + issue_number: context.issue.number, |
| 149 | + body: [ |
| 150 | + `❌ **Schema ingestion failed.**`, |
| 151 | + ``, |
| 152 | + `Please check that your issue body contains a valid LinkML YAML schema`, |
| 153 | + `with both \`classes:\` and \`slots:\` keys, optionally fenced in \`\`\`yaml ... \`\`\`.`, |
| 154 | + ``, |
| 155 | + `[View the workflow run for details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`, |
| 156 | + ].join("\n"), |
| 157 | + }); |
0 commit comments