forked from OP-TED/model2owl-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
408 lines (357 loc) · 14.9 KB
/
diff-combined.yml
File metadata and controls
408 lines (357 loc) · 14.9 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
name: RDF Diff
on:
workflow_call:
inputs:
modules:
description: 'JSON array of module names'
required: false
type: string
revision_to_compare:
description: 'Version to compare against (branch/tag/commit)'
required: false
type: string
revision_repo_url:
description: 'External repository URL (optional)'
required: false
type: string
from_workflow_artifacts:
description: 'Use OWL/SHACL from workflow artifacts (true) or committed files (false)'
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
modules:
description: 'Comma-separated module names (empty = all modules)'
required: false
type: string
default: ''
revision_to_compare:
description: 'Version to compare against (e.g., main, release/5.0.0)'
required: false
type: string
default: 'develop'
revision_repo_url:
description: 'External repository URL (leave empty for same repo)'
required: false
type: string
default: ''
old_ontology_dir:
description: 'Root directory for old OWL/SHACL files'
required: false
type: string
default: 'implementation'
new_ontology_dir:
description: 'Root directory for new OWL/SHACL files'
required: false
type: string
default: 'implementation'
output_dir:
description: 'Output directory for diff reports'
required: false
type: string
default: 'diff-reports'
env:
# Default directory for module implementations
IMPL_DIR: implementation
# Path to diff configuration file
DIFF_CONFIG: .github/workflows/diff-config.env
jobs:
# Resolve modules: single from workflow_call, or list/auto-detect from dispatch
resolve:
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.resolve.outputs.modules }}
count: ${{ steps.resolve.outputs.count }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
${{ env.DIFF_CONFIG }}
${{ env.IMPL_DIR }}
- name: Resolve modules
id: resolve
run: |
# Load config
source "${DIFF_CONFIG}" 2>/dev/null || true
INPUT='${{ inputs.modules }}'
if [ -n "$INPUT" ] && [[ "$INPUT" == \[* ]]; then
# Already JSON array (from workflow_call)
MODULES_JSON="$INPUT"
elif [ -n "$INPUT" ]; then
# Comma-separated string (from workflow_dispatch)
MODULES_JSON=$(echo "$INPUT" | jq -Rc 'split(",") | map(gsub("^\\s+|\\s+$";""))')
elif [ -n "${MODULES:-}" ]; then
# From config file
MODULES_JSON=$(echo "$MODULES" | jq -Rc 'split(",") | map(gsub("^\\s+|\\s+$";""))')
else
# Auto-detect from NEW_ONTOLOGY_DIR
NEW_DIR="${NEW_ONTOLOGY_DIR:-${IMPL_DIR}}"
MODULES_JSON=$(ls -d ${NEW_DIR}/*/owl_ontology 2>/dev/null | cut -d/ -f2 | jq -Rsc 'split("\n") | map(select(. != ""))')
fi
COUNT=$(echo "$MODULES_JSON" | jq length)
echo "Resolved $COUNT module(s): $MODULES_JSON"
echo "modules=${MODULES_JSON}" >> $GITHUB_OUTPUT
echo "count=$COUNT" >> $GITHUB_OUTPUT
# Compare old vs new OWL/SHACL and generate diff reports
diff:
needs: resolve
strategy:
fail-fast: false
matrix:
module: ${{ fromJson(needs.resolve.outputs.modules) }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed to fetch old version
- name: Download transform artifacts
if: inputs.from_workflow_artifacts == true
uses: actions/download-artifact@v4
with:
pattern: transform-*
path: new-artifacts/
merge-multiple: true
- name: Load configuration
id: config
run: |
MODULE="${{ matrix.module }}"
echo "module=${MODULE}" >> $GITHUB_OUTPUT
# Load diff-config if exists
if [ -f "${DIFF_CONFIG}" ]; then
echo "Loading diff-config..."
source "${DIFF_CONFIG}"
fi
# Priority: inputs > config file > vars > defaults
# Use ${VAR-default} (no colon) so empty config values override vars
REV="${{ inputs.revision_to_compare }}"
if [ -z "$REV" ]; then
REV="${REVISION_TO_COMPARE_COMMIT_ID-${{ vars.REVISION_TO_COMPARE_COMMIT_ID }}}"
fi
REV="${REV:-develop}"
echo "revision=${REV}" >> $GITHUB_OUTPUT
REPO="${{ inputs.revision_repo_url }}"
if [ -z "$REPO" ] && [ -n "${REVISION_TO_COMPARE_REPO_URL+set}" ]; then
# Config file explicitly set (even if empty) - use that
REPO="${REVISION_TO_COMPARE_REPO_URL}"
elif [ -z "$REPO" ]; then
# Fall back to vars
REPO="${{ vars.REVISION_TO_COMPARE_REPO_URL }}"
fi
echo "repo_url=${REPO}" >> $GITHUB_OUTPUT
# Directory configuration (priority: inputs > config > vars > default)
OLD_DIR="${{ inputs.old_ontology_dir }}"
if [ -z "$OLD_DIR" ] || [ "$OLD_DIR" == "implementation" ]; then
OLD_DIR="${OLD_ONTOLOGY_DIR:-${{ vars.OLD_ONTOLOGY_DIR }}}"
fi
OLD_DIR="${OLD_DIR:-${IMPL_DIR}}"
echo "old_dir=${OLD_DIR}" >> $GITHUB_OUTPUT
NEW_DIR="${{ inputs.new_ontology_dir }}"
if [ -z "$NEW_DIR" ] || [ "$NEW_DIR" == "implementation" ]; then
NEW_DIR="${NEW_ONTOLOGY_DIR:-${{ vars.NEW_ONTOLOGY_DIR }}}"
fi
NEW_DIR="${NEW_DIR:-${IMPL_DIR}}"
echo "new_dir=${NEW_DIR}" >> $GITHUB_OUTPUT
OUTDIR="${{ inputs.output_dir }}"
if [ -z "$OUTDIR" ] || [ "$OUTDIR" == "diff-reports" ]; then
OUTDIR="${RDF_DIFF_OUTDIR:-${{ vars.RDF_DIFF_OUTDIR }}}"
fi
OUTDIR="${OUTDIR:-diff-reports}"
echo "outdir=${OUTDIR}" >> $GITHUB_OUTPUT
# Derive file paths from module name and directories
echo "old_ontology=${OLD_DIR}/${MODULE}/owl_ontology/${MODULE}.ttl" >> $GITHUB_OUTPUT
echo "old_shacl=${OLD_DIR}/${MODULE}/shacl_shapes/${MODULE}_shapes.ttl" >> $GITHUB_OUTPUT
echo "new_ontology=${NEW_DIR}/${MODULE}/owl_ontology/${MODULE}.ttl" >> $GITHUB_OUTPUT
echo "new_shacl=${NEW_DIR}/${MODULE}/shacl_shapes/${MODULE}_shapes.ttl" >> $GITHUB_OUTPUT
echo "Configuration loaded:"
echo " module: ${MODULE}"
echo " revision: ${REV}"
echo " repo_url: ${REPO:-'(same repo)'}"
echo " old_dir: ${OLD_DIR}"
echo " new_dir: ${NEW_DIR}"
echo " outdir: ${RDF_DIFF_OUTDIR}"
- name: Fetch old TTL files
id: fetch_old
run: |
MODULE="${{ steps.config.outputs.module }}"
REVISION="${{ steps.config.outputs.revision }}"
REPO_URL="${{ steps.config.outputs.repo_url }}"
OLD_ONTOLOGY="${{ steps.config.outputs.old_ontology }}"
OLD_SHACL="${{ steps.config.outputs.old_shacl }}"
mkdir -p old-files
if [ -n "${REPO_URL}" ]; then
echo "Fetching from external repo: ${REPO_URL}@${REVISION}"
git clone --depth 1 --branch "${REVISION}" "${REPO_URL}" old-repo || {
git clone "${REPO_URL}" old-repo
cd old-repo && git checkout "${REVISION}" && cd ..
}
cp "old-repo/${OLD_ONTOLOGY}" old-files/old_ontology.ttl
cp "old-repo/${OLD_SHACL}" old-files/old_shacl.ttl
rm -rf old-repo
else
echo "Fetching from current repo at ${REVISION}"
# Try origin/REVISION for branches, fall back to REVISION for tags/commits
REF="${REVISION}"
if git show-ref --verify --quiet "refs/remotes/origin/${REVISION}"; then
REF="origin/${REVISION}"
fi
echo "Using ref: ${REF}"
git show "${REF}:${OLD_ONTOLOGY}" > old-files/old_ontology.ttl || {
echo "::error::Comparison with module ${MODULE} failed: No preexisting files to compare to (${OLD_ONTOLOGY} not found at ${REF})"
exit 1
}
git show "${REF}:${OLD_SHACL}" > old-files/old_shacl.ttl || {
echo "::error::Comparison with module ${MODULE} failed: No preexisting files to compare to (${OLD_SHACL} not found at ${REF})"
exit 1
}
fi
echo "OLD_ONTOLOGY_PATH=old-files/old_ontology.ttl" >> $GITHUB_ENV
echo "OLD_SHACL_PATH=old-files/old_shacl.ttl" >> $GITHUB_ENV
- name: Prepare new TTL files
run: |
MODULE="${{ steps.config.outputs.module }}"
NEW_ONTOLOGY="${{ steps.config.outputs.new_ontology }}"
NEW_SHACL="${{ steps.config.outputs.new_shacl }}"
# If artifact was downloaded, use those files
if [ -d "new-artifacts" ]; then
echo "Using new TTL files from artifact"
NEW_ONTOLOGY_PATH=$(find new-artifacts -name "${MODULE}.ttl" -path "*/owl_ontology/*" | head -1)
NEW_SHACL_PATH=$(find new-artifacts -name "${MODULE}_shapes.ttl" | head -1)
else
echo "Using new TTL files from repository"
NEW_ONTOLOGY_PATH="${NEW_ONTOLOGY}"
NEW_SHACL_PATH="${NEW_SHACL}"
fi
echo "NEW_ONTOLOGY_PATH=${NEW_ONTOLOGY_PATH}" >> $GITHUB_ENV
echo "NEW_SHACL_PATH=${NEW_SHACL_PATH}" >> $GITHUB_ENV
echo "New ontology: ${NEW_ONTOLOGY_PATH}"
echo "New SHACL: ${NEW_SHACL_PATH}"
- name: Clone model2owl
run: |
git clone --branch develop https://github.com/OP-TED/model2owl.git
echo "model2owl/" >> .gitignore
- name: Install dependencies
run: |
cd model2owl
make install
- name: Merge OWL and SHACL for old version
run: |
cd model2owl
make merge-owl-shacl \
MERGE_ONTOLOGY_FILE=../${OLD_ONTOLOGY_PATH} \
MERGE_SHAPES_FILE=../${OLD_SHACL_PATH} \
MERGE_OUTPUT_FILE=../old_combined.ttl
echo "MERGE_OLD=old_combined.ttl" >> $GITHUB_ENV
- name: Merge OWL and SHACL for new version
run: |
cd model2owl
make merge-owl-shacl \
MERGE_ONTOLOGY_FILE=../${NEW_ONTOLOGY_PATH} \
MERGE_SHAPES_FILE=../${NEW_SHACL_PATH} \
MERGE_OUTPUT_FILE=../new_combined.ttl
echo "MERGE_NEW=new_combined.ttl" >> $GITHUB_ENV
- name: Generate diff reports
run: |
MODULE="${{ steps.config.outputs.module }}"
OUTDIR="${{ steps.config.outputs.outdir }}/${MODULE}"
mkdir -p "${OUTDIR}"
cd model2owl
# Generate AsciiDoc report
make run-rdf-diff \
RDF_DIFF_FILE1=../${MERGE_OLD} \
RDF_DIFF_FILE2=../${MERGE_NEW} \
RDF_DIFF_OUTDIR=../${OUTDIR} \
RDF_DIFF_AP=owl-core-en-only \
RDF_DIFF_TEMPLATE=asciidoc
# Generate JSON report
make run-rdf-diff \
RDF_DIFF_FILE1=../${MERGE_OLD} \
RDF_DIFF_FILE2=../${MERGE_NEW} \
RDF_DIFF_OUTDIR=../${OUTDIR} \
RDF_DIFF_AP=owl-core-en-only \
RDF_DIFF_TEMPLATE=json
echo "DIFF_OUTDIR=${OUTDIR}" >> $GITHUB_ENV
- name: Install AsciiDoctor
run: |
sudo apt-get update
sudo apt-get install -y asciidoctor
- name: Convert AsciiDoc to HTML
run: |
if [ -f "${DIFF_OUTDIR}/diff.asciidoc" ]; then
asciidoctor \
--attribute source-highlighter=rouge \
--attribute toc=left \
--attribute toclevels=3 \
--attribute sectlinks \
--attribute sectanchors \
--attribute icons=font \
--out-file "${DIFF_OUTDIR}/diff.html" \
"${DIFF_OUTDIR}/diff.asciidoc"
echo "Generated ${DIFF_OUTDIR}/diff.html"
fi
- name: Upload diff artifact
uses: actions/upload-artifact@v4
with:
name: diff-${{ matrix.module }}
path: ${{ steps.config.outputs.outdir }}/${{ matrix.module }}/
retention-days: 1
# Commit results only when triggered manually (not from workflow_call)
commit_dispatch:
if: github.event_name == 'workflow_dispatch' && !cancelled()
needs: [resolve, diff]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
pattern: diff-*
path: artifacts/
- name: Merge and commit diff reports
run: |
# Load config for outdir
source "${DIFF_CONFIG}" 2>/dev/null || true
OUTDIR="${RDF_DIFF_OUTDIR:-diff-reports}"
# Track which modules had successful diff artifacts
SUCCESSFUL_MODULES=""
mkdir -p "$OUTDIR"
for diff_dir in artifacts/diff-*/; do
if [ -d "$diff_dir" ]; then
module=$(basename "$diff_dir" | sed 's/diff-//')
SUCCESSFUL_MODULES="${SUCCESSFUL_MODULES} ${module}"
mkdir -p "$OUTDIR/$module"
cp -r "${diff_dir}"* "$OUTDIR/$module/" 2>/dev/null || true
fi
done
echo "SUCCESSFUL_DIFF_MODULES=${SUCCESSFUL_MODULES}" >> $GITHUB_ENV
rm -rf artifacts/
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$OUTDIR"
git commit -m "chore(ci): diff ${{ needs.resolve.outputs.count }} module(s) #${{ github.run_number }} [skip ci]" || echo "No changes to commit"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate workflow summary
run: |
MODULES_JSON='${{ needs.resolve.outputs.modules }}'
COUNT='${{ needs.resolve.outputs.count }}'
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
OUTDIR="${RDF_DIFF_OUTDIR:-diff-reports}"
cat >> $GITHUB_STEP_SUMMARY << EOF
## ${{ github.workflow }} - Run #${{ github.run_number }}
**Modules compared:** ${COUNT}
EOF
echo "$MODULES_JSON" | jq -r '.[]' | while read module; do
if [[ " ${SUCCESSFUL_DIFF_MODULES} " =~ " ${module} " ]]; then
echo "- ${module} → [${OUTDIR}/${module}/](${REPO_URL}/tree/${{ github.ref_name }}/${OUTDIR}/${module})" >> $GITHUB_STEP_SUMMARY
else
echo "- ${module} — No preexisting files to compare to" >> $GITHUB_STEP_SUMMARY
fi
done
cat >> $GITHUB_STEP_SUMMARY << EOF
**Commit:** [Diff reports](${REPO_URL}/commits/${{ github.ref_name }})
EOF