Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
105 changes: 105 additions & 0 deletions .github/workflows/_pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
# Reusable test runner. To be called from other workflows.
name: pytest

on:
workflow_call:
inputs:
test-files:
description: "Space-separated pytest paths or options/arguments (empty = whole suite)"
type: string
default: ""
python-versions:
description: "JSON array of Python versions for the matrix"
type: string
default: '["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]'
install-native-toolchains:
description: "Install compilers/tools to build & run generated bindings"
type: boolean
default: true
install-go:
description: >-
Install Go via brew on macOS. Default false since Go is
preinstalled on Linux runners and only the golang job needs it.
type: boolean
default: false
install-rust-clippy:
description: "Install the clippy component (needed by tests/test_rust.py's static analysis test)"
type: boolean
default: false
install-go-staticcheck:
description: "Install staticcheck (needed by tests/test_golang.py's static analysis test)"
type: boolean
default: false

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ${{ fromJSON(inputs.python-versions) }}
include:
- os: macos-latest
python-version: "3.10"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python-version }}
cache: pip
# jsonld-cli is used by the tests (incl. core), so always install it.
- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
cache: npm
cache-dependency-path: scripts/package-lock.json
- name: Install Python build tooling
run: |
python -m pip install --upgrade pip
pip install build
- name: Install jsonld-cli
run: |
npm install -g jsonld-cli
- name: Install Node test/build scripts
run: |
npm --prefix scripts ci
- name: Install Linux packages
if: ${{ inputs.install-native-toolchains && runner.os == 'Linux' }}
run: |
sudo apt update
sudo apt install -y build-essential ccache cppcheck doxygen graphviz
- name: Install macOS packages
if: ${{ inputs.install-native-toolchains && runner.os == 'macOS' }}
run: |
brew update
brew install ccache cppcheck doxygen gcc graphviz
- name: Install Go (macOS)
if: ${{ inputs.install-go && runner.os == 'macOS' }}
run: |
brew install go
- name: Install Rust static analysis tools
if: ${{ inputs.install-rust-clippy }}
run: |
rustup component add clippy
- name: Install Go static analysis tools
if: ${{ inputs.install-go-staticcheck }}
run: |
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Configure ccache
if: ${{ inputs.install-native-toolchains }}
uses: hendrikmuhs/ccache-action@f09c25b45002a07be2955cbe52e8cee55643f89d # v1.2.24
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
- name: Build package
run: |
python -m build
- name: Install package
run: |
pip install -e .[dev]
- name: Run tests
run: |
pytest -v ${{ inputs.test-files }}
17 changes: 16 additions & 1 deletion .github/workflows/coverage-generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ name: Generate coverage

