-
Notifications
You must be signed in to change notification settings - Fork 2
74 lines (62 loc) · 2.75 KB
/
sync.yaml
File metadata and controls
74 lines (62 loc) · 2.75 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
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."