Deploy Ontology to SPARQL Endpoint #25
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: Deploy Ontology to SPARQL Endpoint | |
| on: | |
| workflow_run: | |
| workflows: ["Generate Public Ontology Docs"] # Trigger after docs | |
| types: | |
| - completed | |
| workflow_dispatch: # Optional manual trigger | |
| jobs: | |
| deploy-ontology: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| # --- 1. Checkout --- | |
| - name: π§Ύ Check out repository | |
| uses: actions/checkout@v4 | |
| # --- 2. Detect ontology changes --- | |
| - name: π΅οΈ Detect changes in src/ontology | |
| id: changes | |
| uses: tj-actions/changed-files@v44 | |
| with: | |
| files: src/ontology/** | |
| - name: π Skip if no ontology changes | |
| if: steps.changes.outputs.any_changed != 'true' | |
| run: echo "No ontology changes detected. Skipping deployment." | |
| # --- 3. Backup and deploy ontology --- | |
| - name: π Backup and deploy ontology | |
| if: steps.changes.outputs.any_changed == 'true' | |
| env: | |
| ONTOLOGY_SPARQL_ENDPOINT: ${{ secrets.ONTOLOGY_SPARQL_ENDPOINT }} | |
| GRAPHDB_USERNAME: ${{ secrets.GRAPHDB_USERNAME }} | |
| GRAPHDB_PASSWORD: ${{ secrets.GRAPHDB_PASSWORD }} | |
| GRAPH_URI: ${{ secrets.GRAPH_URI }} | |
| run: | | |
| set -euo pipefail | |
| timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
| ARCHIVE_URI="${GRAPH_URI}/archive/${timestamp}" | |
| echo "π Deploying ontology to ${ONTOLOGY_SPARQL_ENDPOINT}" | |
| echo "Target graph: ${GRAPH_URI}" | |
| echo "Backup archive graph: ${ARCHIVE_URI}" | |
| echo "π¦ Backing up current graph to ${ARCHIVE_URI}..." | |
| curl -sf -u "${GRAPHDB_USERNAME}:${GRAPHDB_PASSWORD}" \ | |
| -X POST \ | |
| -H "Content-Type: application/sparql-update" \ | |
| --data "COPY GRAPH <${GRAPH_URI}> TO GRAPH <${ARCHIVE_URI}>" \ | |
| "${ONTOLOGY_SPARQL_ENDPOINT}" || echo "β οΈ No existing graph to back up (may be first deployment)." | |
| echo "π§Ή Dropping existing graph <${GRAPH_URI}>..." | |
| curl -sf -u "${GRAPHDB_USERNAME}:${GRAPHDB_PASSWORD}" \ | |
| -X POST \ | |
| -H "Content-Type: application/sparql-update" \ | |
| --data "DROP GRAPH <${GRAPH_URI}>" \ | |
| "${ONTOLOGY_SPARQL_ENDPOINT}" | |
| echo "π€ Uploading TTL files from src/ontology to <${GRAPH_URI}>..." | |
| ls -l src/ontology/ | |
| find src/ontology -type f -name "*.ttl" -print0 | while IFS= read -r -d '' file; do | |
| echo "β $file" | |
| curl -sf -u "${GRAPHDB_USERNAME}:${GRAPHDB_PASSWORD}" \ | |
| -X POST \ | |
| -H "Content-Type: text/turtle" \ | |
| --data-binary "@${file}" \ | |
| "${ONTOLOGY_SPARQL_ENDPOINT}?graph=${GRAPH_URI}" | |
| done | |
| echo "π Ontology deployment completed successfully." |