on:
pull_request:
# Skip docs and edits to other workflows; later patterns override earlier.
paths: &trigger-paths
- "**"
- "!**/*.md"
- "!LICENSE"
- "!.github/ISSUE_TEMPLATE/**"
- "!.github/workflows/**"
- ".github/workflows/coverage-generate.yaml"
push:
branches:
- "main"
paths: *trigger-paths

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
Expand Down Expand Up @@ -38,9 +47,11 @@ jobs:
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
cache: npm
cache-dependency-path: scripts/package-lock.json
- name: Install dependencies
run: |
sudo apt install -y build-essential cppcheck doxygen graphviz
sudo apt install -y build-essential ccache cppcheck doxygen graphviz
npm install -g jsonld-cli
npm --prefix scripts ci
- name: Install Go static analysis tools
Expand All @@ -50,6 +61,10 @@ jobs:
- name: Install Rust static analysis tools
run: |
rustup component add clippy
- name: Configure ccache
uses: hendrikmuhs/ccache-action@f09c25b45002a07be2955cbe52e8cee55643f89d # v1.2.24
with:
key: ${{ github.job }}
- name: Install package
run: |
pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard (optional).
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@v4
uses: github/codeql-action/upload-sarif@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
with:
sarif_file: results.sarif
168 changes: 113 additions & 55 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- "!.github/ISSUE_TEMPLATE/**"
- "!.github/workflows/**"
- ".github/workflows/test.yaml"
- ".github/workflows/_pytest.yaml"
pull_request:
paths: *trigger-paths
workflow_call:
Expand All @@ -22,64 +23,121 @@ permissions:
contents: read

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
include:
- os: macos-latest
python-version: "3.10"
# Check which language bindings are affected by the change
changes:
runs-on: ubuntu-latest
outputs:
cpp: ${{ steps.filter.outputs.cpp }}
golang: ${{ steps.filter.outputs.golang }}
jsonschema: ${{ steps.filter.outputs.jsonschema }}
python: ${{ steps.filter.outputs.python }}
rust: ${{ steps.filter.outputs.rust }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
cache: npm
cache-dependency-path: scripts/package-lock.json
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
npm install -g jsonld-cli
npm --prefix scripts ci
- name: Install Linux packages
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt install -y build-essential cppcheck doxygen graphviz ccache
- name: Install macOS packages
if: runner.os == 'macOS'
run: |
brew update
brew install cppcheck doxygen gcc go graphviz ccache
- name: Install Go static analysis tools
run: |
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Install Rust static analysis tools
run: |
rustup component add clippy
- name: Configure ccache
uses: hendrikmuhs/ccache-action@v1.2
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
id: filter
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
- name: Build package
run: |
python -m build
- name: Install package
run: |
pip install -e .[dev]
- name: Run tests
run: |
pytest -v
filters: |
common: &common
- '.github/workflows/_pytest.yaml'
- '.github/workflows/test.yaml'
- 'src/shacl2code/*.py'
- 'src/shacl2code/lang/__init__.py'
- 'src/shacl2code/lang/common.py'
- 'src/shacl2code/lang/jinja.py'
- 'src/shacl2code/lang/lang.py'
- 'pyproject.toml'
- 'tests/conftest.py'
- 'tests/data/**'
- 'testfixtures/**'
cpp:
- *common
- 'src/shacl2code/lang/cpp.py'
- 'src/shacl2code/lang/sources/cpp/**'
- 'src/shacl2code/lang/templates/cpp/**'
- 'tests/test_cpp.py'
golang:
- *common
- 'src/shacl2code/lang/golang.py'
- 'src/shacl2code/lang/sources/golang/**'
- 'src/shacl2code/lang/templates/golang/**'
- 'tests/test_golang.py'
jsonschema:
- *common
- 'scripts/**'
- 'src/shacl2code/lang/jsonschema.py'
- 'src/shacl2code/lang/sources/jsonschema/**'
- 'src/shacl2code/lang/templates/jsonschema.j2'
- 'tests/test_jsonschema.py'
python:
- *common
- 'src/shacl2code/lang/python.py'
- 'src/shacl2code/lang/sources/python/**'
- 'src/shacl2code/lang/templates/python/**'
- 'tests/test_python.py'
rust:
- *common
- 'src/shacl2code/lang/rust.py'
- 'src/shacl2code/lang/templates/rust/**'
- 'tests/test_rust.py'

# Always run core (ignores language-specific test suites)
core:
uses: ./.github/workflows/_pytest.yaml
with:
install-native-toolchains: false
test-files: >-
tests
--ignore=tests/test_cpp.py
--ignore=tests/test_golang.py
--ignore=tests/test_jsonschema.py
--ignore=tests/test_python.py
--ignore=tests/test_rust.py

cpp:
needs: changes
if: needs.changes.outputs.cpp == 'true'
uses: ./.github/workflows/_pytest.yaml
with:
install-native-toolchains: true
test-files: tests/test_cpp.py

golang:
needs: changes
if: needs.changes.outputs.golang == 'true'
uses: ./.github/workflows/_pytest.yaml
with:
install-native-toolchains: false
install-go: true
install-go-staticcheck: true
test-files: tests/test_golang.py

jsonschema:
needs: changes
if: needs.changes.outputs.jsonschema == 'true'
uses: ./.github/workflows/_pytest.yaml
with:
install-native-toolchains: false
test-files: tests/test_jsonschema.py

python:
needs: changes
if: needs.changes.outputs.python == 'true'
uses: ./.github/workflows/_pytest.yaml
with:
install-native-toolchains: false
test-files: tests/test_python.py

rust:
needs: changes
if: needs.changes.outputs.rust == 'true'
uses: ./.github/workflows/_pytest.yaml
with:
# `rust`/`cargo` preinstalled on runners
install-native-toolchains: false
install-rust-clippy: true
test-files: tests/test_rust.py

lint:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ shacl2code generate \
--input model-draft.ttl \
--context-url context-draft.jsonld https://example.com/context.jsonld \
jsonschema \
--output schema.json
--output schema.json
```

## Developing
Expand Down
Loading