Skip to content

Commit 4102307

Browse files
committed
Query KG data from GraphDB SPARQL endpoint on method build
1 parent 56627ba commit 4102307

File tree

8 files changed

+307
-55
lines changed

8 files changed

+307
-55
lines changed

.github/workflows/build-prod.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ jobs:
5353
working-directory: web
5454

5555
- name: Build 11ty
56+
id: build
5657
run: npx @11ty/eleventy
5758
working-directory: web
59+
env:
60+
NODE_ENV: production
61+
KG_AUTH: ${{ secrets.KG_AUTH }}
62+
continue-on-error: false
63+
64+
- name: Check for KG fallback usage
65+
run: |
66+
if grep -q "Using fallback data" web/_site/index.html; then
67+
echo "WARNING: Using fallback KG data" >> $GITHUB_STEP_SUMMARY
68+
echo "::warning::Using fallback KG data"
69+
fi
5870
5971
- name: Verify build
6072
run: ls -la ./_site
@@ -67,6 +79,22 @@ jobs:
6779
sudo chmod 600 ~/.ssh/do_uxm_prod
6880
ssh-keyscan -H "24.199.98.130" > ~/.ssh/known_hosts
6981
82+
- name: Manage fallback data directory
83+
run: |
84+
# Create directory if it doesn't exist
85+
ssh -i ~/.ssh/do_uxm_prod prod@24.199.98.130 "mkdir -p /var/www/uxm/fallback-data"
86+
87+
# Keep only the 2 most recent backup files
88+
ssh -i ~/.ssh/do_uxm_prod prod@24.199.98.130 "ls -t /var/www/uxm/fallback-data/kg-data-*.json | tail -n +3 | xargs -r rm"
89+
90+
- name: Upload fallback data
91+
run: |
92+
if [ -f "web/_data/fallback-data/kg-data.json" ]; then
93+
# Add timestamp to filename to keep history
94+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
95+
scp -i ~/.ssh/do_uxm_prod web/_data/fallback-data/kg-data.json prod@24.199.98.130:/var/www/uxm/fallback-data/kg-data-${TIMESTAMP}.json
96+
fi
97+
7098
- name: Clean & FTP Upload
7199
run: |
72100
ssh -i ~/.ssh/do_uxm_prod prod@24.199.98.130 "rm -rf /var/www/uxm/html/*"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ _local
66
/node_modules
77

88
# Local development directories
9-
/_kg-integration
9+
/_kg-integration/
10+
/_kg-integration/**

kg/README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,62 @@ To stop GraphDB, run:
2525
docker compose down
2626
```
2727

28-
Your data in `./data/` stays safe and portable.
28+
Your data in `./data/` stays safe and portable.
29+
30+
## Test Queries
31+
32+
Query to test a tunnel to `kg.uxmethods.org` with basic authentication.
33+
34+
### Method Centrality
35+
36+
```bash
37+
curl -u "username:password" \
38+
-X POST http://kg.uxmethods.org/repositories/uxm \
39+
-H "Content-Type: application/x-www-form-urlencoded" \
40+
-H "Accept: application/sparql-results+json" \
41+
--data-urlencode "query=
42+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
43+
PREFIX : <https://uxmethods.org/>
44+
PREFIX uxmo: <https://uxmethods.org/ontology/>
45+
46+
SELECT ?method ?label (COUNT(?transput) AS ?centrality)
47+
WHERE {
48+
?methodA skos:prefLabel ?label.
49+
{?methodA uxmo:hasInput ?transput.}
50+
UNION
51+
{?methodA uxmo:hasOutput ?transput.}
52+
BIND(?methodA AS ?method)
53+
}
54+
GROUP BY ?method ?label
55+
ORDER BY DESC (?centrality)
56+
"
57+
```
58+
59+
### Shared Output
60+
61+
```bash
62+
curl -u "username:password" \
63+
-X POST http://kg.uxmethods.org/repositories/uxm \
64+
-H "Content-Type: application/x-www-form-urlencoded" \
65+
-H "Accept: application/sparql-results+json" \
66+
--data-urlencode "query=
67+
PREFIX : <https://uxmethods.org/>
68+
PREFIX uxmo: <https://uxmethods.org/ontology/>
69+
70+
SELECT ?origin ?destination (COUNT(?output) AS ?sharedOutputCount)
71+
(GROUP_CONCAT(DISTINCT ?output; SEPARATOR=',') AS ?sharedOutput)
72+
WHERE {
73+
?origin uxmo:hasOutput ?output.
74+
?destination uxmo:hasInput ?output.
75+
}
76+
GROUP BY ?origin ?destination
77+
ORDER BY DESC(?sharedOutputCount)
78+
"
79+
```
80+
81+
Replace `username` and `password` with your actual credentials.
82+
83+
### Notes
84+
85+
- `-u` The most basic curl authentication option is -u / --user. It accepts an argument that is the username and password, colon separated.
86+
- `-X` Tell curl to change the method into something else by using the -X or --request command-line options followed by the actual method name.

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/.eleventy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default function (eleventyConfig) {
3030

3131
// Watch all asset directories for changes
3232
eleventyConfig.addWatchTarget('_src/**/*') // Watch everything in _src
33+
eleventyConfig.watchIgnores.add('_data/fallback-data/**/*') // Ignore fallback data directory
3334

3435
eleventyConfig.setServerOptions({
3536
showAllHosts: true,

web/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
# Dotenv and similar local-only files
1212
*.local
13+
_data/fallback-data/
14+
_data/fallback-data/**
1315

1416
# Static site
1517
_site

0 commit comments

Comments
 (0)