Skip to content

Commit 659fe55

Browse files
authored
Merge pull request #1134 from bact/use-spdx3-validate
Add spdx3-validate to examples validation workflow
2 parents 2eeb71c + ba1aeff commit 659fe55

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

.github/workflows/validate_examples.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
cache: "pip"
2222
- name: Install Python dependencies
2323
run: |
24-
python3 -m pip install check-jsonschema==0.29.4 pyshacl==0.29.0
24+
python3 -m pip install check-jsonschema==0.31.0 pyshacl==0.29.1 spdx3-validate==0.0.5
2525
- name: Install dependencies
2626
run: |
2727
sudo apt install -y gawk

bin/check-examples.sh

+49-15
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,84 @@
44
# documentation
55
#
66
# SPDX-License-Identifier: MIT
7+
# SPDX-FileCopyrightText: Copyright 2024 The SPDX Contributors
78

89
set -e
910

1011
THIS_DIR="$(dirname "$0")"
12+
MD_DIR=docs/annexes
13+
JSON_DIR=examples/jsonld
14+
1115
SPDX_VERSION="3.0.1"
1216
SCHEMA_URL="https://spdx.org/schema/${SPDX_VERSION}/spdx-json-schema.json"
1317
RDF_URL="https://spdx.org/rdf/${SPDX_VERSION}/spdx-model.ttl"
1418
CONTEXT_URL="https://spdx.org/rdf/${SPDX_VERSION}/spdx-context.jsonld"
1519

20+
# print validation setup
21+
echo "Checking examples in"
22+
echo "Snippets : $MD_DIR"
23+
echo "Files : $JSON_DIR"
24+
echo "SPDX version : $SPDX_VERSION"
25+
echo "Schema : $SCHEMA_URL"
26+
echo "Schema resolved : $(curl -I "$SCHEMA_URL" 2>/dev/null | grep -i "location:" | awk '{print $2}')"
27+
echo "RDF : $RDF_URL"
28+
echo "RDF resolved : $(curl -I "$RDF_URL" 2>/dev/null | grep -i "location:" | awk '{print $2}')"
29+
echo "Context : $CONTEXT_URL"
30+
echo "Context resolved : $(curl -I "$CONTEXT_URL" 2>/dev/null | grep -i "location:" | awk '{print $2}')"
31+
echo "$(check-jsonschema --version)"
32+
echo -n "$(pyshacl --version)"
33+
echo "spdx3-validate version: $(spdx3-validate --version)"
34+
echo ""
35+
1636
check_schema() {
37+
echo "Checking schema (check-jsonschema): $1"
1738
check-jsonschema \
18-
-v \
39+
--verbose \
1940
--schemafile $SCHEMA_URL \
2041
"$1"
2142
}
2243

2344
check_model() {
45+
echo "Checking model (pyschacl): $1"
2446
pyshacl \
25-
-s $RDF_URL \
26-
-e $RDF_URL \
47+
--shacl $RDF_URL \
48+
--ont-graph $RDF_URL \
2749
"$1"
2850
}
2951

52+
check_spdx() {
53+
echo "SPDX 3 Validating (spdx3-validate): $1"
54+
spdx3-validate --json $1
55+
}
56+
3057
# Check examples in JSON files in examples/jsonld/
31-
if [ "$(ls $THIS_DIR/../examples/jsonld/*.json 2>/dev/null)" ]; then
32-
for f in $THIS_DIR/../examples/jsonld/*.json; do
33-
echo "Checking $f"
58+
if [ "$(ls $THIS_DIR/../$JSON_DIR/*.json 2>/dev/null)" ]; then
59+
for f in $THIS_DIR/../$JSON_DIR/*.json; do
3460
check_schema $f
61+
echo ""
3562
check_model $f
63+
echo ""
64+
check_spdx $f
65+
echo ""
3666
done
3767
fi
3868

39-
TEMP=$(mktemp -d)
40-
4169
# Check examples in inline code snippets in Markdown files in docs/annexes/
42-
for f in $THIS_DIR/../docs/annexes/*.md; do
70+
TEMP=$(mktemp -d)
71+
for f in $THIS_DIR/../$MD_DIR/*.md; do
4372
if ! grep -q '^```json' $f; then
4473
continue
4574
fi
46-
echo "Checking $f"
75+
echo "Extract snippets from $f"
4776
DEST=$TEMP/$(basename $f)
4877
mkdir -p $DEST
4978

5079
# Read inline code snippets and save them in separate, numbered files.
5180
cat $f | awk -v DEST="$DEST" 'BEGIN{flag=0} /^```json/, $0=="```" { if (/^---$/){flag++} else if ($0 !~ /^```.*/ ) print $0 > DEST "/doc-" flag ".spdx.json"}'
5281

5382
# Combine all JSON code snippets into a single file, with SPDX context and creation info.
54-
echo "[" > $DEST/combined.json
83+
COMBINED_JSON = $DEST/__combined.jso
84+
echo "[" > $COMBINED_JSON
5585

5686
for doc in $DEST/*.spdx.json; do
5787
if ! grep -q '@context' $doc; then
@@ -81,11 +111,15 @@ HEREDOC
81111
HEREDOC
82112
fi
83113
check_schema $doc
84-
cat $doc >> $DEST/combined.json
85-
echo "," >> $DEST/combined.json
114+
echo ""
115+
cat $doc >> $COMBINED_JSON
116+
echo "," >> $COMBINED_JSON
86117
done
87118

88-
echo "{}]" >> $DEST/combined.json
119+
echo "{}]" >> $COMBINED_JSON
89120

90-
check_model $DEST/combined.json
121+
check_model $COMBINED_JSON
122+
echo ""
123+
check_spdx $COMBINED_JSON
124+
echo ""
91125
done

examples/jsonld/package_sbom.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"spdxId": "http://spdx.example.com/Package1",
6262
"creationInfo": "_:creationinfo",
6363
"name": "my-package",
64-
"software_packageVersion": "1.0",
64+
"software_packageVersion": "1.0.0",
6565
"software_downloadLocation": "http://dl.example.com/my-package_1.0.0.tar",
6666
"builtTime": "2024-03-06T00:00:00Z",
6767
"originatedBy": [

0 commit comments

Comments
 (0)