Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spdx3-validate to examples validation workflow #1134

Merged
merged 30 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
589d52f
Use spdx3-validate
bact Sep 13, 2024
4bfe510
Update example dir to trigger validation
bact Sep 13, 2024
bb8b348
Print resolved URLs
bact Sep 13, 2024
75da365
Use full option names
bact Sep 14, 2024
dc0b047
Make locations variables
bact Oct 7, 2024
0ece60c
Add SPDX-FileCopyrightText
bact Oct 7, 2024
7911faa
Update checkout action to v4.2.1
bact Oct 7, 2024
92057c4
Merge branch 'development/v3.0.1' into use-spdx3-validate
bact Oct 8, 2024
c49fbec
Merge branch 'development/v3.0.1' into use-spdx3-validate
bact Oct 13, 2024
05b7251
Update PySHACL
bact Oct 25, 2024
e34b83f
Merge branch 'development/v3.0.1' into use-spdx3-validate
bact Nov 15, 2024
55af858
Merge branch 'develop' into use-spdx3-validate
bact Nov 16, 2024
95e9150
Merge branch 'develop' into use-spdx3-validate
bact Nov 19, 2024
fc06c37
Update spdx3-validate to 0.0.5
bact Nov 25, 2024
aa71035
Merge branch 'develop' into use-spdx3-validate
bact Dec 5, 2024
d312c10
Merge branch 'develop' into use-spdx3-validate
bact Dec 6, 2024
b74252c
Skip pyshacl
bact Dec 6, 2024
c3a5ef0
Merge branch 'use-spdx3-validate' of https://github.com/bact/spdx-spe…
bact Dec 6, 2024
957c722
Skip pyshacl
bact Dec 6, 2024
cd2034c
Put back pyshacl
bact Dec 6, 2024
760cd72
Merge branch 'develop' into use-spdx3-validate
bact Dec 10, 2024
32d1db9
Merge branch 'develop' into use-spdx3-validate
bact Dec 10, 2024
a8ab31f
Merge branch 'develop' into use-spdx3-validate
bact Dec 13, 2024
8a245f4
Merge branch 'develop' into use-spdx3-validate
bact Dec 29, 2024
047e70c
Update pyshacl==0.29.1
bact Jan 5, 2025
5d04d93
Merge branch 'develop' into use-spdx3-validate
bact Jan 14, 2025
fff347b
Update check-jsonschema==0.31.0
bact Jan 15, 2025
2c4dafe
Merge branch 'develop' into use-spdx3-validate
bact Jan 15, 2025
c8245e5
Merge branch 'develop' into use-spdx3-validate
bact Jan 15, 2025
ba1aeff
Merge branch 'develop' into use-spdx3-validate
bact Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
cache: "pip"
- name: Install Python dependencies
run: |
python3 -m pip install check-jsonschema==0.29.4 pyshacl==0.29.0
python3 -m pip install check-jsonschema==0.29.4 pyshacl==0.29.0 spdx3-validate==0.0.4
- name: Install dependencies
run: |
sudo apt install -y gawk
Expand Down
64 changes: 49 additions & 15 deletions bin/check-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,84 @@
# documentation
#
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Copyright 2024 The SPDX Contributors

set -e

THIS_DIR="$(dirname "$0")"
MD_DIR=docs/annexes
JSON_DIR=examples/jsonld

SPDX_VERSION="3.0.1"
SCHEMA_URL="https://spdx.org/schema/${SPDX_VERSION}/spdx-json-schema.json"
RDF_URL="https://spdx.org/rdf/${SPDX_VERSION}/spdx-model.ttl"
CONTEXT_URL="https://spdx.org/rdf/${SPDX_VERSION}/spdx-context.jsonld"

# print validation setup
echo "Checking examples in"
echo "Snippets : $MD_DIR"
echo "Files : $JSON_DIR"
echo "SPDX version : $SPDX_VERSION"
echo "Schema : $SCHEMA_URL"
echo "Schema resolved : $(curl -I "$SCHEMA_URL" 2>/dev/null | grep -i "location:" | awk '{print $2}')"
echo "RDF : $RDF_URL"
echo "RDF resolved : $(curl -I "$RDF_URL" 2>/dev/null | grep -i "location:" | awk '{print $2}')"
echo "Context : $CONTEXT_URL"
echo "Context resolved : $(curl -I "$CONTEXT_URL" 2>/dev/null | grep -i "location:" | awk '{print $2}')"
echo "$(check-jsonschema --version)"
echo -n "$(pyshacl --version)"
echo "spdx3-validate version: $(spdx3-validate --version)"
echo ""

check_schema() {
echo "Checking schema (check-jsonschema): $1"
check-jsonschema \
-v \
--verbose \
--schemafile $SCHEMA_URL \
"$1"
}

check_model() {
echo "Checking model (pyschacl): $1"
pyshacl \
-s $RDF_URL \
-e $RDF_URL \
--shacl $RDF_URL \
--ont-graph $RDF_URL \
"$1"
}

check_spdx() {
echo "SPDX 3 Validating (spdx3-validate): $1"
spdx3-validate --json $1
}

# Check examples in JSON files in examples/jsonld/
if [ "$(ls $THIS_DIR/../examples/jsonld/*.json 2>/dev/null)" ]; then
for f in $THIS_DIR/../examples/jsonld/*.json; do
echo "Checking $f"
if [ "$(ls $THIS_DIR/../$JSON_DIR/*.json 2>/dev/null)" ]; then
for f in $THIS_DIR/../$JSON_DIR/*.json; do
check_schema $f
echo ""
check_model $f
echo ""
check_spdx $f
echo ""
done
fi

TEMP=$(mktemp -d)

# Check examples in inline code snippets in Markdown files in docs/annexes/
for f in $THIS_DIR/../docs/annexes/*.md; do
TEMP=$(mktemp -d)
for f in $THIS_DIR/../$MD_DIR/*.md; do
if ! grep -q '^```json' $f; then
continue
fi
echo "Checking $f"
echo "Extract snippets from $f"
DEST=$TEMP/$(basename $f)
mkdir -p $DEST

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

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

for doc in $DEST/*.spdx.json; do
if ! grep -q '@context' $doc; then
Expand Down Expand Up @@ -81,11 +111,15 @@ HEREDOC
HEREDOC
fi
check_schema $doc
cat $doc >> $DEST/combined.json
echo "," >> $DEST/combined.json
echo ""
cat $doc >> $COMBINED_JSON
echo "," >> $COMBINED_JSON
done

echo "{}]" >> $DEST/combined.json
echo "{}]" >> $COMBINED_JSON

check_model $DEST/combined.json
check_model $COMBINED_JSON
echo ""
check_spdx $COMBINED_JSON
echo ""
done
2 changes: 1 addition & 1 deletion examples/jsonld/package_sbom.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"spdxId": "http://spdx.example.com/Package1",
"creationInfo": "_:creationinfo",
"name": "my-package",
"software_packageVersion": "1.0",
"software_packageVersion": "1.0.0",
"software_downloadLocation": "http://dl.example.com/my-package_1.0.0.tar",
"builtTime": "2024-03-06T00:00:00Z",
"originatedBy": [
Expand Down
Loading