Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into validation-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Dec 5, 2023
2 parents aa59bca + 76352a5 commit 23357ab
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 43 deletions.
8 changes: 6 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": [],
"privatePackages": {
"tag": true,
"version": true
}
}
14 changes: 11 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
docker:
runs-on: ubuntu-latest

env:
DOCKER_IMAGE: ghcr.io/zazuko/cube-link

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -32,11 +35,16 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
uses: zazuko/action-docker-meta@main
id: docker_meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/zazuko/cube-link
include-pipeline-id: true
images: "${{ env.DOCKER_IMAGE }}"
tags: |
type=ref,event=branch
type=semver,prefix=v,pattern={{version}}
type=semver,prefix=v,pattern={{major}}.{{minor}}
type=semver,prefix=v,pattern={{major}}
type=sha
- name: Build and push Docker images
id: docker_build
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
# This allow GitHub Actions to trigger the jobs for tags if needed
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.GH_APP_ID }}
private_key: ${{ secrets.GH_PRIVATE_KEY }}

- name: Checkout Repo
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}

- name: Setup Node.js
uses: actions/setup-node@v3
Expand All @@ -23,7 +35,11 @@ jobs:
- name: Install Dependencies
run: npm ci

- name: Create Release Pull Request
- name: Create Release Pull Request or Create a GitHub Release + tag
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# cube-link

## 0.1.3

### Patch Changes

- 86a40d7: In the CI, make sure to pull the Git repository with the token, to make sure it is able to trigger tags GitHub Actions workflows
- 7777e94: Generate Docker tags and labels using docker/metadata-action

## 0.1.2

### Patch Changes

- 6b78238: Bumping version only to trigger CI

## 0.1.1

### Patch Changes

- 09e2f3d: Forward profiles directly from GitHub

## 0.1.0

### Minor Changes

