|
| 1 | +name: Ontology CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: # Manual trigger |
| 7 | + inputs: |
| 8 | + release_tag: |
| 9 | + description: 'Release tag to process (leave empty for latest)' |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + # ============================================ |
| 15 | + # JOB 1: DOWNLOAD & VALIDATE |
| 16 | + # ============================================ |
| 17 | + validate: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: 🧾 Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: 📥 Download ontology from release |
| 24 | + run: | |
| 25 | + # Get release info |
| 26 | + if [ -n "${{ inputs.release_tag }}" ]; then |
| 27 | + RELEASE_TAG="${{ inputs.release_tag }}" |
| 28 | + echo "Using specified release: ${RELEASE_TAG}" |
| 29 | + RELEASE_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/${RELEASE_TAG}" |
| 30 | + else |
| 31 | + echo "Using latest release" |
| 32 | + RELEASE_URL="https://api.github.com/repos/${{ github.repository }}/releases/latest" |
| 33 | + fi |
| 34 | + |
| 35 | + # Get download URL for the ontology asset |
| 36 | + ASSET_URL=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 37 | + "${RELEASE_URL}" | \ |
| 38 | + jq -r '.assets[] | select(.name=="AREMA-ontology.ttl") | .browser_download_url') |
| 39 | + |
| 40 | + echo "📥 Downloading ontology from: ${ASSET_URL}" |
| 41 | + mkdir -p src/ontology |
| 42 | + curl -L -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 43 | + "${ASSET_URL}" -o src/ontology/AREMA-ontology.ttl |
| 44 | + |
| 45 | + echo "✅ Ontology downloaded" |
| 46 | + ls -lh src/ontology/AREMA-ontology.ttl |
| 47 | +
|
| 48 | + - name: 🐍 Set up Python |
| 49 | + uses: actions/setup-python@v5 |
| 50 | + with: |
| 51 | + python-version: '3.12' |
| 52 | + |
| 53 | + - name: 📦 Install uv |
| 54 | + run: | |
| 55 | + curl -LsSf https://astral.sh/uv/install.sh | sh |
| 56 | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
| 57 | +
|
| 58 | + - name: 🔧 Sync Python environment |
| 59 | + run: uv sync --frozen |
| 60 | + |
| 61 | + - name: ✅ SHACL Validation |
| 62 | + run: | |
| 63 | + echo "🔍 Validating ontology with SHACL shapes..." |
| 64 | + uv run python tools/python/checks/shacl.py \ |
| 65 | + src/ontology/AREMA-ontology.ttl \ |
| 66 | + src/quality-checks/skohub.shacl.ttl |
| 67 | + echo "✅ Validation passed!" |
| 68 | + |
| 69 | + - name: 💾 Upload ontology artifact |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + with: |
| 72 | + name: validated-ontology |
| 73 | + path: src/ontology/AREMA-ontology.ttl |
| 74 | + retention-days: 7 |
| 75 | + |
| 76 | + # ============================================ |
| 77 | + # JOB 2: BUILD DOCS & DEPLOY |
| 78 | + # ============================================ |
| 79 | + build-and-deploy: |
| 80 | + needs: validate |
| 81 | + runs-on: ubuntu-latest |
| 82 | + permissions: |
| 83 | + contents: write # Required to push docs back to repo |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: 🧾 Checkout repository |
| 87 | + uses: actions/checkout@v4 |
| 88 | + with: |
| 89 | + fetch-depth: 0 # Full history for proper git operations |
| 90 | + |
| 91 | + - name: 📥 Download validated ontology |
| 92 | + uses: actions/download-artifact@v4 |
| 93 | + with: |
| 94 | + name: validated-ontology |
| 95 | + path: src/ontology |
| 96 | + |
| 97 | + - name: 📚 Build Documentation |
| 98 | + run: | |
| 99 | + echo "🏗️ Generating documentation with SKOHub..." |
| 100 | + |
| 101 | + # Prepare environment |
| 102 | + mkdir -p docs |
| 103 | + echo "BASEURL=/" > .env |
| 104 | + echo "PATH_PREFIX=/" >> .env |
| 105 | + echo "GATSBY_BASE_PATH=/" >> .env |
| 106 | + |
| 107 | + # Preserve CNAME if it exists |
| 108 | + [ -f docs/CNAME ] && cp docs/CNAME /tmp/CNAME || true |
| 109 | + |
| 110 | + # Build using volumes (simpler than docker create/cp/start) |
| 111 | + docker run --rm \ |
| 112 | + -v $(pwd)/src/ontology:/app/data \ |
| 113 | + -v $(pwd)/.env:/app/.env \ |
| 114 | + -v $(pwd)/tools/skohub-vocabs/config.yaml:/app/config.yaml \ |
| 115 | + -v $(pwd)/tools/skohub-vocabs/src:/app/src/custom \ |
| 116 | + -v $(pwd)/tools/skohub-vocabs/static:/app/static/custom \ |
| 117 | + -v $(pwd)/docs:/app/public \ |
| 118 | + ghcr.io/sdsc-ordes/skohub-vocabs:v0.3.2 \ |
| 119 | + npm run build |
| 120 | + |
| 121 | + # Restore CNAME |
| 122 | + [ -f /tmp/CNAME ] && mv /tmp/CNAME docs/CNAME || true |
| 123 | + |
| 124 | + echo "✅ Documentation generated!" |
| 125 | +
|
| 126 | + - name: 💾 Commit Documentation & Ontology |
| 127 | + run: | |
| 128 | + git config user.name "github-actions[bot]" |
| 129 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 130 | + |
| 131 | + # Pull latest changes to avoid race conditions |
| 132 | + git pull --rebase origin ${{ github.ref_name }} || true |
| 133 | + |
| 134 | + # Add both docs and the ontology file (updates src/ontology/) |
| 135 | + git add docs src/ontology/AREMA-ontology.ttl |
| 136 | + |
| 137 | + # Only commit if there are changes |
| 138 | + if ! git diff --cached --quiet; then |
| 139 | + RELEASE_TAG="${{ github.event.release.tag_name || inputs.release_tag || 'manual' }}" |
| 140 | + git commit -m "Update ontology and docs from release ${RELEASE_TAG} [skip ci]" |
| 141 | + git push |
| 142 | + echo "✅ Documentation and ontology committed" |
| 143 | + else |
| 144 | + echo "ℹ️ No changes to commit" |
| 145 | + fi |
| 146 | +
|
| 147 | + - name: 🚀 Deploy to Fuseki |
| 148 | + env: |
| 149 | + FUSEKI_SPARQL_ENDPOINT: ${{ secrets.FUSEKI_SPARQL_ENDPOINT }} |
| 150 | + FUSEKI_USERNAME: ${{ secrets.FUSEKI_USERNAME }} |
| 151 | + FUSEKI_PASSWORD: ${{ secrets.FUSEKI_PASSWORD }} |
| 152 | + GRAPH_URI: ${{ secrets.GRAPH_URI }} |
| 153 | + run: | |
| 154 | + set -euo pipefail |
| 155 | + |
| 156 | + timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 157 | + ARCHIVE_URI="${GRAPH_URI}/archive/${timestamp}" |
| 158 | + |
| 159 | + echo "🚀 Deploying ontology to ${FUSEKI_SPARQL_ENDPOINT}" |
| 160 | + echo "📍 Target graph: ${GRAPH_URI}" |
| 161 | + echo "💾 Backup graph: ${ARCHIVE_URI}" |
| 162 | + |
| 163 | + # Backup existing graph |
| 164 | + echo "📦 Backing up current graph..." |
| 165 | + curl -sf -u "${FUSEKI_USERNAME}:${FUSEKI_PASSWORD}" \ |
| 166 | + -X POST \ |
| 167 | + -H "Content-Type: application/sparql-update" \ |
| 168 | + --data "COPY GRAPH <${GRAPH_URI}> TO GRAPH <${ARCHIVE_URI}>" \ |
| 169 | + "${FUSEKI_SPARQL_ENDPOINT}" || echo "⚠️ No existing graph to back up" |
| 170 | + |
| 171 | + # Drop existing graph |
| 172 | + echo "🧹 Dropping existing graph..." |
| 173 | + curl -sf -u "${FUSEKI_USERNAME}:${FUSEKI_PASSWORD}" \ |
| 174 | + -X POST \ |
| 175 | + -H "Content-Type: application/sparql-update" \ |
| 176 | + --data "DROP GRAPH <${GRAPH_URI}>" \ |
| 177 | + "${FUSEKI_SPARQL_ENDPOINT}" |
| 178 | + |
| 179 | + # Upload new ontology |
| 180 | + echo "📤 Uploading ontology..." |
| 181 | + curl -sf -u "${FUSEKI_USERNAME}:${FUSEKI_PASSWORD}" \ |
| 182 | + -X POST \ |
| 183 | + -H "Content-Type: text/turtle" \ |
| 184 | + --data-binary "@src/ontology/AREMA-ontology.ttl" \ |
| 185 | + "${FUSEKI_SPARQL_ENDPOINT}?graph=${GRAPH_URI}" |
| 186 | + |
| 187 | + echo "✅ Deployment completed successfully!" |
0 commit comments