-
Notifications
You must be signed in to change notification settings - Fork 3
96 lines (83 loc) · 3.19 KB
/
Copy pathcheck-models.yml
File metadata and controls
96 lines (83 loc) · 3.19 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
name: Check modified models
on:
push:
branches: [master]
jobs:
check-models:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get modified model files
id: changed
run: |
files=$(git diff --name-only --diff-filter=ACMR HEAD~1 HEAD -- 'models/*.ttl' | tr '\n' ' ')
echo "files=$files" >> "$GITHUB_OUTPUT"
- name: Set up Java
if: steps.changed.outputs.files != ''
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: Install Jena
if: steps.changed.outputs.files != ''
run: |
wget -q https://archive.apache.org/dist/jena/binaries/apache-jena-6.0.0.tar.gz
tar xzf apache-jena-6.0.0.tar.gz
echo "$PWD/apache-jena-6.0.0/bin" >> "$GITHUB_PATH"
- name: Run SPARQL checks
if: steps.changed.outputs.files != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for model in ${{ steps.changed.outputs.files }}; do
for query in sparql/*.rq; do
query_name=$(basename "$query")
# Run query on current version, stripping \r from CSV output
csv_current=$(arq --data="$model" --query="$query" --results=csv 2>/dev/null | tr -d '\r')
header=$(echo "$csv_current" | head -1)
current_rows=$(echo "$csv_current" | tail -n +2 | grep -v '^$' || true)
# Run query on previous version of model
prev_ttl=$(mktemp --suffix=.ttl)
if git show HEAD~1:"$model" > "$prev_ttl" 2>/dev/null; then
prev_rows=$(arq --data="$prev_ttl" --query="$query" --results=csv 2>/dev/null | tr -d '\r' | tail -n +2 | grep -v '^$' || true)
else
prev_rows=""
fi
rm -f "$prev_ttl"
# Find rows present in current but not in previous
new_rows=$(comm -23 \
<(echo "$current_rows" | grep -v '^$' | sort) \
<(echo "$prev_rows" | grep -v '^$' | sort))
if [ -n "$new_rows" ]; then
md_table=$(printf '%s\n%s' "$header" "$new_rows" | awk -F',' '
NR==1 {
printf "| "
for (i=1; i<=NF; i++) printf "%s | ", $i
printf "\n| "
for (i=1; i<=NF; i++) printf "--- | "
printf "\n"
}
NR>1 {
printf "| "
for (i=1; i<=NF; i++) printf "%s | ", $i
printf "\n"
}
')
title="Model check failed: ${query_name} on $(basename "$model")"
body=$(cat <<EOF
**Query:** \`${query_name}\`
**Model:** \`${model}\`
**Commit:** ${{ github.sha }}
**New results:**
${md_table}
EOF
)
gh issue create \
--title "$title" \
--body "$body" \
--assignee balhoff,kltm,vanaukenk,pgaudet
fi
done
done