- 6d65dca: Adjust shape base to match how they are deployed (re #94)

### Patch Changes

- a38baff: Fixes the problem that validation script did not correctly target cube observations
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ In this repository we develop the *Cube Schema* model.

DRAFT: https://zazuko.github.io/cube-link/

## Validation shapes

The [validation](validation) directory contains various SHACL Shapes which can be used to ensure the correctness of datasets, cubes, hierarchies, and other.

They can be retrieved from the web using an URI in the form of `https://cube.link/{VERSION}/shape/{CONSTRAINT}`, where the `{CONSTRAINT}` variable is replaced with any of the shape documents (without `.ttl`) and the `{VERSION}` variable is replaced with any [tag name](https://github.com/zazuko/cube-link/tags) or the word `latest`.
It is recommended to always use a specific version to avoid breaking changes.

For example, to get version 0.0.4 of `standalone-cube-constraint.ttl`, fetch https://cube.link/v0.0.4/shape/standalone-cube-constraint .

Otherwise, to get the latest version, fetch https://cube.link/latest/shape/standalone-cube-constraint instead.

## How to Contribute

Please open [Issues](https://github.com/zazuko/cube-link/issues) on this repository or provide PRs for contributions.
Expand Down
6 changes: 4 additions & 2 deletions documentation/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ To provide a generic solution that works for all numbers and IRIs, _Cube Schema_
<observation2> a cube:Observation;
ex:literalDimension ""^^cube:Undefined.
## Snippet for for the according shape:
## Snippet for the according shape:
[
sh:path ex:literalDimension;
sh:nodeKind sh:Literal;
sh:or([
sh:datatype xsd:string
sh:datatype xsd:string ; sh:minLength 1
], [
sh:datatype cube:Undefined
])
Expand All @@ -191,6 +191,8 @@ To provide a generic solution that works for all numbers and IRIs, _Cube Schema_

If it is necessary to state why the value is `cube:Undefined`, annotations should be used.

Additional constraints (like `sh:minLength` in the example) may be placed within the _real_ data type so that they do not apply to undefined values.


## Metadata

Expand Down
21 changes: 12 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "cube-link",
"version": "0.0.5",
"version": "0.1.3",
"private": true,
"description": "Cube Schema",
"main": "validate.js",
"scripts": {
"build": "./build.sh",
"trifid": "trifid --verbose --config=trifid/config.json",
"trifid:local": "trifid --verbose --config=trifid/config.local.json",
"test": "standard",
"validation-test": "mocha"
"release": "changeset tag"
},
"bin": {
"cube-link": "bin/cube-link.js"
Expand Down
22 changes: 21 additions & 1 deletion trifid/redirect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
const { Readable } = require('stream')
const { fetchBuilder, MemoryCache } = require('node-fetch-cache')

/**
Expand Down Expand Up @@ -54,7 +55,26 @@ function factory () {
}
}
if (shapePath) {
return res.redirect(`https://raw.githubusercontent.com/zazuko/cube-link/${versionPath}/validation/${shapePath}.ttl`)
try {
const rawGithub = await fetch(`https://raw.githubusercontent.com/zazuko/cube-link/${versionPath}/validation/${shapePath}.ttl`)
if (rawGithub.ok) {
res.set('Content-Type', 'text/turtle')
} else {
res.status(500)
}
// if the shape does not exist, we return a 404
if (rawGithub.status === 404) {
return res.sendStatus(404)
}
/** @type {any | null} */
const body = rawGithub.body
if (!rawGithub.body) {
throw new Error('No body')
}
return Readable.fromWeb(body).pipe(res)
} catch (e) {
return res.status(502).send(`Error fetching shape: ${e.message}`)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The cube and shape are connected on the fly with triples in the following patter
_:b1 a sh:NodeShape;
sh:targetNode ?cube;
sh:property [
sh:node ?observationShape; # from ?cube cube:observationShape ?observationShape
sh:node ?observationShape; # from ?cube cube:observationConstraint ?observationShape
sh:path (cube:observationSet cube:observation);
].
Expand All @@ -32,7 +32,7 @@ async function validateCube (cube, shape, factory = rdf) {
clownface({ dataset: shape, term: rdf.blankNode() })
.addOut(ns.sh.targetNode, cubeRoot)
.addOut(ns.sh.property, null, property => {
property.addOut(ns.sh.node, cubeRoot.out(ns.cube.observationShape))
property.addOut(ns.sh.node, cubeRoot.out(ns.cube.observationConstraint))
property.addList(ns.sh.path, [ns.cube.observationSet, ns.cube.observation])
})

Expand Down
6 changes: 3 additions & 3 deletions validation/basic-cube-constraint-ml.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@base <http://example.org/> .
@base <https://cube.link/shape/basic-cube-constraint-ml#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
Expand Down Expand Up @@ -46,7 +46,7 @@
sh:path sh:property ;
sh:minCount 3 ;
sh:message "cube:Constraint needs at least a certain amount of sh:properties"
] ,
] ,
[
# we assume at least 3 dimensions, otherwise we would have an empty list of dimensions
# one for cube:observedBy, one for rdf:type and at least one cube dimension
Expand All @@ -69,4 +69,4 @@
sh:in (rdf:type cube:observedBy);
]
)
] .
] .
4 changes: 2 additions & 2 deletions validation/basic-cube-constraint.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@base <http://example.org/> .
@base <https://cube.link/shape/basic-cube-constraint#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
Expand Down Expand Up @@ -46,4 +46,4 @@
sh:path sh:property ;
sh:minCount 3 ;
sh:message "cube:Constraint needs at least a certain amount of sh:properties"
] .
] .
16 changes: 8 additions & 8 deletions validation/datacatalog-constraint.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@base <http://example.org/> .
@base <https://cube.link/shape/datacatalog-constraint#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
Expand Down Expand Up @@ -114,33 +114,33 @@ PREFIX dcterms: <http://purl.org/dc/terms/>
sh:minCount 1 ;
sh:nodeKind sh:IRI ;
sh:message "schema:Dataset needs a schema:hasPart"
] ;
] ;
sh:property [
sh:path void:sparqlEndpoint ;
sh:minCount 1 ;
sh:nodeKind sh:IRI ;
sh:message "schema:Dataset needs a void:sparqlEndpoint"
] ;
] ;
sh:property [
sh:path void:rootResource ;
sh:minCount 1 ;
sh:nodeKind sh:IRI ;
sh:message "schema:Dataset needs a void:rootResource"
] ;
] ;
sh:property [
sh:path void:exampleResource ;
sh:minCount 1 ;
sh:nodeKind sh:IRI ;
sh:message "schema:Dataset needs a void:exampleResource"
] ;
] ;
sh:property [
sh:path dcat:distribution ;
sh:minCount 1 ;
sh:nodeKind sh:IRI ;
sh:node <DCATDistributionShape>;
sh:message "schema:Dataset needs a valid dcat:Distribution"
] ;
] ;

.

<DCATDistributionShape>
Expand Down Expand Up @@ -171,4 +171,4 @@ PREFIX dcterms: <http://purl.org/dc/terms/>
sh:nodeKind sh:IRI ;
sh:message "dcat:Distribution needs a valid dcat:downloadURL"
] ;
.
.
6 changes: 3 additions & 3 deletions validation/standalone-constraint-constraint.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@base <http://example.org/> .
@base <https://cube.link/shape/standalone-constraint-constraint#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
Expand Down Expand Up @@ -88,7 +88,7 @@
]
);
];

sh:property [
sh:message "needs a sh:datatype, sh:nodeKind or sh:datatype within sh:or (...)" ;
sh:or(
Expand Down Expand Up @@ -214,4 +214,4 @@
sh:node <NextInHierarchy>;
sh:minCount 1;
sh:message "inHierarchy requires a conform nextInHierarchy"
] .
] .
8 changes: 4 additions & 4 deletions validation/standalone-cube-constraint.ttl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@base <http://example.org/> .
@base <https://cube.link/shape/standalone-cube-constraint#> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
Expand All @@ -9,7 +9,7 @@

#
# This is the bare minimal SHACL shape for validating a cube.
# All cubes should pass this validation.
# All cubes should pass this validation.
# It does not validate the constraints
#

Expand Down Expand Up @@ -82,7 +82,7 @@
# optional, but recommended
sh:path cube:observationConstraint ;
sh:message "cube:Cube must point to a valid constraint"
]
]
.

<ObservationSetShape>
Expand All @@ -104,4 +104,4 @@
sh:minCount 1 ;
sh:nodeKind sh:IRI ;
sh:message "cube:Observation requires cube:observedBy"
] .
] .

0 comments on commit 23357ab

Please sign in to comment.