Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23
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 }}
85 changes: 85 additions & 0 deletions .github/workflows/coverage-generate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
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.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
coverage:
name: Generate coverage report
runs-on: ubuntu-latest
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for pushing data to the
# python-coverage-comment-action branch, and for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write
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: "3.11"
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: |
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
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@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23
with:
key: ${{ github.job }}
- name: Install package
run: |
pip install -e .[dev]
- name: Generate coverage report
run: |
pytest -v
- name: Coverage comment
id: coverage_comment
uses: py-cov-action/python-coverage-comment-action@a05be3d2e8a6272d3ef5fb2840ab20368bb2eb71 # v4.3
with:
GITHUB_TOKEN: ${{ github.token }}
- name: Store Pull Request comment to be posted
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
name: python-coverage-comment-action
# If you use a different name, update COMMENT_FILENAME accordingly
path: python-coverage-comment-action.txt
4 changes: 2 additions & 2 deletions .github/workflows/coverage-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Post coverage comment

on:
workflow_run:
workflows: ["Test shacl2code"]
workflows: ["Generate coverage"]
types:
- completed

Expand All @@ -30,7 +30,7 @@ jobs:
# DO NOT run actions/checkout here, for security reasons
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Post comment
uses: py-cov-action/python-coverage-comment-action@2b84cfb222691291ba358a586c13606f0a9c172c # v3
uses: py-cov-action/python-coverage-comment-action@a05be3d2e8a6272d3ef5fb2840ab20368bb2eb71 # v4.3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
Expand Down
Loading
Loading